diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e554c2..fb2f653 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Plugin.php b/src/Plugin.php index 17dce99..360985a 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -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);