Search code examples
laravelnullstripe-paymentslaravel-cashier

Can't proceed to checkout - Call to a member function checkout() on null


I'm trying to charge a customer in my Laravel app but it keeps saying $customer is null. Any idea what's wrong?

The error: Call to a member function checkout() on null refers to this line return $customer->checkout...

However calling echo $id returns the customer ID so I see no issue why findBillable returns a null object.

The customer does indeed exist in Stripe and hard-coding the ID doesn't change anything.

                    use Laravel\Cashier\Cashier;

                    $user = new App\Competitor();

                    $stripeCustomer = $user->createAsStripeCustomer([
                        'name' => $request->name,
                        'email' => $request->email,
                        'phone' => $request->phone,
                    ]);

                    $id = $user->stripeId();
                    $customer = Cashier::findBillable($id);

                    return $customer->checkout(['price_foobarfoobar' => 1], [
                        'success_url' => 'https://staging.domain.com/thank-you',
                        'cancel_url' => 'https://staging.domain.com/sign-up',
                    ]);
                    

Competitor.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Laravel\Cashier\Billable;

class Competitor extends Model
{
    use Billable;

    protected $table = 'competitors';
    protected $fillable = [
        'name',
        'email',
        'phone',
        'selected_event',
        'team_name',
        'user_agent',
        'ip_address',
        'created_at',
        'stripe_transaction',
        'stripe_id',
    ];
}

Solution

  • Had to inform Cashier I was using a different Billable model...

    Cashier::useCustomerModel(Competitor::class);