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
- #cancelled? ⇒ Boolean
-
#initialize(intent, stripe_account: nil) ⇒ Payment
constructor
A new instance of Payment.
- #payment_intent? ⇒ Boolean
- #requires_action? ⇒ Boolean
- #requires_payment_method? ⇒ Boolean
- #setup_intent? ⇒ Boolean
- #succeeded? ⇒ Boolean
- #validate ⇒ Object
Constructor Details
#initialize(intent, stripe_account: nil) ⇒ Payment
Returns a new instance of Payment.
15 16 17 18 |
# File 'lib/pay/payment.rb', line 15 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 |
# 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) end |
Instance Method Details
#amount_with_currency ⇒ Object
48 49 50 |
# File 'lib/pay/payment.rb', line 48 def amount_with_currency Pay::Currency.format(amount, currency: currency) end |
#canceled? ⇒ Boolean
28 29 30 |
# File 'lib/pay/payment.rb', line 28 def canceled? status == "canceled" end |
#cancelled? ⇒ Boolean
32 33 34 |
# File 'lib/pay/payment.rb', line 32 def cancelled? canceled? end |
#payment_intent? ⇒ Boolean
40 41 42 |
# File 'lib/pay/payment.rb', line 40 def payment_intent? intent.is_a?(::Stripe::PaymentIntent) end |
#requires_action? ⇒ Boolean
24 25 26 |
# File 'lib/pay/payment.rb', line 24 def requires_action? status == "requires_action" end |
#requires_payment_method? ⇒ Boolean
20 21 22 |
# File 'lib/pay/payment.rb', line 20 def requires_payment_method? status == "requires_payment_method" end |
#setup_intent? ⇒ Boolean
44 45 46 |
# File 'lib/pay/payment.rb', line 44 def setup_intent? intent.is_a?(::Stripe::SetupIntent) end |
#succeeded? ⇒ Boolean
36 37 38 |
# File 'lib/pay/payment.rb', line 36 def succeeded? status == "succeeded" end |
#validate ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/pay/payment.rb', line 52 def validate if requires_payment_method? raise Pay::InvalidPaymentMethod.new(self) elsif requires_action? raise Pay::ActionRequired.new(self) end end |