Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Cashier - Create New Subscription With Existing Customer Object

I'm using Laravel Cashier along with Stripe to manage subscriptions. The user will supply their credit card information when signing up, but they won't be subscribed in a specific plan at this point. So I can successfully use Stripe Checkout to create a Stripe customer object and save the Stripe customer ID in my database. But when it comes time for the user to enroll in a plan, I can't see a way to use the Stripe customer ID to enroll them in the plan they want.

Of course, I could ask for their credit card information again and get a Stripe token to use with Laravel Cashier, but I'd like to avoid this since the app already created a Stripe customer object when they signed up and I'd like to simply use the existing customer object to charge their credit card rather than asking for their card number again.

To try illustrate what I'm trying to do, here is some sample code from the Laravel docs:

$user->newSubscription('main', 'monthly')->create($creditCardToken);

But what I'd like to be able to do is something like this (note the change to the create method:

$user->newSubscription('main', 'monthly')->create($user->stripe_id);

Any advice?

like image 226
BakerStreetSystems Avatar asked Mar 30 '16 17:03

BakerStreetSystems


1 Answers

If there is a stripe ID for the user, you don't have to supply the token

$user->newSubscription('main', 'monthly')->create();

Have a look at the SubscriptionBuilder class.

like image 199
Tosho Trajanov Avatar answered Nov 15 '22 00:11

Tosho Trajanov