Created
June 24, 2020 18:23
-
-
Save karakanb/2e455211ea404415e7f5833c6c6d1b06 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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