Skip to content

Instantly share code, notes, and snippets.

@djekl
Created July 30, 2014 20:06
Show Gist options
  • Save djekl/83e601ac4e67d384cd11 to your computer and use it in GitHub Desktop.
Save djekl/83e601ac4e67d384cd11 to your computer and use it in GitHub Desktop.
Laravel Cashier Free Subscription w/o Credit Card Filter
<?php
Route::filter('stripe.plans.free', function() {
if (Auth::guest() || Auth::user()->subscribed()) {
return;
}
$user = Auth::user();
$chosenPlan = 'free';
$creditCardToken = null;
$additionalUserInformation = [
'plan' => $chosenPlan,
'email' => $user->email,
'metadata' => [
'user_id' => $user->id,
'username' => $user->username,
'username_slug' => $user->username_slug,
],
];
$customer = $user->subscription()->createStripeCustomer($creditCardToken, $additionalUserInformation);
$subscriptions = Collection::make($customer->subscriptions->data);
$subscription = $subscriptions->last();
$user->stripe_active = true;
$user->stripe_id = $customer->id;
$user->stripe_subscription = $subscription->id;
$user->stripe_plan = $chosenPlan;
$user->save();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment