我正在爲慈善機構捐款,他們已經要求每月捐款計劃,用戶可以選擇他們想要捐贈的數額。不同數量的條紋訂購計劃
我知道我可以制定個人計劃(即如果他們表示每月捐款5美元,10美元或20美元),我可以制定三種不同的計劃並訂閱用戶。有沒有辦法避免爲每個不同的訂閱量制定新的計劃?
我正在爲慈善機構捐款,他們已經要求每月捐款計劃,用戶可以選擇他們想要捐贈的數額。不同數量的條紋訂購計劃
我知道我可以制定個人計劃(即如果他們表示每月捐款5美元,10美元或20美元),我可以制定三種不同的計劃並訂閱用戶。有沒有辦法避免爲每個不同的訂閱量制定新的計劃?
我不認爲你可以用Stripe做到這一點。
您可以做的就是繼續使用Stripe,並使用Stripe API動態構建訂閱計劃,或轉移到PayPal並使用其Preapproval操作。
https://developer.paypal.com/docs/classic/api/adaptive-payments/Preapproval_API_Operation/
你的問題似乎弄巧成拙的 - 你不能有數量不等,而無需創建相應的計劃訂閱!
處理經常性捐款的最簡單方法是每個捐獻者捐獻create one plan。舉例來說,你可以做這樣的事情:
# 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]
將捐贈的金額,作爲美分整數)。
條紋文檔推薦上訂閱的quantity
參數。
https://stripe.com/docs/guides/subscriptions
變結算金額
有些用戶需要充分的靈活性在計算結算金額。例如,對於 示例,您可能有一個概念訂閱,其基本成本爲 每月10美元,每個月每個座位的成本爲5美元。我們建議 代表這些計費關係,方法是創建一個基本計劃,即 僅爲每月1美元,甚至每月0.01美元。這使您可以使用
quantity
參數非常靈活地爲每個用戶開票。在 的示例中,基本成本爲10美元,座位爲3美元,您可以使用每月1美元的基本計劃 ,並設置quantity=25
以實現該月的期望總成本 25美元。