Stripe: How to set up recurring payments without a plan?

First time working with Stripe API. Implementing it in WordPress using PHP and JS. Work on the form of gift. The donor should be able to choose the proposed amount (radio buttons 25,50,75,100) or pay as he sees fit (text box after selecting "other"). I was able to get this job.

There is a checkbox to set the amount as a recurring payment. I have created recurring payment plans for fixed options like 25, 50, 100, etc.

How to set up a recurring payment if the donor selects an individual amount? Cannot find the appropriate API. Please, help.

+7
javascript php forms wordpress stripe-payments
source share
2 answers

First you need to create a new customer .

In send mode, you can use a custom amount to create a new plan :

$current_time = time(); $plan_name = strval( $current_time ); Stripe_Plan::create(array( "amount" => $_POST['custom-amount'], "interval" => "month", "name" => "Some Plan Name " . $_POST['customer-name'], "currency" => "usd", "id" => $plan_name ) ); 

Keep in mind that the 'id' must be unique. You can use the customer name, timestamp, or some other random method to ensure that this is always the case.

Then you just created a subscription to the added client :

 $customer = Stripe_Customer::retrieve($customer_just_created); $customer->subscriptions->create(array("plan" => $plan_name)); 

You can probably omit the first line above, since you should already have a client variable assigned since the client was created.

+5
source share

Another approach that Stripe offers is to set up a plan with a recurring amount of $ 1 (or $ 0.01 for more flexibility), and then change the quantity if necessary.

eg. Using a $ 0.01 plan, if I wanted to charge 12.50 per month, I could set the amount as follows:

 $customer->subscriptions->create(array("plan" => "basic", "quantity" => "1250")); 

Band Support

+17
source share

All Articles