Laravel Cashier creating customer without subscription
Our app initially stores the user's credit card with Stripe, and only bills them when they purchase a given product at a later date.
We're considering switching to Laravel 5 but I can't seem to find anywhere in Laravel Cashier instructions on simply storing a token of a card (really a token obtained by Stripe.js) for future billing.
I've installed LC locally and see a stripe_id field in the users table. Is it just a matter of assigning it $user->stripe_id = \Request::input('stripe_customer_token')?
As it utilizes subscriptions to charge at intervals. Changing the logic to your business logic should be do able. Set the token when a user adds a card, how ever is done in your app. I probably would set a boolean value that a user has a card available. Then when needed charge the user.
Most of it would be how you have stripe set up on that end.
My solution to this was to add a method to my Billable class (aka: App\User)
public function setBillingCard($stripeToken) {
if ($this->stripeIsActive()) {
return $this->updateCard($stripeToken);
}
$stripeGateway = $this->subscription();
$customer = $stripeGateway->createStripeCustomer($stripeToken, [
'email' => $this->email
]);
return $stripeGateway->updateLocalStripeData($customer);
}
One thing to note, because the database field stripe_active will be set to true, the $user->subscribed() method will always return true. I decided to write another method to check against the $user->stripe_subscription along with $user->onGracePeriod().
If you have no intentions on allowing subscriptions then you have no need for Cashier and you can just use the Stripe php library for everything you need. Create the customer and store the card. Then when they buy something just charge the customer, not the card.
I had some success adding a card without a subscription by running this on Laravel 5:
//pass the user object to the gateway; it must implement BillableContract
$gateway = new \Laravel\Cashier\StripeGateway($user);
//manually create a new Customer instance with Stripe
$customer = $gateway->createStripeCustomer($request->get('stripe_token'));
//update the model's info
$gateway->updateLocalStripeData($customer);