我一直在使用Stripe支付集成,目前我发现自己被一个特定的用例困住了。
Stripe可以选择持有对未来的付款,并根据业务逻辑获取稍后的金额。这里解释了这一点( https://stripe.com/docs/payments/save-and-reuse),并且工作非常好。
但是,我需要保存卡的详细信息,然后在上创建一个订阅(而不是像上面的docs链接中解释的那样一次性支付)。有人用过类似的用例吗?
提前谢谢。
发布于 2022-08-11 16:50:02
我对这个过程也很感兴趣,并且在条形网站上找到了这个方法,尽管有一些困难。
您的上述方法是一个巧妙的解决方法,但对我来说有点笨重,所以希望其他人会发现下面的方法是处理这个过程的一个更流畅的方法。
创建订阅并立即获取付款
流动情况如下:
如果还没有创建客户,则
这样,您就不必手动处理订阅开始日期、周期等问题,从而简化了流程,减少了人为错误的空间。
$stripe = new \Stripe\StripeClient(
'your_secret_stripe_key'
);
// *Create customer if not already created *
$customer = $stripe->customers->create([
'description' => 'example customer',
'email' => 'example@blah.com'
]);
$customer_id = $customer->id;
//*Create subscription*
$subscription = $stripe->subscriptions->create([
'customer' => $customer_id,
'items' => [['price' => '*your_previously_created_price_id*']],
'payment_behavior' => 'default_incomplete',
'payment_settings' => ['save_default_payment_method' => 'on_subscription'],
'expand' => ['latest_invoice.payment_intent']
]);
// *Use this client secret to capture payment with the Payment Elements form*
$clientSecret = $subscription->latest_invoice->payment_intent->client_secret;
如您所见,创建订阅将生成一张发票,该发票将创建支付意图,客户端秘密可用于捕获卡并将其保存为订阅的默认支付方法。您的客户输入卡的详细信息,付款被处理和订阅成为‘活动’。
https://stackoverflow.com/questions/71634238
复制相似问题