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();
});