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

前端 未结 6 1797
暖寄归人
暖寄归人 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 16:42

    Solved for Laravel 5.8 and Cashier 10.2

    PlanController:

    public function show(\App\Plan $plan, Request $request)
    {
        $paymentMethods = $request->user()->paymentMethods();
    
        $intent = $request->user()->createSetupIntent();
        return view('plans.show', compact('plan', 'intent'));
    }
    

    View:

    
    

    ...

    
    
    

    SubscriptionController

    public function create(Request $request, \App\Plan $plan)
    {
        $plan = \App\Plan::findOrFail($request->get('plan'));
        $user = $request->user();
        $paymentMethod = $request->paymentMethod;
    
        $user->createOrGetStripeCustomer();
        $user->updateDefaultPaymentMethod($paymentMethod);
        $user
            ->newSubscription('main', $plan->stripe_plan)
            ->trialDays(7)
            ->create($paymentMethod, [
                'email' => $user->email,
            ]);
    
        return redirect()->route('home')->with('status', 'Your plan subscribed successfully');
    }
    

提交回复
热议问题