For this tutorial we will see how to create a subscription to charge periodically a service to a customer.
Say you have a service where you offer a one month trial and then you charge a monthly fee of $ 99.99 pesos indefinitely (or until your customer cancels the service).
You have to do the following:
- Create a plan
- Create customer
- Save card
- Subscribe customer
Create a plan
A plan is a template for a subscription that contains the cost, charge frequency, trial period, etc.
To create a plan we have two options:
Option 1.- Creation from the API
You can have as many plans as you want. For example you can have a Gold, Platinum and Bronze plan for different levels of service.
If the request is successful we will have a response that contains the
id of the plan
For more information about the plan parameters go to "Add Plan"
Option 2.- Creation from the dashboard
You can also create plans from the dashboard in Planes -> Agregar:
Create a customer
Now we’ll create the customer we want to subscribe:
The next thing is to save the customer card to use for the subscription. We are going to fill the customer
id (axapgwwolofnckfui2wx) created earlier.
Finally we create the subscription with the plan
id (psjubnktzpofhakixfkp), the customer
id (axapgwwolofnckfui2wx) and the card
id (kokzmiiwephcdmq1h2qr), thus the request would look like:
Ready, we have created the subscription, which will be automatically charged each month for $ 99.99 after trial period.
- You can simulate different results using the test cards
- Implement Notifications to know the status of payments in real time