From 07abb7f4bc39c4beee4721ca0bf685d4707bca42 Mon Sep 17 00:00:00 2001 From: i-just Date: Fri, 3 Jan 2025 15:23:43 +0000 Subject: [PATCH 1/4] use old email to search for stripe customers --- src/Plugin.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Plugin.php b/src/Plugin.php index 17dce99..6844975 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -619,7 +619,9 @@ private function handleUserElementChanges(): void $oldEmail = $userRecord->getAttribute('email'); $newEmail = $user->email; if ($oldEmail && $newEmail && ($oldEmail != $newEmail)) { + $user->email = $oldEmail; $customers = $user->getStripeCustomers(); + $user->email = $newEmail; if ($customers->isNotEmpty()) { $client = $this->getApi()->getClient(); foreach ($customers->all() as $customer) { From f97e6ab538bdeb33c22385e78e93bd2096ae1001 Mon Sep 17 00:00:00 2001 From: i-just Date: Tue, 7 Jan 2025 07:44:14 +0000 Subject: [PATCH 2/4] use getCustomersByEmail --- src/Plugin.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index 6844975..360985a 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -619,12 +619,10 @@ private function handleUserElementChanges(): void $oldEmail = $userRecord->getAttribute('email'); $newEmail = $user->email; if ($oldEmail && $newEmail && ($oldEmail != $newEmail)) { - $user->email = $oldEmail; - $customers = $user->getStripeCustomers(); - $user->email = $newEmail; - 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); From 11c9f9055b97d30591e72e318544ad44b1dd1b79 Mon Sep 17 00:00:00 2001 From: i-just Date: Tue, 7 Jan 2025 07:49:27 +0000 Subject: [PATCH 3/4] updated changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75d5e64..6d40fce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Release Notes for Stripe +## 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)) + ## 1.3.2 - 2024-12-11 - Fixed an error that occurred on Edit Entry screens if Stripe wasn’t configured with an API key. ([#66](https://github.com/craftcms/stripe/pull/66)) From ca004c51e3fe748631aa32d78229be1bb99542ce Mon Sep 17 00:00:00 2001 From: i-just Date: Tue, 7 Jan 2025 07:58:39 +0000 Subject: [PATCH 4/4] prettier --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d40fce..5688469 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Release Notes for Stripe ## 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)) ## 1.3.2 - 2024-12-11