不同金额的条带订阅计划



我正在为慈善机构提供捐赠表格,他们要求每月捐赠计划,用户可以选择他们想要的任何金额。

我知道我可以制定个人计划(例如,如果他们说每月捐赠5美元,10美元或20美元),我可以制定三种不同的计划并订阅用户。是否有一种方法可以避免为每个不同的订阅金额制定新的计划?

Stripe文档建议在订阅时使用quantity参数。

https://stripe.com/docs/guides/subscriptions

不同的计费金额

一些用户需要完全灵活地计算计费金额。为例如,您可能有一个具有基本成本的概念性订阅每月10美元,每个座位每月5美元。我们建议通过创建基本计划来表示这些计费关系每月只有1美元,甚至是0.01美元。这样就可以使用quantity参数对每个用户计费非常灵活。举个例子10美元的基本费用和3个5美元的座位,你可以每月使用1美元,并设置quantity=25,以达到期望的总成本每月$25

我不认为你可以用Stripe。

你可以做的是继续使用Stripe,并使用Stripe API动态构建订阅计划,或者转移到PayPal并使用他们的预批准操作。

https://developer.paypal.com/docs/classic/api/adaptive-payments/Preapproval_API_Operation/

你的问题似乎是在弄死自己——你不可能有不同数量的订阅而不创建相应的计划!

处理不同金额的经常性捐赠的最简单方法是为每个捐赠者创建一个计划。例如,您可以这样做:

# Create the plan for this donator
plan = Stripe::Plan.create(
  :amount => params[:amount],
  :currency => 'usd',
  :interval => 'month',
  :name => 'Donation plan for #{params[:stripeEmail]}',
  :id => 'plan_#{params[:stripeEmail]}'
)
# Create the customer object and immediately subscribe them to the plan
customer = Stripe::Customer.create(
  :source => params[:stripeToken],
  :email => params[:stripeEmail],
  :plan => plan.id
)

如果您希望避免创建不必要的计划,您可以简单地检查是否已经存在合适的计划。最简单的方法是使用包含数量的命名约定。例如:

plan_id = '#{params[:amount]}_monthly'
begin
  # Try to retrieve the plan for this amount, if one already exists
  plan = Stripe::Plan.retrieve(plan_id)
rescue Stripe:: InvalidRequestError => e
  # No plan found for this amount: create the plan
  plan = Stripe::Plan.create(
    :amount => params[:amount],
    :currency => 'usd',
    :interval => 'month',
    :name => "$#{'%.02f' % (params[:amount] / 100.0)} / month donation plan",
    :id => plan_id
  )
# Create the customer object as in the previous example

(注意,在这两个例子中,我假设params[:amount]是捐赠的金额,以分为单位的整数。)

最新更新