Class: Pay::Payment
- Inherits:
-
Object
- Object
- Pay::Payment
- Defined in:
- lib/pay/payment.rb
Instance Attribute Summary collapse
-
#intent ⇒ Object
readonly
Returns the value of attribute intent.
Class Method Summary collapse
Instance Method Summary collapse
- #amount_with_currency ⇒ Object
- #canceled? ⇒ Boolean
- #cancelled? ⇒ Boolean
-
#initialize(intent) ⇒ 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) ⇒ Payment
Returns a new instance of Payment.
12 13 14 |
# File 'lib/pay/payment.rb', line 12 def initialize(intent) @intent = intent end |
Instance Attribute Details
#intent ⇒ Object (readonly)
Returns the value of attribute intent.
3 4 5 |
# File 'lib/pay/payment.rb', line 3 def intent @intent end |
Class Method Details
.from_id(id) ⇒ Object
7 8 9 10 |
# File 'lib/pay/payment.rb', line 7 def self.from_id(id) intent = id.start_with?("seti_") ? ::Stripe::SetupIntent.retrieve(id) : ::Stripe::PaymentIntent.retrieve(id) new(intent) end |
Instance Method Details
#amount_with_currency ⇒ Object
44 45 46 |
# File 'lib/pay/payment.rb', line 44 def amount_with_currency Pay::Currency.format(amount, currency: currency) end |
#canceled? ⇒ Boolean
24 25 26 |
# File 'lib/pay/payment.rb', line 24 def canceled? status == "canceled" end |
#cancelled? ⇒ Boolean
28 29 30 |
# File 'lib/pay/payment.rb', line 28 def cancelled? canceled? end |
#payment_intent? ⇒ Boolean
36 37 38 |
# File 'lib/pay/payment.rb', line 36 def payment_intent? intent.is_a?(::Stripe::PaymentIntent) end |
#requires_action? ⇒ Boolean
20 21 22 |
# File 'lib/pay/payment.rb', line 20 def requires_action? status == "requires_action" end |
#requires_payment_method? ⇒ Boolean
16 17 18 |
# File 'lib/pay/payment.rb', line 16 def requires_payment_method? status == "requires_payment_method" end |
#setup_intent? ⇒ Boolean
40 41 42 |
# File 'lib/pay/payment.rb', line 40 def setup_intent? intent.is_a?(::Stripe::SetupIntent) end |
#succeeded? ⇒ Boolean
32 33 34 |
# File 'lib/pay/payment.rb', line 32 def succeeded? status == "succeeded" end |
#validate ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/pay/payment.rb', line 48 def validate if requires_payment_method? raise Pay::InvalidPaymentMethod.new(self) elsif requires_action? raise Pay::ActionRequired.new(self) end end |