2
votes

I am working on a donation form for a charity and they have requested a monthly donation plan where the user can choose whatever amount they would like to give.

I know I can make individual plans (i.e. if they said monthly donations of $5, $10, or $20 dollars) I could make three different plans and subscribe users to them. Is there a way to avoid making new plans for every varying subscription amount?

3

3 Answers

4
votes

The Stripe documentation recommends using the quantity parameter on the subscription.

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

Varying billing amounts

Some users need full flexibility in computing billing amounts. For example, you might have a conceptual subscription that has a base cost of $10 per month, and a $5 per-seat cost each month. We recommend representing these billing relationships by creating a base plan that is only $1 per month, or even $0.01 per month. This lets you use quantity parameter to bill each user very flexibly. In an example with a $10 base cost and three $5 seats, you could use a $1 per month base plan, and set quantity=25 to achieve the desired total cost of $25 for the month.

0
votes

I don't think you can do it with Stripe.

What you can do is keep using Stripe and dynamically build the subscription plans using Stripe API or move to PayPal and use their Preapproval operation.

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

0
votes

Your question seems self-defeating -- you can't have subscriptions of varying amounts without creating the corresponding plans!

The simplest way to handle recurring donations of varying amounts would be to create one plan per donator. For instance, you could do something like this:

# 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
)

If you wish to avoid creating unnecessary plans, you could simply check if an appropriate plan already exists. The simplest way to do so would be to use a naming convention that includes the amount. For instance:

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

(Note that in both these examples, I assumed that params[:amount] would be the donation's amount, as an integer in cents.)