laravel - 带确认方法手动的 Stripe PaymentIntent 每次都会失败

标签 laravel stripe-payments payment

我正在使用 Laravel 与 Stripe API 的个人集成(使用来自 github 的 Stripe API)。
一切都工作正常,直到我切换到手动确认模式,现在我收到以下错误:

This PaymentIntent pi_**************uVme cannot be confirmed using your publishable key because its `confirmation_method` is set to `manual`. Please use your secret key instead, or create a PaymentIntent with `confirmation_method` set to `automatic`.

有什么想法吗?
这是我当前的代码(不起作用):

Stripe::setApiKey(config('services.stripe.secret')); // config('services.stripe.secret') returns "sk_test_gFi********************nMepv"

$paymentIntent = PaymentIntent::create([
    'amount' => $orderSession->order_total * 100,
    'currency' => 'eur',
    'description' => "Pagamento di ".(price($orderSession->order_total))."€ a ".$orderSession->user->user_name." in data ".(now()->format("d-m-Y H:m:s")),
    'metadata' => [
        'subtotal' => $orderSession->order_subtotal,
        'user'=> "{$orderSession->user_id} : {$orderSession->user->user_email}",
        'wines'=> substr(
                        $orderSession->wines()->select('wine_id', 'quantity')->get()->each(
                            function($el){
                                $el->q= $el->quantity;
                                $el->id = $el->wine_id;
                                unset($el->wine_id, $el->pivot, $el->quantity);
                            }
                        )->toJson(),
                        0,
                        500
                    ),
    ],
    'confirmation_method' => 'manual',
]);

JS 前端:

<button class="myButtonPayment" id="card-button" type="button" data-secret="{!!$stripePaymentIntent->client_secret!!}" ><span>Pay</span></button>
...
<script>
cardButton.addEventListener('click', function() {
    if(!document.getElementById('order_telephone_number').value || /^\+?[0-9 ]{6,20}$/.test(document.getElementById('order_telephone_number').value)){
           stripe.handleCardPayment(
               clientSecret, cardElement, {
                   payment_method_data: {
                         billing_details: {name: cardholderName.value}
                   }
               }
           ).then(function (result) {
               if (result.error) {
                   console.log(result.error);
              } else {
                   document.getElementById('myForm').submit();
              }
           });
    } 
});
</script>

当我点击按钮时发生错误(因此与我确认付款的代码部分无关)

错误序列化如下:

{
   "type":"invalid_request_error",
   "code":"payment_intent_invalid_parameter",
   "doc_url":"https://stripe.com/docs/error-codes/payment-intent-invalid-parameter",
   "message":"This PaymentIntent pi_1H3TQ*********T00uVme cannot be confirmed using your publishable key because its `confirmation_method` is set to `manual`. Please use your secret key instead, or create a PaymentIntent with `confirmation_method` set to `automatic`.",
   "payment_intent":{
      "id":"pi_1H3***********uVme",
      "object":"payment_intent",
      "amount":2060,
      "canceled_at":null,
      "cancellation_reason":null,
      "capture_method":"automatic",
      "client_secret":"pi_1H3TQ********T00uVme_secret_2T7Di*********nkoaceKx",
      "confirmation_method":"manual",
      "created":1594415166,
      "currency":"eur",
      "description":"....",
      "last_payment_error":null,
      "livemode":false,
      "next_action":null,
      "payment_method":null,
      "payment_method_types":[
         "card"
      ],
      "receipt_email":null,
      "setup_future_usage":null,
      "shipping":null,
      "source":null,
      "status":"requires_payment_method"
   }
}

最佳答案

付款意向的手动确认仅适用于服务器端确认(即使用您的 secret API key ,而不是您的可发布 key )。将付款意图的 confirmation_method 设置为 manual 相当于“此付款意图只能在服务器端确认”。

您可以在finalize payments on the server guide中阅读更多相关信息。在 Stripe 的文档中。

关于laravel - 带确认方法手动的 Stripe PaymentIntent 每次都会失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62842612/

相关文章:

Xamarin.Forms 中的 Paypal 集成?

process - Paypal ipn 处理和下拉选项/价格按钮逻辑

flutter - flutter 中的 Paypal 集成

php - Laravel:查询中间表

php - 带有订阅的 Stripe 付款请求按钮

php - 在 Laravel 中允许多个密码重置 token

google-apps-script - 将 Stripe API 语法转换为 Google Apps 脚本

node.js - Stripe webhook 错误 : No signatures found matching the expected signature for payload

php - 如何更新 Laravel 中的哈希密码?

基于角色的 Laravel 菜单?