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

Gerulisss's avatar

Laravel cashier The resource ID cannot be null or whitespace

Hello, I wanted to ask, when integrating stripe, when entering card data, an error is received: The resource ID cannot be null or whitespace?

public function create(Request $request, Plan $plan) { $plan = Plan::findOrFail($request->get('plan'));

    $user = $request->user();
    $paymentMethod = $request->paymentMethod;

    $user->createOrGetStripeCustomer();
    $user->updateDefaultPaymentMethod($paymentMethod);
    $user->newSubscription('default', $plan->stripe_plan)
        ->create($paymentMethod, [
            'email' => $user->email,
        ]);

    return redirect()->route('home')->with('success', 'Your plan subscribed successfully');
}

blade: @extends('layouts.app') @section('content')

You will be charged ${{ number_format($plan->cost, 2) }} for {{ $plan->name }} Plan

@csrf Enter your credit card information Pay @endsection @section('scripts') // Custom styling can be passed to options when creating an Element. // (Note that this demo uses a wider set of styles than the guide below.) var style = { base: { color: '#32325d', lineHeight: '18px', fontFamily: '"Helvetica Neue", Helvetica, sans-serif', fontSmoothing: 'antialiased', fontSize: '16px', '::placeholder': { color: '#aab7c4' } }, invalid: { color: '#fa755a', iconColor: '#fa755a' } };

    const stripe = Stripe('{{ env("STRIPE_KEY") }}', { locale: 'en' }); // Create a Stripe client.
    const elements = stripe.elements(); // Create an instance of Elements.
    const cardElement = elements.create('card', { style: style }); // Create an instance of the card Element.
    const cardButton = document.getElementById('card-button');
    const clientSecret = cardButton.dataset.secret;

    cardElement.mount('#card-element'); // Add an instance of the card Element into the `card-element` <div>.

    // Handle real-time validation errors from the card Element.
    cardElement.addEventListener('change', function(event) {
        var displayError = document.getElementById('card-errors');
        if (event.error) {
            displayError.textContent = event.error.message;
        } else {
            displayError.textContent = '';
        }
    });

    // Handle form submission.
    var form = document.getElementById('payment-form');

    form.addEventListener('submit', function(event) {
        event.preventDefault();

        stripe
            .handleCardSetup(clientSecret, cardElement, {
                payment_method_data: {
                    //billing_details: { name: cardHolderName.value }
                }
            })
            .then(function(result) {
                console.log(result);
                if (result.error) {
                    // Inform the user if there was an error.
                    var errorElement = document.getElementById('card-errors');
                    errorElement.textContent = result.error.message;
                } else {
                    console.log(result);
                    // Send the token to your server.
                    stripeTokenHandler(result.setupIntent.payment_method);
                }
            });
    });

    // Submit the form with the token ID.
    function stripeTokenHandler(paymentMethod) {
        // Insert the token ID into the form so it gets submitted to the server
        var form = document.getElementById('payment-form');
        var hiddenInput = document.createElement('input');
        hiddenInput.setAttribute('type', 'hidden');
        hiddenInput.setAttribute('name', 'paymentMethod');
        hiddenInput.setAttribute('value', paymentMethod);
        form.appendChild(hiddenInput);

        // Submit the form
        form.submit();
    }
</script>

@endsection

0 likes
9 replies
martinbean's avatar

@gerulisss I imagine the issue is with your $plan->stripePlan property given you don’t show us how or where that’s defined.

Gerulisss's avatar

I add additional code to the existing controller

Gerulisss's avatar
public function storePlan(Request $request)
{
    $data = $request->except('_token');

    $data['slug'] = strtolower($data['name']);
    $price = $data['cost'] *100;

    //create stripe product
    $stripeProduct = $this->stripe->products->create([
        'name' => $data['name'],
    ]);

    //Stripe Plan Creation
    $stripePlanCreation = $this->stripe->plans->create([
        'amount' => $price,
        'currency' => 'eur',
        'interval' => 'month',
        'product' => $stripeProduct->id,
    ]);

    $data['stripe_plan'] = $stripePlanCreation->id;

    Plan::create($data);

    echo 'plan has been created';
}
Gerulisss's avatar
public function up()
{
    Schema::create('plans', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('slug')->unique();
        $table->string('stripe_plan');
        $table->float('cost');
        $table->text('description')->nullable();
        $table->timestamps();
    });
}
1 like
HiwaB41's avatar

@Gerulisss hello bro have you solved the problem please tell me i want to know the problem bcz i have the same problem ....

1 like
Gerulisss's avatar
protected $fillable = [
    'name',
    'slug',
    'stripe_plan',
    'cost',
    'description'
];
Gerulisss's avatar

Maybe you know where i uploaded the above code, where it might be, which is why it shows this error? Thanks right away

Hondaman900's avatar

@Gerulisss Did you ever solve this issue? I have the same problem but can't find a solution (the stripe_id in my user record is NULL until populated with a valid Stripe ID).

1 like

Please or to participate in this conversation.