Class: Reji::Payment
- Inherits:
-
Object
- Object
- Reji::Payment
- Defined in:
- lib/reji/payment.rb
Instance Method Summary collapse
-
#amount ⇒ Object
Get the total amount that will be paid.
-
#as_stripe_payment_intent ⇒ Object
The Stripe PaymentIntent instance.
-
#cancelled? ⇒ Boolean
Determine if the payment was cancelled.
-
#client_secret ⇒ Object
The Stripe PaymentIntent client secret.
-
#initialize(payment_intent) ⇒ Payment
constructor
A new instance of Payment.
-
#method_missing(key) ⇒ Object
Dynamically get values from the Stripe PaymentIntent.
-
#raw_amount ⇒ Object
Get the raw total amount that will be paid.
-
#requires_action ⇒ Object
Determine if the payment needs an extra action like 3D Secure.
-
#requires_payment_method ⇒ Object
Determine if the payment needs a valid payment method.
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
-
#succeeded? ⇒ Boolean
Determine if the payment was successful.
-
#validate ⇒ Object
Validate if the payment intent was successful and throw an exception if not.
Constructor Details
#initialize(payment_intent) ⇒ Payment
Returns a new instance of Payment.
5 6 7 |
# File 'lib/reji/payment.rb', line 5 def initialize(payment_intent) @payment_intent = payment_intent end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key) ⇒ Object
Dynamically get values from the Stripe PaymentIntent.
57 58 59 |
# File 'lib/reji/payment.rb', line 57 def method_missing(key) @payment_intent[key] end |
Instance Method Details
#amount ⇒ Object
Get the total amount that will be paid.
10 11 12 |
# File 'lib/reji/payment.rb', line 10 def amount Reji.format_amount(raw_amount, @payment_intent.currency) end |
#as_stripe_payment_intent ⇒ Object
The Stripe PaymentIntent instance.
52 53 54 |
# File 'lib/reji/payment.rb', line 52 def as_stripe_payment_intent @payment_intent end |
#cancelled? ⇒ Boolean
Determine if the payment was cancelled.
35 36 37 |
# File 'lib/reji/payment.rb', line 35 def cancelled? @payment_intent.status == 'canceled' end |
#client_secret ⇒ Object
The Stripe PaymentIntent client secret.
20 21 22 |
# File 'lib/reji/payment.rb', line 20 def client_secret @payment_intent.client_secret end |
#raw_amount ⇒ Object
Get the raw total amount that will be paid.
15 16 17 |
# File 'lib/reji/payment.rb', line 15 def raw_amount @payment_intent.amount end |
#requires_action ⇒ Object
Determine if the payment needs an extra action like 3D Secure.
30 31 32 |
# File 'lib/reji/payment.rb', line 30 def requires_action @payment_intent.status == 'requires_action' end |
#requires_payment_method ⇒ Object
Determine if the payment needs a valid payment method.
25 26 27 |
# File 'lib/reji/payment.rb', line 25 def requires_payment_method @payment_intent.status == 'requires_payment_method' end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
61 62 63 |
# File 'lib/reji/payment.rb', line 61 def respond_to_missing?(method_name, include_private = false) super end |
#succeeded? ⇒ Boolean
Determine if the payment was successful.
40 41 42 |
# File 'lib/reji/payment.rb', line 40 def succeeded? @payment_intent.status == 'succeeded' end |
#validate ⇒ Object
Validate if the payment intent was successful and throw an exception if not.
45 46 47 48 49 |
# File 'lib/reji/payment.rb', line 45 def validate raise Reji::PaymentFailureError.invalid_payment_method(self) if requires_payment_method raise Reji::PaymentActionRequiredError.incomplete(self) if requires_action end |