Move CoF saving and Stripe source creation to webhooks (configurable)

Created on 14 November 2017, almost 8 years ago
Updated 18 August 2025, about 1 month ago

In New Relic, I'm noticing that the API calls to Stripe can sometimes take a while. Currently, we have three things (potentially) happening when the payment form is submitted:

1. A charge is created.
2. A source is created at Stripe.
3. A Card on File entity is created.

In addition, I have new code in the works that updates the Stripe source if a user updates her Commerce Billing address/profile, to make sure the saved card stays current if the customer has moved and needs to update.

Stripe's docs recommend deferring all of these other API calls that are not strictly token- and charge-related into a webhook processor. I think this will be a good idea for sites like ours with lots of concurrent users who are looking to optimize performance however they can.

My idea is the following:

1. First, allow an option for store admins to choose either "At runtime" (default) or "From webhooks" for when and how to save user's cards during checkout.
2. Upon successful charge event, save the generated Stripe token within the $order->data array.
3. When a *.payment_succeeded webhook is received, if configured, retrieve the source and then:
4. If configured to, save the data as a Card on File, as well as a new Source for the customer.
5. This will also mean deferring the creation of a Stripe Customer to the webhook, since saving a card requires it (and we may not always want or need to create a Customer at checkout).

We might need to include additional information in the order, for example a customer_id if applicable.

I'll spin these off into some child issues, including a) new data to save with the order, and b) what events should react upon Webhook receiption, based on what we're doing currently in commerce_stripe_submit_form_submit().

πŸ“Œ Task
Status

Closed: outdated

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States torgosPizza Portland, OR

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.

Production build 0.71.5 2024