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

标签 php payment-gateway stripe-payments

我有一个网站,我想在其中集成 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/

相关文章:

ruby-on-rails - 如何在后台处理事务时向用户显示 'your payment is processing...' 页面?

javascript - 创建不带元素的 Stripe token

javascript - 尝试使用 JSON 的点表示法从 Stripe API 获取特定键值时遇到问题

php - 现代 PHP Web 应用程序的 AJAX 进度指示器是如何实现的?

paypal - 关于设置定期计费的建议?

php - 检查今天的日期是否超过到期日期

payment-gateway - Google Pay 付款集成

javascript - 如何将信息传递给 stripe.checkout.sessions.create() 函数

php - 如果未找到结果,则显示(消息)

php - 在正则表达式中允许一些 url