Problem/Motivation

Currently, Commerce Stripe's Payment Element integration offers 2 "Payment method usage" options: "On-session" and "Off-session". Both of these options will store the payment method for future use, and both cause Stripe to show a message like this:

By providing your card information, you allow [business name] to charge your card for future payments in accordance with their terms.

For use-cases where the site will not be making future charges, this message can be confusing and off-putting to potential customers.

Steps to reproduce

  1. Create "Stripe Payment Element" payment gateway
  2. Test checkout flow — the Stripe Payment Element iframe includes the above message

Proposed resolution

Add a third "Payment method usage" option, "None", which will omit the setup_future_usage key, causing Stripe to omit the above message.

Remaining tasks

Review patch

User interface changes

Add option to Stripe Payment Element settings form

API changes

n/a

Data model changes

n/a

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

smokris created an issue. See original summary.

smokris’s picture

Assigned: smokris » Unassigned
Status: Active » Needs review
StatusFileSize
new2.12 KB

Patch attached.

rszrama’s picture

Title: In Stripe Payment Element, allow turning off future payments » Add the option to not setup payment methods for future usage
Component: Payment Element » User interface
Status: Needs review » Needs work

Ahh, I see - the field is indeed optional. However, let's use this ticket to solve this for both the Card Element and the Payment Element. Note that in either case, we also need to ensure the payment method entity created in Drupal Commerce is set to non-reusable when this "none" option is selected.

Additionally, as a slight clarification to the option, given the name of the field, let's make this the third option, not the first, with a key of single_use and label of, "Single use: the payment method will not be made available for subsequent transactions".

Good find! I was actually wondering about that message myself when testing other issues just now. 😛

vmarchuk made their first commit to this issue’s fork.

vmarchuk’s picture

I've opened MR with the initial work for both payment gateways. But it still requires some additional work and testing. We need to figure out if we need to create a remote payment method if None (or Single use) is selected and attach it to the remote client or not.

vmarchuk’s picture

After some research, I see the following.
For the Stripe Card Element, this works perfectly - the PaymentIntent succeeded and the payment method was attached to the customer with no "Set up for future use" options.
For the Stripe Payment Element, it still doesn't work - the PaymentIntent succeeded but I get an error "This PaymentMethod was previously used without being attached to a Customer or was detached from a Customer, and may not be used again.". This means that we want to attach the payment method to the customer after the paymentIntent has used it, so this should happen before that. In our case, it is impossible because it does not exist.

So basically when we use the setup_future_usage parameter, the paymentIntent automatically attaches the payment method to the customer, but in case it is empty or missing, we need to attach it to the customer manually. In the case of the Stripe Payment Element, the payment method will be created after the paymentIntent is confirmed, but at this point, we cannot attach it to the customer because it has already been used by the paymentIntent.

I'm open to discussion if anyone is also interested in this issue.

vmarchuk’s picture

Status: Needs work » Needs review

From my comment we cannot attach a payment method to the customer after the paymentIntent is confirmed but we can skip attaching a payment method to the customer. But in this case, the Stripe dashboard on the customer page won't show the payment method (is that a big deal?). Otherwise, for the Stripe Card Element, the payment method will be there.
This seems to be the only way we can use the Stripe Payment element.

skyredwang’s picture

Status: Needs review » Reviewed & tested by the community

https://www.drupal.org/project/commerce_stripe/issues/3392413#mr56-note2... works, I can see the new option "Single use: the payment method will not be made available for subsequent transactions" under Stripe Payment Element payment gateway. When choosing it, I can see single-use payment methods showing up, although they don't actually work, that's new issues.

Can we get this in first, so follow up issues can fix additional problems.

skyredwang’s picture

Status: Reviewed & tested by the community » Needs review

I brought the latest changes from 8.1-1.x to this MR.

However, I temporarily removed the changes to Stripe.php

In #3, @rszrama wanted to add this third option for Card Element. But, Card Element uses Stripe Card Element (Stripe.php) gateway, which doesn't have on-session and off-session configurations.

@vmarchuk made this 3rd option available to Card Element by using the configuration from Stripe Review Pane. Programming wise, add a condition or dependency on routing makes Stripe.php less robust, as routing isn't always safe assumption. Personally, I think if we want the Card Element to have this configuration, then we want to add this configuration to its gateway. The configuration for Stripe Review Pane serves as an option to override in the checkout process.

What do you think?

skyredwang’s picture

Status: Needs review » Needs work

Here is one more thing we have to deal with: when a payment succeeded, we have the logic to create a customer and attach the payment method in both Stripe.php and StripePaymentElement.php.

However, when we set setup_future_usage: null to make/allow single-use payment method. We cannot create the customer and attach the single-use payment method. Otherwise, Stripe API will return:

400 invalid_request_error
This PaymentMethod was previously used without being attached to a Customer or was detached from a Customer, and may not be used again.

This is documented here https://stripe.com/docs/payments/payment-methods#usage

Single-use payment methods (for example, some kinds of bank transfers) can’t be attached to customers because they’re consumed after a payment attempt.

So, depending on the gateway, we will conditionally attach the payment method that just completed.

skyredwang’s picture

Status: Needs work » Needs review
agoradesign’s picture

Coming from #3403745-4: Update Stripe API Version, I've tried this patch (latest MR) and it solved our problem :-)

nicolas bouteille’s picture

Hi there,
I'd like to add some info to the mix that needs to be taken into account about setup_future_usage:
#3414706: Do not set setup_future_usage off_session again for already stored payment methods to avoid multiple mandates creation

loze’s picture

The MR needs to be rebased, its no longer applying for me.

vmarchuk’s picture

Rebased patch with the latest changes from 8.x-1.x.
+ tested changes locally and everything works as expected.
@skyredwang
I just don't know why we need a new test in tests/src/FunctionalJavascript/CheckoutTest.php since all the tests were written for the Stripe Card Element, but as part of this issue, we are only making changes for the Stripe Payment Element.

TomTech made their first commit to this issue’s fork.

  • TomTech committed 85463717 on 8.x-1.x authored by vmarchuk
    Issue #3392413 by vmarchuk, skyredwang, smokris, rszrama, loze, Nicolas...
tomtech’s picture

Status: Needs review » Fixed
tomtech’s picture

Assigned: Unassigned » tomtech

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.