【问题标题】:Stripe sca subscription php and charge automaticallyStripe sca 订阅 php 并自动收费
【发布时间】:2023-03-27 11:31:02
【问题描述】:

我已经实施了 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 期。

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

此发票草稿由订阅生成。可以编辑 直到它在 1 小时内自动完成。

.

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

发票已敲定,但客户需要完成 3D 支付成功的安全认证。这个额外的 他们的银行要求采取措施以防止欺诈。 3D 安全电子邮件是 在您的设置中禁用,因此您需要通知客户 手动

发票未能捕获。 题: 1:我希望第一部分或计划发生。 我如何在登台环境中实现这一点。我在创建订阅或 SCA 方法时是否遗漏了任何要点?

2:真正的“确认方法”=>“手动”。真是一头雾水。

【问题讨论】:

    标签: php stripe-payments laravel-cashier


    【解决方案1】:

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

    回答您的具体问题:

    问题:1:我希望第一期或计划发生。我如何在登台环境中实现这一点。我在创建订阅或 SCA 方法时是否遗漏了任何要点?

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

    2:什么是真正的“确认方法”=>“手动”。真是一头雾水。

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

    【讨论】:

    • 非常感谢您的回答。它回答了我来的大部分问题。但是新的疑问是,当您使用 'expand' => ['subscription.latest_invoice.payment_intent'] 创建订阅时,例如,它会返回 payment_intent。但我正在使用 'expand' => ['subscription.latest_invoice.payment_intent ']。它只返回到最新的发票。但 payment_intent 为 Null。
    • 在发票完成之前不会创建发票的付款意图,听起来您使用订阅计划可能会阻止发票立即完成。一种可能的替代方法是侦听invoice.finalized events 并在此之后检索付款意图。
    猜你喜欢
    • 1970-01-01
    • 2018-06-21
    • 2021-03-18
    • 2021-02-08
    • 2020-04-18
    • 2021-04-20
    • 2022-10-21
    • 1970-01-01
    • 2015-04-08
    相关资源
    最近更新 更多