Cannot make payments - intent is succeeded

Created on 17 August 2021, over 3 years ago
Updated 12 April 2024, 8 months ago

Problem/Motivation

I can only make one payment with a webform with a stripe element (Stripe Credit Card). If I remove the element and re-create it I get another go.

I get an error in Chrome's console:
donate?ajax_form=1&_wrapper_format=drupal_ajax:1 Failed to load resource: the server responded with a status of 500 ()
ajax.js?v=9.2.0:513 Uncaught Drupal.AjaxErrormessage: "\nAn AJAX HTTP error occurred.\nHTTP Result Code: 500\nDebugging information follows.\nPath: /donate?ajax_form=1\nStatusText: error\nResponseText: The website encountered an unexpected error. Please try again later.Stripe\\Exception\\InvalidRequestException: This PaymentIntent's amount could not be updated because it has a status of succeeded. You may only update the amount of a PaymentIntent with one of the following statuses: requires_payment_method, requires_confirmation, requires_action. in Stripe\\Exception\

So for some reason it is trying to update the same payment intent each time.

Apologies if this should be in the Stripe module queue as I am not sure which module is causing this.

Steps to reproduce

Create a webform with an amount, name, email address and address part elements minimum. Add a Stripe credit card element that refers to these elements in the webform submission.

Validation on the card fields work. One payment can be successfully made.

After that one successful payment, each click of the submit button will generate the above Ajax error. This happens whether the card fields are valid or not.

If you then remove the Stripe element, save the webform definition, re-add the stripe element and save again, you can then make another payment.

Proposed resolution

Make sure code is always doing a new intent.

Remaining tasks

Unknown

User interface changes

No

API changes

No

Data model changes

Unknown

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom Rory Downes

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • @piscos I am getting the same error. Do you recall exactly the steps you took to disable the cache for the webform? I have not found an obvious config for that. Thanks.

  • We managed to get past this issue by adding this to our custom theme's THEME.theme file:

    function THEME_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
      if (str_starts_with($form_id, '<start of webform id>') { // client occasionally made changes that altered form id
        $form['#cache']['contexts'][] = 'session';
        Drupal::service('page_cache_kill_switch')->trigger();
      }
    }
    
    
Production build 0.71.5 2024