【问题标题】:Laravel 7 Cashier subscription: Call to a member function create() on nullLaravel 7 Cashier 订阅:在 null 上调用成员函数 create()
【发布时间】:2020-11-04 07:50:21
【问题描述】:

我有 2 件产品,这是其中之一

我已经实现了stripehttps://stripe.com/docs/stripe-js的默认支付方式。用户类使用 billable 像这样

use Laravel\Cashier\Billable;

class User extends Authenticatable
{
use Notifiable;
use Billable;

.env 包含正确的数据

STRIPE_KEY=your-stripe-key
STRIPE_SECRET=your-stripe-secret

现在我正在尝试让用户以这种方式订阅此计划:

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Cartalyst\Stripe\Stripe;
use App\User;

class PaymentController extends Controller
{
    public function store(Request $request){
        $user = auth()->user();
        $user->subscription('prod_HeC7XMT2SVe21K')->create($request->stripeToken);
    }
}

但我明白了

Call to a member function create() on null

为什么会这样以及如何解决?

注意:除了 .env 文件,我没有在任何地方使用密钥,因为我遵循了一些教程,不知道这是否正确。

【问题讨论】:

  • 你试过$user->newSubscription('prod_HeC7XMT2SVe21K')->create($data['payment_method']); ...注意newSubscription和create方法将接受付款方式作为第一个参数和其他参数的数组,如电子邮件、电话(即用户详细信息)作为第二个参数

标签: stripe-payments subscription laravel-7 laravel-cashier


【解决方案1】:

您可以尝试通过以下方式创建订阅:

$subscription = $user->newSubscription('plan_name' , 'plan_id'); 
$subscription->create('payment_method', ['other_parameters']);

替换
'plan_name' 带有在条带仪表板上创建的计划的名称。
'plan_id' 带有所选计划的 ID。
'other_parameters' 可以包括用户的电子邮件、电话号码等。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-25
    • 2016-09-04
    相关资源
    最近更新 更多