This document shows how to create a Subscription without leaving the seller site.
You can create a Subscription directly or from a Plan or Template. These are the steps that need to be followed:
- Setting Credentials
- Create a Plan (optional)
- Submit a form in which the user will select the method of payment and card details, safely.
- Get Card Token
- Create a Subscription with or without a plan
To create a Plan you first need to fulfill this PlanInputSDT with de corresponding information:
Then call the CreatePlan procedure:
&AccessToken = GetAccessToken()
MercadoPago.Subscriptions.CreatePlan(&AccessToken, &PlanInputSDT, &PlanInfoSDT, &Message, &ErrorCode)
If &ErrorCode = 0
&PlanId = &PlanInfoSDT.id
msg(format('Plan %1 successfully created', &PlanId), status)
else
msg(&Message.Description, status)
endif
The result of this operation is an SDT (&PlanInfoSDT) with all the information of the created plan.
Here you will need to create a Web Panel where the user will enter their credit card information safely. See MercadoPago Custom Checkout
After submitting the panel, you will get a Token for the credit card, required for the next step.
To create a subscription from a Plan, use the SubscriptionInputWithPlanSDT and fill it with the PlanId, PayerEmail, and the CardToken. Then call the CreateSubscriptionWithPlan procedure.
&SubscriptionInputWithPlanSDT = new()
&SubscriptionInputWithPlanSDT.preapproval_plan_id = &PlanId
&SubscriptionInputWithPlanSDT.card_token_id = &CardToken
&SubscriptionInputWithPlanSDT.payer_email = !'test_payer_xxx@testuser.com'
MercadoPago.Subscriptions.CreateSubscriptionWithPlan(&AccessToken, &SubscriptionInputWithPlanSDT, &SubscriptionInfoSDT, &Message, &ErrorCode)
If &ErrorCode = 0
msg(format('Subscription %1 successfully created', &SubscriptionInfoSDT.id), status)
else
msg(&Message.Description, status)
endif
To create a Subscription without a Plan, use the SubscriptionInputSDT to fill in the required information and then call the CreateSubscription procedure.