Getting error "Couldn't load payment data" while capturing payment

Created on 27 June 2023, about 1 year ago

Problem/Motivation

Sending a request to `/commerce/payment/capture/${orderId}/${paymentId}` after confirming the payment using Stripe.js v3 on the client side results in getting 400 Bad Request response from the server with this body:
{"message":"Couldn't load payment data."}

Steps to reproduce

Explained above.

Proposed resolution

Seems like commerce_decoupled_stripe is using an older version of the "stripe/stripe-php" package. Probably some time in the past Stripe stopped sending "$intent->charges" in its response, and the $intent object doesn't contain any information about the card that was used to make the payment, but it does include the "latest_charge" ID. The only way to retrieve this data seems to be by sending a separate request to retrieve the charge, but $intent->latest_charge is undefined because of the old version of the "stripe/stripe-php" package.

The merge request updates the "stripe/stripe-php" package to "~10.0".

StripeGateway::capturePayment() checks to see if $intent->charges exists, and if so, it won't do anything and continues as before.
If it doesn't exist, it'll look for $intent->latest_charge and if it's not empty, it'll retrieve it.
If $intent->latest_charge is also empty, it'll return the same "Couldn't load payment data" error.

Remaining tasks

none

User interface changes

none

API changes

none

Data model changes

none

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

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

Comments & Activities

  • Issue created by @farhadhf
  • @farhadhf opened merge request.
Production build 0.69.0 2024