You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: app/Jobs/CreateUserFromStripeCustomer.php
+10-4Lines changed: 10 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@
9
9
useIlluminate\Queue\InteractsWithQueue;
10
10
useIlluminate\Queue\SerializesModels;
11
11
useIlluminate\Support\Facades\Hash;
12
+
useIlluminate\Support\Facades\Log;
12
13
useIlluminate\Support\Str;
13
14
useLaravel\Cashier\Cashier;
14
15
useStripe\Customer;
@@ -21,14 +22,19 @@ public function __construct(public Customer $customer) {}
21
22
22
23
publicfunctionhandle(): void
23
24
{
24
-
if (Cashier::findBillable($this->customer)) {
25
-
$this->fail("A user already exists for Stripe customer [{$this->customer->id}].");
25
+
/** @var User $user */
26
+
if ($user = Cashier::findBillable($this->customer)) {
27
+
Log::debug("A user [{$user->id} | {$user->email}] with stripe_id [{$this->customer->id}] already exists.");
26
28
27
29
return;
28
30
}
29
31
30
-
if (User::query()->where('email', $this->customer->email)->exists()) {
31
-
$this->fail("A user already exists for email [{$this->customer->email}].");
32
+
if ($user = User::query()->where('email', $this->customer->email)->first()) {
33
+
// This could occur if a user performs/attempts multiple checkouts with the same email address.
34
+
// In the event all existing stripe customers for this email address do NOT have an active
35
+
// subscription, we could theoretically update the stripe_id for the existing user
36
+
// and continue. However, for now, we will throw an exception.
37
+
$this->fail("A user with email [{$user->email}] already exists but the current stripe_id [{$user->stripe_id}] does not match the new customer id [{$this->customer->id}].");
0 commit comments