laravel / cashier-paddle

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

Unable to re-register a User in Laravel because of previous Customer record #281

Closed devinfd closed 2 months ago

devinfd commented 2 months ago

Cashier Paddle Version

2.5.2

Laravel Version

11.23.5

PHP Version

8.3.11

Database Driver & Version

SingleStore

Description

Related to https://github.com/laravel/cashier-paddle/issues/274

I was getting a Paddle Customer already exists in the database error which didn't make sense to me. In my case the user was archived in Paddle. With the current code logic it seems that if a user cancels their account and their Paddle status becomes archived then that user can't return to the "service" as user again with the same email address?

Why is a LogicException thrown in ManagesCustomer@createAsCustomer? The doc blocks for createAsCustomer don't indicate that an exception will be thrown. Shouldn't the $customer object just be returned if one is found matching the Paddle ID? Then make an API PUT request to update the user status to 'active' if they are archived?

Steps To Reproduce

  1. Register a user in a Laravel application using Laravel/cashier-paddle.
  2. Delete the user and mark them as archived in Paddle.
  3. Try to register that user again in the Laravel Application.

I would be happy to submit a PR if this is acceptable.

driesvints commented 2 months ago

It's because paddle_id needs to be unique: https://github.com/laravel/cashier-paddle/blob/a7cd9a9a3f71617a8a4080f80f72568c219106a7/database/migrations/2019_05_03_000001_create_customers_table.php#L17

If you have a user canceling their account and returning with the same email address then you should either restore their original user account or make sure the old paddle customer record isn't in the database anymore.

We need the unique paddle_id on the paddle customer table because it's a foundation of how the package works and maps subscriptions to it. It also doesn't makes sense to connect a paddle customer record to multiple users. One paddle customer record matches a single user.

devinfd commented 2 months ago

@driesvints thank you, that makes sense. Just one follow up question: In addition to deleting the Customer if the user cancels their account, is it also advisable to keep the User and Customer models in sync? ie: if the User's name or email changes then the Customer modelname/email should change as well?

driesvints commented 1 month ago

No these don't necessarily need to be the same. The email and name column on the customer record reflect's what's in paddle. You could have separate legal/billing name and email for invoicing and a separate email/name for your billable.

For example, You're Devin and your company is named Acme company with invoicing@acme.com