Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Marcolino922's avatar

Stripe\PaymentMethod instance has invalid ID:

Hi, I'm following this tutorial to create subscriptions via cashier / stripe, unfortunately, however, after entering the test credit card credentials, and sending, this error appears:

https://medium.com/fabcoding/laravel-7-create-a-subscription-system-using-cashier-stripe-77cdf5c8ea5d

Could not determine which URL to request: Stripe\PaymentMethod instance has invalid ID:

I searched around for a while, but I haven't solved it.

  • After submitting the form, the stripe_id field in the users table is regularly filled in.

public function retrievePlans() {
        $key = \config('services.stripe.secret');
        $stripe = new \Stripe\StripeClient($key);
        $plansraw = $stripe->plans->all();
        $plans = $plansraw->data;
       
        foreach($plans as $plan) {
            $prod = $stripe->products->retrieve(
                $plan->product,[]
            );
            $plan->product = $prod;
        }
        return $plans;
    }
    
    public function showSubscription() {
       
        $plans = $this->retrievePlans();
        $user = Auth::user();
       
        return view('subscribe')->with([
            'site_name' => Settings::find('site_name')->value,
            'site_description' => __(''),
            'page_name' => __('Exclusive Content for Subscribers'),
            'categories' => $this->categories,
            'user' => $user,
            'intent' => $user->createSetupIntent(),
            'plans' => $plans
        ]);
    }
    
   public function processSubscription(Request $request)
   {
       $user = Auth::user();
       $paymentMethod = $request->input('payment_method');
                   
       $user->createOrGetStripeCustomer();
       $user->addPaymentMethod($paymentMethod);
       $plan = $request->input('plan');
       try {
           $user->newSubscription('default', $plan)->create($paymentMethod, [
               'email' => $user->email
           ]);
       } catch (\Exception $e) {
           return back()->withErrors(['message' => 'Error creating subscription. ' . $e->getMessage()]);
       }
       
       return redirect('dashboard');
   }

0 likes
1 reply
Marcolino922's avatar

I checked in the events, in the developer section of Stripe, and SetupIntent is created.

Please or to participate in this conversation.