Laravel - 基于数量/变量订阅金额

时间:2016-03-09 12:25:21

标签: php laravel laravel-4 stripe-payments laravel-cashier

我在Laravel项目中实现了Stripe。我想每月向客户收费,但每个客户都需要支付不同的金额。我通过另一个系统单独向他们发送发票,他们必须在我的网站上输入发票号,金额和付款。

现在向客户收取可变金额,我在这里遇到了一个解决方案:https://support.stripe.com/questions/how-can-i-create-plans-that-dont-have-a-fixed-price

我的表格中,客户将输入他的发票号,其他详细信息以及他想要支付的金额。现在我如何以条带形式使用此信息并创建像这样的条带客户?我无法让它发挥作用。

3 个答案:

答案 0 :(得分:3)

我看到处理变量订阅金额的最佳方法是在条带上创建基本计划,例如freePlan并为其分配1的数量。

因此,如果您想处理“在您的情况下”的变量订阅量 您将订阅此freePlan,然后按您的订阅数量(金额)增加 1 的金额。

例如,您想分别向2位用户收取10美元和15美元的费用。你会

// Let get first user
$user = User::find(1);

// subscribe to free plan which has an amount of one(1)
// and increment the quantity by 10 so in this case he/she will pay 
// $10 every month
$user->subscription('freePlan')->incrementQuantity(10); 

// Lets do same for user 2 
$user = User::find(2);

// subscribe to free plan which has an amount of one(1)
// and increment the quantity by 15 so in this case he/she will pay 
// $15 every month
$user->subscription('freePlan')->incrementQuantity(15); 

或者您可以选择使用已创建的计划示例basicPlanbusinessPlan并增加或减少数量

// Let say basicPlan is $30 so increasing it by 5 will be 150
$user->subscription('basicPlan')->incrementQuantity(15); 

此链接指向如何设置数量https://stripe.com/docs/subscriptions/guide#setting-quantities

的条带

这是关于如何增加或减少数量的链接点 https://laravel.com/docs/5.2/billing#subscription-quantity

答案 1 :(得分:1)

听起来您只想向客户收取一定金额的费用。您不需要使用Stripe的计划或订阅,只需create a charge

如果您想收集客户的信用卡详细信息并且能够反复收费而无需再次要求他们提供信用卡详细信息,则应首先create a customer使用信用卡令牌,然后使用customer参数中的客户ID。

您应该查看本教程:https://stripe.com/docs/charges#saving-credit-card-details-for-later

答案 2 :(得分:0)

好的,所以我已经解决了这个问题的解决方案。我没有使用Stripe的QuantityQuantityIncrement(),而是为每个客户创建了一个单独的计划。

现在Laravel Cashier不允许我们以编程方式创建条带计划。但是,this solution帮助我做到了这一点。虽然我不得不做一些改变才能让它在Laravel中工作,但是我在玩完之后终于有了这个工作。