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

Daniel-Pablo's avatar

Cashier official docs not working, some help please

Hi I am trying to make a subscription for the User Models but I can't make it work I got an error this is the exact part where is the error https://laravel.com/docs/9.x/billing#creating-subscriptions

as you can see this code

use Illuminate\Http\Request;
 
Route::post('/user/subscribe', function (Request $request) {
    $request->user()->newSubscription(
        'default', 'price_monthly'
    )->create($request->paymentMethodId);
 
    // ...
});

there is an error with the $request->paymentMethodId variable, or I can't make it work in fact, I do the following

    ray($request->paymentMethodId);
    ray($request->paymentMethod);

for both I got NULL so this parameter is not coming back from the front end... the thing is that I am following the exact documentation

I follow exactly this https://laravel.com/docs/9.x/billing#payment-methods-for-subscriptions

but I can't make this work, any help is more than appreciated, thanks in advance

0 likes
5 replies
Daniel-Pablo's avatar

yes all is working, in fact I can see that if I use the flag of TRIAL all is working even on the stripe side, BUT the payment method is the real problem, that parameter is not been sent from the front end side to the back end, I know because I RAY it and ray give me a NULL on both $request->paymentMethodId ... so far

return view('update-payment-method', [
    'intent' => $user->createSetupIntent()
]);

this is what you ask, this is been sent through the route to the subscription form, then this information is been proceeded and inserted in the form, then all the credit card stuff is doing the magic as explained In the Laravel guide but when you hit the update method but it try to do his best but this variable is not working, send null info

Thanks for your help @vmitchell85

vmitchell85's avatar

@Arius Tigger Do you see the paymentMethodId getting posted from the frontend to the /user/subscribe route?

Daniel-Pablo's avatar

@vmitchell85 I don't see it @vmitchell85 , in fact in the Laravel guides there is no input that has that name, so I have been thinking this is a field generated by the stripe JS script, but now I am starting to think that field doesn't exist...

Daniel-Pablo's avatar
Daniel-Pablo
OP
Best Answer
Level 12

@vmitchell85 thanks for your help, after reading a lot of documentation I finally find this tutorial https://laracasts.com/series/andres-larabits/episodes/20

Its a gem, thus explaining how this should be done, and in fact Andre's done it in a course called Laravel cashier here in laracast so, after all my intents, is really beneficial go step by step with the tutorial, this way I manage my way to achieve the integration of stripe and subscriptions

for any one that want to read and make the follow on this

    ray($request->paymentMethodId);
    ray($request->paymentMethod);

this return NULL because no parameter was returned, the way Andre's done it is with the following code

var form = document.getElementById('payment-form');
                var hiddenInput = document.createElement('input');
                hiddenInput.setAttribute('type', 'hidden');
                hiddenInput.setAttribute('name', 'paymentMethod');
                hiddenInput.setAttribute('value', setupIntent.payment_method);
                form.appendChild(hiddenInput);
                form.submit();

as you can see he adds the paymentMethod field, after all the process so when he send the information to your post route, you can on that action have access to that variable, the one that was NULL for me thus I never create that before

@vmitchell85 Thanks for your help

1 like

Please or to participate in this conversation.