Skip to content

Commit

Permalink
Merge pull request #280 from craftcms/support-legacy-default-source
Browse files Browse the repository at this point in the history
Support legacy default_source
  • Loading branch information
lukeholder committed Jan 4, 2024
2 parents 495abd2 + d6bca22 commit ec0e541
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
10 changes: 6 additions & 4 deletions src/base/SubscriptionGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit ec0e541

Please sign in to comment.