Class: SpreeStripe::PaymentIntent
- Defined in:
- app/models/spree_stripe/payment_intent.rb
Instance Method Summary collapse
- #accepted? ⇒ Boolean
- #amount_in_cents ⇒ Object
- #amount_or_stripe_payment_method_id_changed? ⇒ Boolean
- #charge_not_required? ⇒ Boolean
-
#find_or_create_payment! ⇒ Object
here we create a payment if it doesn’t exist or we find it by the stripe_payment_intent_id.
- #money ⇒ Object
- #set_amount_from_order ⇒ Object
- #stripe_charge ⇒ Object
- #stripe_payment_intent ⇒ Object
- #successful? ⇒ Boolean
- #update_stripe_payment_intent ⇒ Object
Instance Method Details
#accepted? ⇒ Boolean
29 30 31 |
# File 'app/models/spree_stripe/payment_intent.rb', line 29 def accepted? payment_method.payment_intent_accepted?(stripe_payment_intent) end |
#amount_in_cents ⇒ Object
73 74 75 |
# File 'app/models/spree_stripe/payment_intent.rb', line 73 def amount_in_cents @amount_in_cents ||= money.cents end |
#amount_or_stripe_payment_method_id_changed? ⇒ Boolean
69 70 71 |
# File 'app/models/spree_stripe/payment_intent.rb', line 69 def amount_or_stripe_payment_method_id_changed? amount_previously_changed? || stripe_payment_method_id_previously_changed? end |
#charge_not_required? ⇒ Boolean
37 38 39 |
# File 'app/models/spree_stripe/payment_intent.rb', line 37 def charge_not_required? payment_method.payment_intent_charge_not_required?(stripe_payment_intent) end |
#find_or_create_payment! ⇒ Object
here we create a payment if it doesn’t exist or we find it by the stripe_payment_intent_id
54 55 56 57 58 59 |
# File 'app/models/spree_stripe/payment_intent.rb', line 54 def find_or_create_payment! return unless persisted? return payment if payment.present? SpreeStripe::CreatePayment.new(order: order, payment_intent: self, gateway: payment_method, amount: amount).call end |
#money ⇒ Object
77 78 79 |
# File 'app/models/spree_stripe/payment_intent.rb', line 77 def money @money ||= Spree::Money.new(amount, currency: currency) end |
#set_amount_from_order ⇒ Object
61 62 63 |
# File 'app/models/spree_stripe/payment_intent.rb', line 61 def set_amount_from_order self.amount = order&.total_minus_store_credits if order.present? && (amount.nil? || amount.zero?) end |
#stripe_charge ⇒ Object
45 46 47 48 49 50 |
# File 'app/models/spree_stripe/payment_intent.rb', line 45 def stripe_charge @stripe_charge ||= begin latest_charge = stripe_payment_intent.latest_charge latest_charge.present? ? payment_method.retrieve_charge(latest_charge) : nil end end |
#stripe_payment_intent ⇒ Object
41 42 43 |
# File 'app/models/spree_stripe/payment_intent.rb', line 41 def stripe_payment_intent @stripe_payment_intent ||= payment_method.retrieve_payment_intent(stripe_id) end |
#successful? ⇒ Boolean
33 34 35 |
# File 'app/models/spree_stripe/payment_intent.rb', line 33 def successful? stripe_payment_intent.status == 'succeeded' end |
#update_stripe_payment_intent ⇒ Object
65 66 67 |
# File 'app/models/spree_stripe/payment_intent.rb', line 65 def update_stripe_payment_intent payment_method.update_payment_intent(stripe_id, amount_in_cents, order, stripe_payment_method_id) end |