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

dan3460's avatar

Subscription on User Registration

There is another post with exactly this same problem but never got answered, given it another try. I have Cashier and Stripe. I'm trying to create a subscription at the same time that the user creates the account. I'm getting the token back from Stripe and the customer is being created in the Stripe site, but the subscription is throwing an error because I'm passing the token to the subscription call:

 $response = $user->newSubscription('Subscription', $input['subscription'])
            ->create($input['stripeToken']);

This is the error that i'm getting:

Stripe\Exception\InvalidRequestException
No such PaymentMethod: 'tok_1IC2fyDAAbDeUdItaxkZNwTk'
http://127.0.0.1:8000/register

All the solutions that i have seen consist on the registration and a latter page to enter credit card information. Is there a way to do this in one operation as the customer is registering.

0 likes
2 replies
srasch's avatar

I did something similar a few month ago.

This is my "old" controller before I switched everything to Livewire to make it smoother :)

Maybe this helps:

<?php

namespace App\Http\Controllers\Auth;


use App\Http\Controllers\Controller;
use App\Jobs\CreateServer;
use App\Models\Customer;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use Stripe\{Subscription, PaymentMethod, Checkout\Session};
use Stripe\Customer as StripeCustomer;


class RegisterController extends Controller
{

    use RegistersUsers;


    protected $redirectTo = '/backend/dashboard';


    public function showRegistrationForm()
    {

        return view('auth.register')->with([
            'failed' => false
        ]);
    }


    public function success( Request $request )
    {

        $sessionId = $request->input('session_id');

        $session = Session::retrieve($sessionId);
        $customer = Customer::find($session->client_reference_id);

        $sub = Subscription::retrieve($session->subscription);

        $paymentMethod = PaymentMethod::retrieve($sub->default_payment_method);

        $customer->update([
            'stripe_id'      => $session['customer'],
            'card_brand'     => $paymentMethod->card['brand'],
            'card_last_four' => $paymentMethod->card['last4']
        ]);

        $subscription = $customer->subscriptions()->create([
            'name'          => 'default',
            'stripe_id'     => $session->subscription,
            'stripe_status' => 'active',
            'stripe_plan'   => Arr::get($session, 'display_items.0.plan.id'),
            'quantity'      => 1,
            'trial_ends_at' => null,
            'ends_at'       => null,
        ]);

        $subscription->items()->create([
            'stripe_id'   => $sub->items->data[0]->id,
            'stripe_plan' => Arr::get($session, 'display_items.0.plan.id'),
            'quantity'    => 1,
        ]);

        StripeCustomer::update(
            $session['customer'],
            [
                'invoice_settings' => ['default_payment_method' => $paymentMethod->id],
            ]
        );

        if ( $customer->vat ) {
            StripeCustomer::createTaxId(
                $session['customer'],
                [
                    'type'  => 'eu_vat',
                    'value' => $customer->vat
                ]
            );
        }

        CreateServer::dispatch($customer);

        return view('auth.success')->with([
            'customer' => $customer
        ]);

    }


    public function failed( Request $request )
    {

        $sessionId = $request->input('session_id');
        $session = Session::retrieve($sessionId);

        Customer::find($session->client_reference_id)
            ->delete();

        return view('auth.register')->with([
            'failed' => true,
        ]);

    }
}

dan3460's avatar

Thanks. I have decided to separate the subscription from the payment. Seems to be a lot easier.

Please or to participate in this conversation.