无法继续结帐 - 在 null 上调用成员函数 checkout()
Can't proceed to checkout - Call to a member function checkout() on null
我试图在我的 Laravel 应用程序中向客户收费,但它一直说 $customer 为空。知道出了什么问题吗?
错误:
Call to a member function checkout() on null
指的是这一行return $customer->checkout...
但是调用 echo $id
returns 客户 ID 所以我看不出为什么 findBillable
returns 一个空对象。
客户确实存在于 Stripe 中,硬编码 ID 不会改变任何东西。
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',
];
}
必须通知收银员我使用的是不同的 Billable 模型...
Cashier::useCustomerModel(Competitor::class);
我试图在我的 Laravel 应用程序中向客户收费,但它一直说 $customer 为空。知道出了什么问题吗?
错误:
Call to a member function checkout() on null
指的是这一行return $customer->checkout...
但是调用 echo $id
returns 客户 ID 所以我看不出为什么 findBillable
returns 一个空对象。
客户确实存在于 Stripe 中,硬编码 ID 不会改变任何东西。
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',
];
}
必须通知收银员我使用的是不同的 Billable 模型...
Cashier::useCustomerModel(Competitor::class);