When performing a guest checkout through the setup intent flow, creating another payment from the Stripe dashboard is possible.
A solution via a subscriber was attempted as part of #203. The code looked like the following, although it'd need refining after the final version is released:
# frozen-string-literal: true
module SolidusStripe
class SetupIntentSubscriber
include Omnes::Subscriber
handle :order_finalized, with: :detach_setup_intent
def detach_setup_intent(event)
order = event[:order]
payment_method = order.payments.find do |payment|
payment.payment_method.type == "SolidusStripe::PaymentMethod"
end&.payment_method
return unless payment_method && payment_method.preferred_stripe_intents_flow == "setup" && order.user.nil?
intent = payment_method.find_setup_intent_for_order(order)
payment_method.gateway.request do
Stripe::PaymentMethod.detach(intent.payment_method)
end
end
end
end
Some considerations:
Detaching a payment method from Stripe is the API call we need. We could probably also cancel the setup intent after that: it can't be canceled before because of having an associated payment method.
We can't use the callback controller, as that's leaving the order in the confirm state. Later, on order.complete!, we still need access to the payment method to authorize the payment.
Because of the above, a possible solution is the subscriber that runs when the order is finalized.
The previously created payment intent can still be manually captured after the payment method is detached.
Running on the :order_finalized event has the known issue of blocking the database transaction.
When performing a guest checkout through the setup intent flow, creating another payment from the Stripe dashboard is possible.
A solution via a subscriber was attempted as part of #203. The code looked like the following, although it'd need refining after the final version is released:
Some considerations:
confirm
state. Later, onorder.complete!
, we still need access to the payment method to authorize the payment.:order_finalized
event has the known issue of blocking the database transaction.