Created
July 30, 2014 20:06
-
-
Save djekl/83e601ac4e67d384cd11 to your computer and use it in GitHub Desktop.
Laravel Cashier Free Subscription w/o Credit Card Filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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