From c360cf59122612394ddc52b6b5d5d21031e46de8 Mon Sep 17 00:00:00 2001 From: Don Cadavona Date: Fri, 19 Jul 2024 06:04:55 +0000 Subject: [PATCH 1/3] Throw an informative error when there is no name set for the customer --- src/Concerns/ManagesCustomer.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Concerns/ManagesCustomer.php b/src/Concerns/ManagesCustomer.php index c241221..b06aa11 100644 --- a/src/Concerns/ManagesCustomer.php +++ b/src/Concerns/ManagesCustomer.php @@ -45,6 +45,10 @@ public function createAsCustomer(array $options = []) $response = Cashier::api('POST', 'customers', $options)['data']; } + if (is_null($response['name'])) { + throw new LogicException("The Paddle customer [{$response['id']}] has no name. You may need to set the name of the customer in the Paddle dasbhboard."); + } + if (Cashier::$customerModel::where('paddle_id', $response['id'])->exists()) { throw new LogicException("The Paddle customer [{$response['id']}] already exists in the database."); } From 2cb3bda9283e05c209c08b8941db48159f77c643 Mon Sep 17 00:00:00 2001 From: Don Cadavona Date: Tue, 23 Jul 2024 05:59:25 +0000 Subject: [PATCH 2/3] Save the name of the customer as an empty string in the database if it is not set in Paddle. --- src/Concerns/ManagesCustomer.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Concerns/ManagesCustomer.php b/src/Concerns/ManagesCustomer.php index b06aa11..75a681b 100644 --- a/src/Concerns/ManagesCustomer.php +++ b/src/Concerns/ManagesCustomer.php @@ -45,17 +45,13 @@ public function createAsCustomer(array $options = []) $response = Cashier::api('POST', 'customers', $options)['data']; } - if (is_null($response['name'])) { - throw new LogicException("The Paddle customer [{$response['id']}] has no name. You may need to set the name of the customer in the Paddle dasbhboard."); - } - if (Cashier::$customerModel::where('paddle_id', $response['id'])->exists()) { throw new LogicException("The Paddle customer [{$response['id']}] already exists in the database."); } $customer = $this->customer()->make(); $customer->paddle_id = $response['id']; - $customer->name = $response['name']; + $customer->name = $response['name'] ?? ''; $customer->email = $response['email']; $customer->trial_ends_at = $trialEndsAt; $customer->save(); From fc522fef90c775b74aa285db08e79cae4f95fbbc Mon Sep 17 00:00:00 2001 From: Don Cadavona Date: Tue, 23 Jul 2024 07:26:59 +0000 Subject: [PATCH 3/3] Update the name of the customer as an empty string in the database if it is not set in Paddle. --- src/Http/Controllers/WebhookController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Http/Controllers/WebhookController.php b/src/Http/Controllers/WebhookController.php index 8ba3bfa..ee1be9c 100644 --- a/src/Http/Controllers/WebhookController.php +++ b/src/Http/Controllers/WebhookController.php @@ -74,7 +74,7 @@ protected function handleCustomerUpdated(array $payload) } $customer->update([ - 'name' => $data['name'], + 'name' => $data['name'] ?? '', 'email' => $data['email'], ]);