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

->withMetadata but for customer instead of subscription #776

Closed reillychase closed 5 years ago

reillychase commented 5 years ago

I am working on integrating getRewardful affiliate program with Laravel Spark.

The way it works is you add Javascript to layouts/app.blade.php for example to check for a referral cookie. If found it injects a field into the register form on /register.

On the backend I am checking for that being submitted in /src/Interactions/SubscribeTeam.php

Then I need to take it and add it to a metadata 'referral' field when creating the customer (with Cashier's newSubscription function).

If I do ->withMetadata, it adds the referral to the Stripe subscription, but it needs to be added to the Stripe customer.

After looking into this, there appears to be no way to add metadata to the customer instead of the subscription in Cashier, so I have to hack my own API call instead.

driesvints commented 5 years ago

There's the createAsStripeCustomer method on the Billable entity which accepts an $options parameter and the create method on the SubscriptionBuilder als accepts an $options array where you can pass the metadata.