- Issue created by @nicolas bouteille
- π«π·France nicolas bouteille
Because of the code above, a new specific case also needs to be dealt with: after selecting an existing payment method, the client changes his mind, comes back and finally chooses to use a new payment method (that will be added with Payment Element form at review step).
As of now, setup_future_usage is only set in StripeReview when the PaymentIntent does not exist yet.
The PaymentIntent is created the first time we arrive at the Review step.
Because the client selected an already existing payment method at the Payment Information pane, with the code above, we did not set setup_future_usage (null) so that no new mandate would be created.
Now he's gone back and selected "use a new payment method".
So when StripeReview->buildPaneForm() is called for the second time, the PaymentIntent already exist so we never reach the code that is supposed to set setup_future_usage. - π«π·France nicolas bouteille
Rarer scenario: the client chooses to use a new payment method (which creates the PaymentIntent with setup_future_usage to off_session) but changes his mind, goes back, chooses an already existing payment method. Now in StripeReview we need to update the PaymentIntent and set setup_future_usage to null again.
- π«π·France nicolas bouteille
Here is how I've been able to solve the problems I just told you about:
The code below is added to StripeReview->buildPaneForm() after line 200 after we check wether the PaymentIntent already exists or not. Indeed, I believe we should update setup_future_usage every time we come back to StripeReview even if PaymentIntent already exists, because the client may have gone back and switched from using an existing payment method to using a new payment method and vice versa.if ($this->order->get('payment_method')->isEmpty()) { // new payment method // Set the setup_future_usage parameter for the Stripe Payment Element. if ($stripe_plugin instanceof StripePaymentElementInterface) { $intent = PaymentIntent::update($intent->id, [ 'setup_future_usage' => $stripe_plugin->getPaymentMethodUsage(), ]); } } else { // For existing payment methods, we don't set setup_future_usage at all (NULL) so we don't create multiple mandates if ($intent->setup_future_usage === "off_session") { // if the client previously chose to add new payment method // it is not possible to update PaymentIntent that already has setup_future_usage set to off_session back to NULL // only solution that seems possible is to cancel current PaymentIntent and create a new one without setup_future_usage $intent->cancel(); $payment_process_pane = $this->checkoutFlow->getPane('payment_process'); assert($payment_process_pane instanceof CheckoutPaneInterface); $intent_attributes = [ 'capture_method' => $payment_process_pane->getConfiguration()['capture'] ? 'automatic' : 'manual', ]; $intent = $stripe_plugin->createPaymentIntent($this->order, $intent_attributes); } }
Obviously, the code before line 200 that sets setup_future_usage for PaymentElement only when the PaymentIntent did not exist yet, should be deleted...
What do you guys think?
- π¦πΉAustria agoradesign
Side notice on this issue: I'm coming from π In StripePaymentElement->onReturn do not allow PaymentGatewayException to bubble up if we know the payment was successful on Stripe's end Active because I've realized that any other payment methods than credit cards (and the American ACH banking) are currently not supported by Payment Element, like in my case PayPal was refused on the Drupal side (the Stripe transaction was successful)
I found this issue description here a little bit weird at first, as it clearly states that PayPal payments already have worked at the time of writing this issue. This important refactoring here destroyed PayPal and other payments until a dedicated plugin is created: https://git.drupalcode.org/project/commerce_stripe/-/commit/bf118321d3fb...
- π«π·France nicolas bouteille
Your right. Let me update the description to clarify the situation.
- π«π·France nicolas bouteille
Updating the description to make it clear that using Paypal was done via custom code.
- Status changed to Closed: outdated
6 months ago 5:28am 9 July 2024 - πΊπΈUnited States TomTech
This has been addressed in a separate issue. setup_future_usage is no longer set if an existing payment method is selected by the customer.
See: https://git.drupalcode.org/project/commerce_stripe/-/blob/8.x-1.x/src/Pl...