Skip to content

Commit 4b257bc

Browse files
james-allanMayisha
andauthored
Fix Uncaught TypeError: Argument 2 passed to WC_Stripe_API::detach_payment_method_from_customer() errors (#3334)
* Pull the source/payment method ID from the last error correctly * change changelog entries * Fix duplicate changelog entry --------- Co-authored-by: Mayisha <[email protected]>
1 parent 4468d29 commit 4b257bc

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* Fix - Prevent displaying the default admin description on the checkout page when a payment method description is empty.
2222
* Fix - Adds back the ability to perform direct refunds for giropay orders via the order details page.
2323
* Fix - After configuring webhooks automatically ensure only the latest webhook endpoint is active, deleting duplicates configured manually.
24+
* Fix - Resolved PHP errors related to detaching payment methods after failed 3D-Secure challenges.
2425
* Tweak - Minor text updates to webhook-related configuration labels and buttons.
2526
* Tweak - Improve UX by using the 3DS verification modal to confirm setup intents for subscription sign-ups, ensuring customers stay on the checkout page.
2627
* Tweak - Display a notice when the Stripe connect URL is not available.

includes/class-wc-stripe-customer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ public function get_payment_methods( $payment_method_type ) {
540540
* @param string $source_id
541541
*/
542542
public function delete_source( $source_id ) {
543-
if ( ! $this->get_id() ) {
543+
if ( empty( $source_id ) || ! $this->get_id() ) {
544544
return false;
545545
}
546546

includes/class-wc-stripe-intent-controller.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,23 @@ public function verify_intent() {
128128
if ( isset( $_GET['save_payment_method'] ) && ! empty( $_GET['save_payment_method'] ) ) {
129129
$intent = $gateway->get_intent_from_order( $order );
130130
if ( isset( $intent->last_payment_error ) ) {
131+
$last_payment_error = $intent->last_payment_error;
132+
$source_id = '';
133+
134+
// Backwards compatibility for payment intents that use sources.
135+
if ( isset( $last_payment_error->payment_method->id ) ) {
136+
$source_id = $last_payment_error->payment_method->id;
137+
} elseif ( isset( $last_payment_error->source->id ) ) {
138+
$source_id = $last_payment_error->source->id;
139+
}
140+
131141
// Currently, Stripe saves the payment method even if the authentication fails for 3DS cards.
132142
// Although, the card is not stored in DB we need to remove the source from the customer on Stripe
133143
// in order to keep the sources in sync with the data in DB.
134-
$customer = new WC_Stripe_Customer( wp_get_current_user()->ID );
135-
$customer->delete_source( $intent->last_payment_error->source->id );
144+
if ( ! empty( $source_id ) ) {
145+
$customer = new WC_Stripe_Customer( wp_get_current_user()->ID );
146+
$customer->delete_source( $source_id );
147+
}
136148
} else {
137149
$metadata = $intent->metadata;
138150
if ( isset( $metadata->save_payment_method ) && 'true' === $metadata->save_payment_method ) {

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ If you get stuck, you can ask for help in the Plugin Forum.
149149
* Fix - Prevent displaying the default admin description on the checkout page when a payment method description is empty.
150150
* Fix - Adds back the ability to perform direct refunds for giropay orders via the order details page.
151151
* Fix - After configuring webhooks automatically ensure only the latest webhook endpoint is active, deleting duplicates configured manually.
152+
* Fix - Resolved PHP errors related to detaching payment methods after failed 3D-Secure challenges.
152153
* Tweak - Minor text updates to webhook-related configuration labels and buttons.
153154
* Tweak - Improve UX by using the 3DS verification modal to confirm setup intents for subscription sign-ups, ensuring customers stay on the checkout page.
154155
* Tweak - Display a notice when the Stripe connect URL is not available.

0 commit comments

Comments
 (0)