【问题标题】:Getting The payment attempt failed because of an invalid payment method. error in stripe laravel cashier由于付款方式无效,付款尝试失败。条纹 laravel 收银员中的错误
【发布时间】:2021-05-11 06:47:36
【问题描述】:

I am getting 由于付款方式无效,付款尝试失败。条纹 laravel 收银员中的错误。我按照 laravel stripe 收银员文档做所有事情。

public function orderPost(Request $request) {
    $user = auth()->user();
    $paymentMethod = $request->paymentMethod;
    Stripe\Stripe::setApiKey('sk_test_51AKI9PG7pDGBBGY5eNZ8XBOF8HKjTQm9zXUFz4Ww72a3m73jOwDd75FgyDGmsYCxJ68vCuCVX8MmUujJDpCn41oc00TF5O4giI');
    if (is_null($user->stripe_id)) {
        $stripeCustomer = $user->createAsStripeCustomer();
    }
    $user->updateDefaultPaymentMethod($paymentMethod);
    $user->newSubscription('main','price_1IIAk5G7pDGBBGY50mjUUlhj')
        ->create($paymentMethod, [
            'name' => 'Tom Tom',
            'description' => 'test description',
            'email' =>'tomtom@gmail.com',
            "address" =>'VPO DLLDOD DOLODO'
    ]);
}

【问题讨论】:

  • 首先,您应该立即滚动您的密钥。即使它只是一个测试密钥,恶意人员现在也可以破坏您的测试数据。为了解决您的问题,您遇到的确切错误是什么?

标签: php laravel stripe-payments laravel-8


【解决方案1】:

试试这样: 如果您在订阅中添加了试用期:

 $user->newSubscription('main','price_1IIAk5G7pDGBBGY50mjUUlhj')
        ->trialDays($trialDays) //Trial days of particular subscription 
        ->create($paymentMethod, [
            'name' => 'Tom Tom',
            'description' => 'test description',
            'email' =>'tomtom@gmail.com',
            "address" =>'VPO DLLDOD DOLODO'
 ]);

如果试用期结束或您第二次购买:

$user->newSubscription('main','price_1IIAk5G7pDGBBGY50mjUUlhj')
        ->trialDays(0)
        ->create($paymentMethod, [
            'name' => 'Tom Tom',
            'description' => 'test description',
            'email' =>'tomtom@gmail.com',
            "address" =>'VPO DLLDOD DOLODO'
 ]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-14
    • 2021-05-27
    • 2021-07-02
    • 1970-01-01
    • 2023-02-03
    • 2013-10-04
    • 2015-07-01
    • 2018-05-26
    相关资源
    最近更新 更多