gpt4 book ai didi

php - Stripe 在 PHP 中创建客户和经常性费用

转载 作者:可可西里 更新时间:2023-11-01 00:08:42 24 4
gpt4 key购买 nike

我有一个网站,我想在其中集成 Stripe 支付网关,当用户注册时,我想在 Stripe 上创建一个客户并向他们收取第一个月的费用,例如 100 美元,从下个月开始我想向他们收取 50 美元.

我如何创建客户然后同时向他们收费并设置定期付款,到目前为止我只能找到一次性付款系统:

$charge = \Stripe\Charge::create(
array(
"amount" => $amount,
"currency" => "usd",
"source" => $token,
"description" => $email
)
);

对于定期付款,我必须在 cron 中运行此代码还是有更好的方法?

提前致谢。

编辑:

我使用以下代码首先创建了一个客户,然后使用他们的收费 ID 向该客户收费:

//Create Customer:
$customer = \Stripe\Customer::create(array(
'source' => $token,
'email' => $_POST['email'],
'plan' => "monthly_recurring_setupfee",
));

// Charge the order:
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
"amount" => $amount,
"currency" => "usd",
"description" => "monthly payment",
)
);

这似乎有效。

另一个问题:我创建了两个计划 monthly_recurring_setupfeemonthly_recurring,前一个计划包含我要收取的金额加上一次性安装费和后一个计划包含我将从第二个月开始收取的常规金额,我正在考虑在注册时为用户分配 monthly_recurring_setupfee 计划,如果付款成功,将用户的计划更改为 monthly_recurring,这可能吗?

最佳答案

我找到了一种创建客户、为他们注册计划并向他们收取一次性安装费的方法。这是我使用的代码:

$customer = \Stripe\Customer::create(array(
'source' => $token,
'email' => $billing_email,
'plan' => $stripePlan,
'account_balance' => $setupFee,
'description' => "Charge with one time setup fee"
));

这将向他们收取一次性设置费 'account_balance' => $setupFee,,将他们注册到计划中并向他们收取计划金额。

Stripe one-time subscription fee

关于php - Stripe 在 PHP 中创建客户和经常性费用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31579673/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com