php - Stripe sca 订阅 php 并自动收费
问题描述
我已经实现了 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 Secure 身份验证才能成功付款。他们的银行需要此额外步骤以防止欺诈。您的设置中禁用了 3D 安全电子邮件,因此您需要手动通知客户
未能捕获发票。问题:1:我希望第一期或第一期发生。我如何在登台环境中实现这一点。我在创建订阅或 SCA 方法时是否遗漏了任何要点?
2:什么是真正的“确认方法”=>“手动”。真的很迷茫。
解决方案
使用 Stripe 订阅时,您通常不会自己创建付款意图。相反,您将创建订阅和发票等计费对象并与之交互。发票将为您创建付款意向。Stripe 有一个指南,可以引导您获取付款信息和创建订阅。如果您通读并遵循该指南,您应该能够构建您想要的东西。
要回答您的具体问题:
问题:1:我希望第一期或第一期发生。我如何在登台环境中实现这一点。我在创建订阅或 SCA 方法时是否遗漏了任何要点?
这可能是因为您正在创建一个付款意向并支付与属于您的订阅发票的付款意向无关的款项。
2:什么是真正的“确认方法”=>“手动”。真的很迷茫。
该confirmation_method
属性控制如何确认付款意图。但是,如果您使用订阅并希望支持 SCA,则应忽略此属性,而应遵循上面链接的指南。
推荐阅读
- python-3.x - 更改 SQLAlchemy __tablename__
- android - 双击 BottomTabNavigator 的奇怪行为 - React Navigation
- azure-cosmosdb - Cosmos Gremlin 查询的奇怪执行行为
- python - 美丽的汤不返回完整的 html
- shell - SSH 登录为 $PATH 提供不同的值
- jenkins - Jenkins Slave 没有响应创建工作空间
- python - 通过机器人框架中的方法调用类变量打印空列表
- python - 元素不可交互:元素当前不可见,可能无法操作
- mysql - 容器 WordPress 关闭且没有错误消息(Docker、Bitnami、MySQL)
- batch-file - 如何将可用磁盘空间与特定字节数进行比较?