I am developing a wordpress site for my client. He wants 3 types of payments
How can I cancel/stop after 2 months the third subscription?
The best option is to use SubscriptionSchedules. They allow control of multiple "phases" on a subscription such as the number of iterations (in your case 2), or what to do at the end of a phase (such as switching to a new Price).
You would create a SubscriptionSchedule via the API where you have one phase on Price price_123
and you would set the iterations
parameter to 2 so that it renew for a second month. You would also set the end_behavior
parameter to cancel
to indicate that the underlying Subscription should be canceled at the end of the second month automatically.
An alternative would be to simply create a Subscription to Price price_123
and listen to the invoice.created
event. On the second month when the new Invoice is created you can use the Update Subscription API and set the cancel_at_period_end
parameter to true
to indicate you want the Subscription to stop at the end of that second month.