laravel / cashier-paddle

Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.
https://laravel.com/docs/cashier-paddle
MIT License
238 stars 57 forks source link

Handle empty name values for a customer #268

Closed doncadavona closed 1 month ago

doncadavona commented 1 month ago

Gracefully throw an error for the case where there is no name set for the customer.

See https://github.com/laravel/cashier-paddle/issues/266.

doncadavona commented 1 month ago

I think so too. Yes, let me try and adjust the name to be nullable.

doncadavona commented 1 month ago

Hi @driesvints ,

I have finally found a clean way of handling the issue, instead of throwing an error (as I initially thought of) when the name is not set in Paddle, like so:

// File src/Concerns/ManagesCustomer.php

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.");
}

We could simply have the customer name as an empty string, if it is empty in Paddle, like so:

// File src/Concerns/ManagesCustomer.php at line 54

$customer->name = $response['name'] ?? '';

Please check my latest commit in this MR.

driesvints commented 1 month ago

Amazing @doncadavona, thanks for that clean solution. Could we also update other places where we set the name like in the webhooks?

doncadavona commented 1 month ago

Hi @driesvints ,

I just updated this section in the webhook where the customer name was also being set:

https://github.com/laravel/cashier-paddle/pull/268/commits/fc522fef90c775b74aa285db08e79cae4f95fbbc

Thanks for pointing that out too.