Trouble setting up a subscription with Laravel 5.8 / Cashier / Stripe

前端 未结 6 1751
暖寄归人
暖寄归人 2020-12-30 16:38

I followed this tutorial step by step: https://appdividend.com/2018/12/05/laravel-stripe-payment-gateway-integration-tutorial-with-example/

However, when I go to tes

6条回答
  •  有刺的猬
    2020-12-30 17:05

    I think your problem may be the create method. Try this:

        namespace App\Http\Controllers;
    use Illuminate\Http\Request;
    use App\Plan;
    
    class SubscriptionController extends Controller {
        public function create(Request $request, Plan $plan) {
            $plan = Plan::findOrFail($request->get('plan'));
    
            \Auth::user() //make sure your user is signed in and use the authenticated user
                ->newSubscription('main', $request->plan) //You just send the name of the subscription in Stripe, not the object
                ->create($request->stripeToken);
    
            return redirect()->route('home')->with('success', 'Your plan subscribed successfully');
    }
    

    I think your problem is because you were using an invalid user and / or because you're sending a plan object instead of the payment plan's name. For example, if you have a product named Main in Stripe with pricing plans called "Plan 1" and "Plan 2", to subscribe your authenticated user, you'd do this:

    \Auth::user
        ->newSubscription('Main', 'Plan 1')
        ->create($request->stripeToken);
    

    And your Stripe Product should look something like this:

提交回复
热议问题