2

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

我正在按照此链接设置条带订阅。当我创建没有“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' => 'any_email@domain.com',
      '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 安全授权检查模式。

4

1 回答 1

2

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

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

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

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

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

如果订阅在trialing,检查是否有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 Card4000002500003155非常适合此测试。您可以通过更新订阅来模拟试用结束

trial_end: "now"
off_session: true // This is needed because by default, subscription update is considered on_session

希望以上有所帮助

于 2019-08-30T11:25:20.817 回答