laravel / cashier-stripe

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.
https://laravel.com/docs/billing
MIT License
2.37k stars 671 forks source link

asStripeCustomer() should throw InvalidStripeCustomer #833

Closed Xenonym closed 4 years ago

Xenonym commented 4 years ago

Description:

If a user is not yet associated with a Stripe customer, calling asStripeCustomer() throws a Stripe\Exception\UnexpectedValueException with the message:

Could not determine which URL to request: Stripe\Customer instance has invalid ID: 

This is different from the other methods in Billable, which throw a Laravel\Cashier\Exceptions\InvalidCustomerException when the user is not associated with a Stripe customer.

Should calling asStripeCustomer() also do a assertCustomerExists() check? This will make the behaviour of asStripeCustomer() consistent with the others in Billable. I can put up a PR for this if my assessment is accurate.

Steps To Reproduce:

  1. Call asStripeCustomer() on a Billable model with no stripe_id. An UnexpectedValueException will be thrown.
driesvints commented 4 years ago

Thanks. Whipped up a PR for this quickly: https://github.com/laravel/cashier/pull/834