Add the option to not setup payment methods for future usage

Created on 8 October 2023, about 1 year ago
Updated 22 July 2024, 5 months ago

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

✨ Feature request
Status

Fixed

Version

1.0

Component

User interface

Created by

πŸ‡ΊπŸ‡ΈUnited States smokris Athens, Ohio, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @smokris
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    38 pass
  • πŸ‡ΊπŸ‡ΈUnited States smokris Athens, Ohio, USA

    Patch attached.

  • Status changed to Needs work about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States rszrama

    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. πŸ˜›

  • πŸ‡ΊπŸ‡¦Ukraine marchuk.vitaliy Rivne, UA

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

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    20 pass, 2 fail
  • πŸ‡ΊπŸ‡¦Ukraine marchuk.vitaliy Rivne, UA

    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.

  • πŸ‡ΊπŸ‡¦Ukraine marchuk.vitaliy Rivne, UA

    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.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    20 pass, 2 fail
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    20 pass, 2 fail
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    53:42
    51:35
    Running
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    38 pass
  • Status changed to Needs review about 1 year ago
  • πŸ‡ΊπŸ‡¦Ukraine marchuk.vitaliy Rivne, UA

    From my comment ✨ Add the option to not setup payment methods for future usage Fixed 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.

  • Status changed to RTBC 12 months ago
  • πŸ‡¨πŸ‡³China skyredwang Shanghai

    https://www.drupal.org/project/commerce_stripe/issues/3392413#mr56-note2... ✨ Add the option to not setup payment methods for future usage Fixed 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.

  • Status changed to Needs review 12 months ago
  • πŸ‡¨πŸ‡³China skyredwang Shanghai

    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?

  • Pipeline finished with Success
    12 months ago
    #73031
  • Status changed to Needs work 12 months ago
  • πŸ‡¨πŸ‡³China skyredwang Shanghai

    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.

  • Status changed to Needs review 12 months ago
  • πŸ‡¨πŸ‡³China skyredwang Shanghai

    In https://www.drupal.org/project/commerce_stripe/issues/3392413#mr56-note2... ✨ Add the option to not setup payment methods for future usage Fixed , I added a condition.

  • Pipeline finished with Success
    12 months ago
    #73484
  • πŸ‡¦πŸ‡ΉAustria agoradesign

    Coming from #3403745-4: Why is stripe-php still stuck on version 7 and Stripe API on 2019-12-03? What does it imply? β†’ , I've tried this patch (latest MR) and it solved our problem :-)

  • πŸ‡«πŸ‡·France nicolas bouteille

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

  • πŸ‡ΊπŸ‡ΈUnited States loze Los Angeles

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

  • πŸ‡ΊπŸ‡¦Ukraine marchuk.vitaliy Rivne, UA

    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.

  • First commit to issue fork.
  • Status changed to Fixed 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States TomTech
  • Assigned to TomTech
  • πŸ‡ΊπŸ‡ΈUnited States TomTech
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024