laravel / cashier-paddle

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

Passing email on PayLink with custom Billable model #8

Closed enkota closed 4 years ago

enkota commented 4 years ago

Hey again,

When using something other than User for Billable I can't seem to pass through the customer_email parameter as specified on the Paddle docs.

$payLink = $tenant->newSubscription('default', $starter = 123456)
  ->returnTo(route('home'))
  ->create([
      'customer_email' => $tenant->owner->email,
       'prices' => ["USD:1200"]
  ]);

Price seems to work fine, but using customer_email will not pre-fill the email field. I have tried adding marketing_consent = 1 as it mentions this is required but no difference.

Thanks!

enkota commented 4 years ago

I can see under ManagesCustomer you are referencing the email column on the particular model. It would be good to override so we can set the customer_email in the create method.

    public function paddleEmail()
    {
        return $this->email;
    }
driesvints commented 4 years ago

Hey @enkota. Please read the core concepts in the docs, particularly the section here: https://laravel.com/docs/7.x/cashier-paddle#user-identification

We take over control of the customer_email key in Cashier to ensure every payment made is properly linked to the same use in Paddle. This is absolutely vital to make sure Cashier Paddle works properly.

Unfortunately this is due to how Paddle's user identification works and there's no other way for us to achieve this.

enkota commented 4 years ago

Hey @driesvints. I understand that you need to control the customer_email key, however, at the moment when using a different Billable model than User, the payLink will not assign to any email and require the user to enter one on the pop-up.

I do not need to update the email after creation, only the inital subscription where the Tenant owner is the relation to the user.

If you’d rather not allow the email to be passed on the create() method, would you allow the email to be passed through newSubscription()?

For my case, adding the relation to paddleEmail works perfectly since the Tenant belongs to the owner (User):

    public function paddleEmail()
    {
        return $this->owner->email;
    }

This would be useful as at the moment no email can be assigned on a Billable model outside User.

Thanks!

driesvints commented 4 years ago

If you’d rather not allow the email to be passed on the create() method, would you allow the email to be passed through newSubscription()?

Hmm we don't allow that anywhere?

I think you're looking for https://laravel.com/docs/7.x/cashier-paddle#customer-defaults. You can overwrite the paddleEmail method just like you did. It was intended to be used like this. I'm not sure if I understand you completely correctly?

enkota commented 4 years ago

Hey @driesvints ahh sorry, missed that part in the docs. Didn’t realise we could override that on the Model. All makes sense now :) Thanks!