Skip to content

Instantly share code, notes, and snippets.

@karakanb
Created June 24, 2020 18:23
Show Gist options
  • Save karakanb/2e455211ea404415e7f5833c6c6d1b06 to your computer and use it in GitHub Desktop.
Save karakanb/2e455211ea404415e7f5833c6c6d1b06 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
class PlansController extends Controller
{
public function save(Request $request, string $plan)
{
/** @var User $user */
$user = $request->user();
$token = $request->get('paymentMethodId');
$couponCode = $request->get('couponCode');
// Build the subscription object.
$subscriptionBuilder = $user->newSubscription('default', $plan);
if ($couponCode) {
$subscriptionBuilder->withCoupon($couponCode);
}
// Create the subscription.
$subscriptionBuilder->create($token);
return redirect(route('home'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment