Class: SpreeStripe::CompleteOrder
- Inherits:
-
Object
- Object
- SpreeStripe::CompleteOrder
- Defined in:
- app/services/spree_stripe/complete_order.rb
Instance Attribute Summary collapse
-
#payment_intent ⇒ Object
readonly
Returns the value of attribute payment_intent.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(payment_intent:) ⇒ CompleteOrder
constructor
A new instance of CompleteOrder.
Constructor Details
#initialize(payment_intent:) ⇒ CompleteOrder
Returns a new instance of CompleteOrder.
3 4 5 |
# File 'app/services/spree_stripe/complete_order.rb', line 3 def initialize(payment_intent:) @payment_intent = payment_intent end |
Instance Attribute Details
#payment_intent ⇒ Object (readonly)
Returns the value of attribute payment_intent.
7 8 9 |
# File 'app/services/spree_stripe/complete_order.rb', line 7 def payment_intent @payment_intent end |
Instance Method Details
#call ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/services/spree_stripe/complete_order.rb', line 9 def call order = payment_intent.order return order if (order.completed? && order.paid?) || order.canceled? charge = payment_intent.stripe_charge order.with_lock do # needed for quick checkout orders order = add_customer_information(order, charge) # find or create the payment payment = payment_intent.find_or_create_payment! # process the payment if payment_intent.successful? payment.process! else payment. end # complete the order Spree::Dependencies.checkout_complete_service.constantize.call(order: order) unless order.completed? end order.reload end |