Stripe sca 订阅 php 并自动收费

Stripe sca subscription php and charge automatically

我已经实施了 Stripe SCA 迁移 我创建付款意图的服务端代码如下

      $intent = \Stripe\PaymentIntent::create([
            'payment_method' => $requestData['payment_method_id'],
            'amount' => $requestData->amount,
            'currency' => $requestData->currencyIso,
            'payment_method_types' => ['card'],
            'confirmation_method' => "manual",
            'confirm' => true,
            'setup_future_usage'=>"off_session",
        ]);
        return $intent;

我的 js 代码如下,用于创建卡支付和处理响应

 stripe.createPaymentMethod('card', cardElement, {
        billing_details: {name: cardholderName.value}
 })

并处理响应:

function handleServerResponse(response) {
  if (response.error) {

  } else if (response.requires_action) {

    stripe.handleCardAction(
      response.payment_intent_client_secret
    ).then(function(result) {
      if (result.error) {

      } else {
        // The card action has been handled
        // The PaymentIntent can be confirmed again on the server
        fetch('https://test.com/server.php', {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({ 
            payment_method_id: result.paymentMethod.id, 
             amount: amount


          })
        }).then(function(confirmResult) {
            console.log(confirmResult);
          return confirmResult.json();
        }).then(handleServerResponse);
      }
    });
  } 


  }
}

$plan = Plan::create([
                'currency' => $currency,
                'interval' => 'month',
                'product' => $product->id,
                'nickname' => 'Payment Plan for order - ' . $order_id,
                'amount' => $price,
                'metadata' => [
                    'order_number' => $order_id,
                    'bgt_customer_number' => $customer_id,
                ],
            ]);
            $schedule = SubscriptionSchedule::create([
                'customer' => $customer->id,
                'start_date' => 'now',
                'end_behavior' => 'cancel',
                'metadata' => [
                    'local_id' => $order_id,
                    'local_account_id' => $account_id,
                    'local_currency_id' => $currency_id,
                    'local_user_id'=> $user_id,
                    'local_installments_total' => $plan_length,
                    'bgt_customer_number' => $customer_id,
                    'order_number' => $order_id,
                    'invoice_description' => 'Payment Plan for order - ' . $order_id
                ],
                'phases' => [
                    [
                        'items' => [
                            [
                                'plan' => $plan->id,
                            ],
                        ],
                        'collection_method'=> 'charge_automatically',
                        'iterations'=>$plan_length
                    ],
                ],
            ]);
            $metadata = [
                'installments_paid' => '0',
                'installments_total' => $plan_length,
                'local_id' =>$order_id,
                'local_account_id' =>$account_id,
                'local_currency_id' =>$currency_id,
                'subscription_schedule_id' => $schedule->id
            ];

            $subscription_id=$schedule->subscription;
            $result=Subscription::update($subscription_id,
                [
                    'metadata' => $metadata,
                    'default_payment_method' => $paymentMethodParams['payment_method'],
                    'proration_behavior' =>'always_invoice',
                    //Create only after adding payment method id in customer
                ]
            );

我正在获取 sca 卡的 SCA 模态,工作流程是正确的。 但我关心的是测试使用 sca

创建的订阅

我测试使用 4000000000003220 和 424242424242424.. 订阅是分 3 期创建的。

使用正确的分期付款创建订阅: 但令我担心的是订阅的第一期付款不会立即收费。 发票显示为:

This draft invoice was generated by a subscription. It can be edited until it's automatically finalized in 1 hour.

.

当我尝试从条纹仪表板完成充电时(作为测试的一部分)它显示

The invoice was finalized, but the customer needs to complete 3D Secure authentication for the payment to succeed. This additional step is required by their bank to prevent fraud. 3D Secure emails are disabled in your settings, so you'll need to notify the customer manually

发票捕获失败。 题: 1:我希望第一部分或时间表发生。 我如何在暂存环境中完成此操作。我是否遗漏了创建订阅或 SCA 方法的任何要点?

2:什么是真正的 'confirmation_method' => “手动”。真糊涂。

使用 Stripe 订阅时,您通常不会自己创建付款意向。相反,您将创建订阅和发票等计费对象并与之交互。发票将为您创建付款意向。条纹有 a guide that walks you through taking payment information and creating a Subscription。如果您通读并遵循该指南,您应该能够构建您想要的东西。

回答您的具体问题:

Question: 1: I wanted the first installment or schedule to happen. How do I accomplish this in staging env. Am I missing any points here in creating subscription or SCA methods?

这很可能是因为您正在创建付款意向并支付与属于您的订阅发票的付款意向无关的款项。

2: What is really 'confirmation_method' => "manual". Really confused.

The confirmation_method property 控制付款意向的确认方式。但是,如果您使用订阅并希望支持 SCA,则应忽略此 属性 并按照上面链接的指南进行操作。