php - 当订阅类型为跟踪时如何使用 Stripe 3d Secure 进行授权

标签 php laravel 3d-secure stripe-payments

我想要订阅类型 = 试用的 3d 安全模式授权检查。

我正在关注this link设置 strip 订阅。当我创建没有“Trial_period_days”的订阅时,3d 安全授权模式会弹出,因为订阅状态变为“不完整”。

但是当我通过> Trial_period_days 和 ' payment_behavior' => 'allow_incomplete' 时,模式不起作用,因为订阅状态变为“事件”。

订阅试用时如何显示授权模式? 我看过这个链接https://stripe.com/docs/payments/3d-secure#manual-three-ds也是,但没有进展。

建议我一种实现此目的的方法。

这是我的代码:

public function createCustomer($token) {
    \Stripe\Stripe::setApiKey(secretKey);

    $customer = \Stripe\Customer::create([
      'email' => '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="73121d0a2c161e121a1f33171c1e121a1d5d101c1e" rel="noreferrer noopener nofollow">[email protected]</a>',
      'source' => $token,
    ]);

    return $this->createSubscription($customer, $token);    
}

public function createSubscription($customer, $token) {
    $plan_id = $this->getPlanId();
    $payment_intent = $this->createSetupIntent($customer->id, $token);
    $subscription = \Stripe\Subscription::create([
      'customer' => $customer->id,
      'items' => [
        [
          'plan' => $plan->id, 
        ],
      ],
      'trial_period_days' => 14,
      'expand' => ['latest_invoice.payment_intent'],
      'payment_behavior' => 'allow_incomplete',
    ]);

    return [
       'subscription' => $subscription, 
       'payment_intent' => $payment_intent
    ];
}

public function createSetupIntent($customer_id, $token) {
    $client = new Client();
    $url = "https://api.stripe.com/v1/setup_intents";
    $response = $client->request('POST', $url, [
      'auth' => ['sk_test_key', ''],
      'form_params' => [
        'customer' => $customer_id,
        'payment_method_types' => ["card"],
        'payment_method_options' => [
            "card" => [
              "request_three_d_secure" => "any"
            ]
          ]
      ],
      'timeout' => 10.0
    ]);
    $setup_intent = $response->getBody()->getContents();
    return json_decode($setup_intent, true);
  }

当我将订阅设置为试用时,我也期望 3d 安全授权检查模式。

最佳答案

您所描述的是 Stripe doc 中的场景

基本上,当您创建试用期订阅时,由于不会立即付款,因此不需要 3DS 身份验证。

身份验证将延迟到试用期结束。

要求用户进行身份验证,以便在试用期结束时无需进行 3DS 身份验证,当创建具有试用期的订阅时,该订阅将具有 pending_setup_intent attribute

您可以使用该pending_setup_intent来要求用户完成身份验证。您不必显式创 build 置 Intent。您可以做的是检查订阅内的状态。

如果订阅处于试用状态,请检查是否有pending_setup_intent,如果有,则将pending_setup_intent.client_secret传递到前端,其中您的客户正在订阅您的产品,并调用 Stripe.js handleCardSetup

stripe.handleCardSetup(psi.client_secret)
  .then(siResult => {
     log({siResult});
  }).catch(err => {
     log({siErr: err});
  });

当卡设置完毕且试用结束后,扣款将不太可能需要再次经过 3DS 身份验证。

您可以使用 Stripe Test Card , 4000002500003155 适合此测试。 您可以通过使用

更新订阅来模拟试用结束
trial_end: "now"
off_session: true // This is needed because by default, subscription update is considered on_session

希望以上内容对您有所帮助

关于php - 当订阅类型为跟踪时如何使用 Stripe 3d Secure 进行授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57721102/

相关文章:

php - 三元运算符语法 (PHP)

php - 在 Codeigniter 中转义 SQL 查询

php - 如何选择表格的某些列?

laravel - $job->release() 没有放回队列

ios - iOS 中的信用卡支付(3-D 安全?)

ios - 在 iOS 中将 3D 安全与 Stripe 集成

xml - Shopify XML API 响应 - 无效的元素名称 : 3DSecureStatus

php - 如何在 PHP 上声明多个 header

php - 如何查询laravel采集结果

php - 使用 PHP 显示登录错误