First time working with Stripe API. Implementing it on WordPress using PHP and JS.
Working on a donation form. Donor should be able to choose a suggested amount (radio buttons-25,50,75,100) or pay as he/she wishes (text field after selecting ‘other’). I was able to get this working.
There is a check box to set the amount up as a recurring payment. I created recurring payment plans for the fixed options like 25, 50, 100 etc.
How do I set up a recurring payment if the donor chooses a custom amount? Can’t find the relevant API. Please help.
Another approach that Stripe suggests is to setup a plan with a recurring amount of $1 (or $0.01 for more flexibility) and then vary the quantity as needed.
e.g. Using the $0.01 plan approach, if I wanted to charge 12.50/month I could adjust the quantity like so:
Stripe Support
First, you’ll need to create a new customer.
On submit, you could use the custom amount to create a new plan:
Keep in mind that the
'id'
needs to be unique. You could use the customer’s name, a time stamp, or some other random method to ensure that this is always the case.You’d then just create the subscription on the newly-added customer:
You probably will be able to omit the first line above, as you should already have a customer variable assigned from when the customer was actually created.
This is low tech, but the easiest thing I found was to use as little of the Stripe API as possible. Instead of creating subscription plans and products and things like that, you just:
If you already know how to charge somebody, you just have to figure out how to create the customer, and then the rest is good to go.
This means you shift some of Stripe’s cleverness to our own infrastructure, but I actually found this easier to think about/maintain than thinking through all of Stripe’s API docs and features.