laravel / cashier-stripe

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

Cashier with Company Model (wo. email) #485

Closed ApplicationError closed 4 years ago

ApplicationError commented 6 years ago

I am encountering an error, and I'm wondering if this could be caused by the fact that I configured cashier to use my 'Company' model instead of the 'User' model. My 'companies' table does not have an 'email' column. I am suspecting that this could be the cause of the error I'm getting.

The error:

[2018-01-13 12:34:09] local.ERROR: No such customer: tok_1BjoD0LrP3RyeWsmYarCAfom {"userId":24,"email":"daluk@test.com","exception":"[object] (Stripe\\Error\\InvalidRequest(code: 0): No such customer: tok_1BjoD0LrP3RyeWsmYarCAfom at .../vendor/stripe/stripe-php/lib/ApiRequestor.php:124)

Thoughts?

mr-mmmmore commented 6 years ago

I'm going to add a Stripe payment to my website with Cashier and I don't have an email field in my Billable model either.

I find it weird that there is a reference to an email field in the using model, in the Billable::createAsStripeCustomer method:

public function createAsStripeCustomer($token, array $options = [])
    {
        $options = array_key_exists('email', $options)
                ? $options : array_merge($options, ['email' => $this->email]);

        // ...

(@ApplicationError this may be what causes your error, but it's hard to tell since you provide no information on how to reproduce your error).

I'm wondering why there is such a hard-coded reference to an email member... In Billable we don't know anything about the model that will use the trait. As far as I can see, this email is just added to the options when creating the Stripe Customer so it is easier to find in the Stripe admin. The email field is not required when creating a Stripe Customer, so, the email should not be mandatory in the Billable Model... (or if so it should be said in the docs, but I don't think it should).

Maybe the existence of the email member should be tested and added to the options only if present?

shabaz-ejaz commented 6 years ago

@ApplicationError Did you manage to use the Company model as the billable model okay? I also have the exact same use-case and was wondering whether this will cause any problems later?

driesvints commented 6 years ago

Hmm, I agree. Email shouldn't be a requirement. I'll mark this as a feature request. Welcoming PRs for this.

GavinCS commented 5 years ago

Based on the Billable::createAsStripeCustomer method, you could just pass in an empty email key. However considering the benefits that providing an emails gives you / your companies in terms of automatic notifications on failed payments, etc, that are provided by Stripe. Why not provide a company billing/accounts email, someone needs to know about billing after all.

driesvints commented 4 years ago

Sent in a PR to https://github.com/laravel/cashier/pull/887