Class: Pay::Payment
- Inherits:
-
Object
- Object
- Pay::Payment
- Defined in:
- lib/pay/payment.rb
Instance Attribute Summary collapse
-
#intent ⇒ Object
readonly
The Stripe Connect account the intent lives on, if any.
-
#stripe_account ⇒ Object
readonly
The Stripe Connect account the intent lives on, if any.
Class Method Summary collapse
Instance Method Summary collapse
- #amount_with_currency ⇒ Object
- #canceled? ⇒ Boolean
-
#initialize(intent, stripe_account: nil) ⇒ Payment
constructor
A new instance of Payment.
- #requires_action? ⇒ Boolean
- #requires_payment_method? ⇒ Boolean
- #succeeded? ⇒ Boolean
- #validate ⇒ Object
Constructor Details
#initialize(intent, stripe_account: nil) ⇒ Payment
Returns a new instance of Payment.
17 18 19 20 |
# File 'lib/pay/payment.rb', line 17 def initialize(intent, stripe_account: nil) @intent = intent @stripe_account = stripe_account end |
Instance Attribute Details
#intent ⇒ Object (readonly)
The Stripe Connect account the intent lives on, if any. Needed to look the intent up again and to initialize Stripe.js on the SCA confirmation page.
5 6 7 |
# File 'lib/pay/payment.rb', line 5 def intent @intent end |
#stripe_account ⇒ Object (readonly)
The Stripe Connect account the intent lives on, if any. Needed to look the intent up again and to initialize Stripe.js on the SCA confirmation page.
5 6 7 |
# File 'lib/pay/payment.rb', line 5 def stripe_account @stripe_account end |
Class Method Details
.from_id(id, stripe_account: nil) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/pay/payment.rb', line 9 def self.from_id(id, stripe_account: nil) = {stripe_account: stripe_account}.compact intent = id.start_with?("seti_") ? ::Stripe::SetupIntent.retrieve(id, ) : ::Stripe::PaymentIntent.retrieve(id, ) new(intent, stripe_account: stripe_account) rescue ::Stripe::StripeError => e raise Pay::Stripe::Error, e end |
Instance Method Details
#amount_with_currency ⇒ Object
38 39 40 |
# File 'lib/pay/payment.rb', line 38 def amount_with_currency Pay::Currency.format(amount, currency: currency) end |
#canceled? ⇒ Boolean
30 31 32 |
# File 'lib/pay/payment.rb', line 30 def canceled? status == "canceled" end |
#requires_action? ⇒ Boolean
26 27 28 |
# File 'lib/pay/payment.rb', line 26 def requires_action? status == "requires_action" end |
#requires_payment_method? ⇒ Boolean
22 23 24 |
# File 'lib/pay/payment.rb', line 22 def requires_payment_method? status == "requires_payment_method" end |
#succeeded? ⇒ Boolean
34 35 36 |
# File 'lib/pay/payment.rb', line 34 def succeeded? status == "succeeded" end |
#validate ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/pay/payment.rb', line 42 def validate if requires_payment_method? raise Pay::InvalidPaymentMethod.new(self) elsif requires_action? raise Pay::ActionRequired.new(self) end end |