【问题标题】:Stripe PaymentIntent with confirmation method manual fails every time带有确认方法手册的 Stripe PaymentIntent 每次都失败
【发布时间】:2020-10-31 16:28:49
【问题描述】:

我正在使用 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"
   }
}

【问题讨论】:

    标签: laravel stripe-payments payment


    【解决方案1】:

    支付意图的手动确认仅用于服务器端确认(即使用您的 API 密钥,而不是您的可发布密钥)。在 Payment Intent 上将 confirmation_method 设置为 manual 相当于说“此 Payment Intent 只能在服务器端确认”。

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

    【讨论】:

    • 是的,事实上,在表单指向的端点上,经过一些验证后我有PaymentIntent::retrieve($o-&gt;payment_id)-&gt;confirm(),但是我无法验证在表单之前确认付款的位置提交
    • 哦,我明白你在说什么。 stripe.handleCardPayment 尝试确认支付意图客户端。您很可能想改用stripe.createPaymentMethod,如下所示:stripe.com/docs/payments/…
    • 哦,非常感谢,真的很感激.. 那个方法是handleCardPayment 的所有验证吗?比如SCA的2阶段autentication,检查是否有足够的资金,卡没有过期等等?
    • 不,如果您使用手动确认,您还需要手动处理这些步骤。见这里:stripe.com/docs/payments/…
    猜你喜欢
    • 1970-01-01
    • 2020-04-17
    • 2021-01-22
    • 2020-04-23
    • 2021-02-27
    • 2021-02-04
    • 2015-02-23
    • 2021-05-17
    • 2019-02-22
    相关资源
    最近更新 更多