diff --git a/CHANGELOG.md b/CHANGELOG.md index 927c2ac..532f63f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Stripe for Craft Commerce +## Unreleased + +- Fixed a bug where legacy default payment methods were not being set as default. ([#280](https://github.com/craftcms/commerce-stripe/pull/280)) + ## 4.1.0 - 2023-12-19 - Stripe for Craft Commerce now requires Commerce 4.3.3 or later. diff --git a/src/base/SubscriptionGateway.php b/src/base/SubscriptionGateway.php index 6ad717b..f4231d8 100644 --- a/src/base/SubscriptionGateway.php +++ b/src/base/SubscriptionGateway.php @@ -812,10 +812,12 @@ public function handleCustomerUpdated(array $data): void { $stripeCustomer = $data['data']['object']; - // Set the primary payment source for the user if it has changed - if (isset($stripeCustomer['invoice_settings']['default_payment_method'])) { - $paymentMethodId = $stripeCustomer['invoice_settings']['default_payment_method']; + $defaultPaymentMethod = $stripeCustomer['invoice_settings']['default_payment_method'] + ?? $stripeCustomer['default_source'] + ?? null; + // Set the primary payment source for the user if it has changed + if ($defaultPaymentMethod) { $customer = StripePlugin::getInstance()->getCustomers()->getCustomerByReference($stripeCustomer['id'], $this->id); if (!$customer) { return; @@ -827,7 +829,7 @@ public function handleCustomerUpdated(array $data): void return; } - $paymentSource = CommercePlugin::getInstance()->getPaymentSources()->getPaymentSourceByTokenAndGatewayId($paymentMethodId, $this->id); + $paymentSource = CommercePlugin::getInstance()->getPaymentSources()->getPaymentSourceByTokenAndGatewayId($defaultPaymentMethod, $this->id); if (!$paymentSource) { return; }