当我使用3D安全测试卡号时,为什么Stripe没有给我付款意图的require_action状态?

时间:2019-05-23 16:32:12

标签: php stripe-payments

在遵循“计费和订阅”的Stripe文档中,我正在使用PaymentIntents创建订阅。如果我输入不需要3D Secure的测试卡,则效果很好。但是我用它来做,而不是给我一个状态为require_action,而是给卡片一个错误。

//Create customer
$customer = \Stripe\Customer::create(array(
      "source" => $token,
      "email" => $subscriber_email)
    );

    // Get customer variables from Stripe response
    $payment_livemode = $customer->livemode;
    $payer_id = $customer->id;

    // Now put customer on subs plan    
    try {   
        $subscription = \Stripe\Subscription::create([
          "customer" => $payer_id,
          "items" => [
            [
              "plan" => $subscription_plan
            ],
          ],
           "expand" => ["latest_invoice.payment_intent"],
        ]);

        $subscription_id = $subscription->id;
        $subscription_plan_id = $subscription->items->data[0]->plan->id;
        $subscription_latest_invoice_status = $subscription->latest_invoice->status;
        $subscription_latest_invoice_id = $subscription->latest_invoice->id;
        $subscription_latest_invoice_payment_intent_status = $subscription->latest_invoice->payment_intent->status;
        $subscription_latest_invoice_payment_intent_client_secret = $subscription->latest_invoice->payment_intent->client_secret;

        $_SESSION['subscription_latest_invoice_payment_intent_client_secret'] = $subscription_latest_invoice_payment_intent_client_secret;

        if ($subscription_latest_invoice_payment_intent_status=='succeeded') {
             header("Location: ../payment-success");
        }
        if ($subscription_latest_invoice_payment_intent_status=='requires_payment_method') {
             header("Location: ../payment?payment_status=failed&inv=$subscription_latest_invoice_id");
        }
        if ($subscription_latest_invoice_payment_intent_status=='requires_action') {
             header("Location: ../payment?payment_status=requires_action");
        }
    } catch(\Stripe\Error\Card $e) {

          $body = $e->getJsonBody();
          $err  = $body['error'];

          if ($err['code']=="subscription_payment_intent_requires_action") {
              header("Location: ../payment/requires_action");
          }

        } catch (\Stripe\Error\RateLimit $e) {
          // Too many requests made to the API too quickly
        } catch (\Stripe\Error\InvalidRequest $e) {
          // Invalid parameters were supplied to Stripe's API
        } catch (\Stripe\Error\Authentication $e) {
          // Authentication with Stripe's API failed
          // (maybe you changed API keys recently)
        } catch (\Stripe\Error\ApiConnection $e) {
          // Network communication with Stripe failed
        } catch (\Stripe\Error\Base $e) {
          // Display a very generic error to the user, and maybe send
          // yourself an email
        } catch (Exception $e) {
          // Something else happened, completely unrelated to Stripe
        }

我在此页面上使用测试卡: https://stripe.com/docs/testing#three-ds-cards

我选择了具有以下编号的卡: 4000 0000 0000 3220

这是我的错误详细信息: 状态:402 类型:card_error 代码:subscription_payment_intent_requires_action 消息:此预订的付款需要其他用户操作才能成功完成。请在此处参考enable_incomplete_payments参数的使用:https://stripe.com/docs/billing/lifecycle#incomplete-opt-in

我的API版本是2018年5月21日。

任何人都可以给我一个关于我做错了什么的线索吗?

2 个答案:

答案 0 :(得分:0)

已在评论中回答,仅在此处发布以提高可见性:

安迪,您好,因为您使用的是较旧的API版本,所以要在订阅上支持3DS,您应该改用本指南:https://stripe.com/docs/billing/migration/strong-customer-authentication#upgrading-integration

这意味着在创建订阅时更新API版本或传递enable_incomplete_payments标志,这是错误消息指出的。

答案 1 :(得分:0)

我遇到了同样的问题,实际上,API版本不是您下载的库的版本,您必须在仪表板https://dashboard.stripe.com/developers

中对其进行更改。