Skip to content

Commit

Permalink
Merge pull request #73 from craftcms/bugfix/69-sync-changed-user-emai…
Browse files Browse the repository at this point in the history
…ls-to-stripe

use old email to search for stripe customers
  • Loading branch information
i-just authored Jan 15, 2025
2 parents 3600d20 + ad66108 commit b4d81fa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Fixed a bug where Craft user’s email address was not synced to Stripe even if `syncChangedUserEmailsToStripe` was set to `true`. ([#69](https://github.com/craftcms/stripe/issues/69))
- Fixed a bug where the plugin was attempting to create missing users when `createUserIfMissing` was `true` but the Craft edition didn’t allow for multiple users. ([#72](https://github.com/craftcms/stripe/pull/72))

## 1.3.2 - 2024-12-11
Expand Down
6 changes: 3 additions & 3 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,10 +619,10 @@ private function handleUserElementChanges(): void
$oldEmail = $userRecord->getAttribute('email');
$newEmail = $user->email;
if ($oldEmail && $newEmail && ($oldEmail != $newEmail)) {
$customers = $user->getStripeCustomers();
if ($customers->isNotEmpty()) {
$customers = Plugin::getInstance()->getCustomers()->getCustomersByEmail($oldEmail);
if (!empty($customers)) {
$client = $this->getApi()->getClient();
foreach ($customers->all() as $customer) {
foreach ($customers as $customer) {
try {
$updatedCustomer = $client->customers->update($customer->stripeId, ['email' => $newEmail]);
$this->getCustomers()->createOrUpdateCustomer($updatedCustomer);
Expand Down

0 comments on commit b4d81fa

Please sign in to comment.