MercadoPago Basic Subscription Checkout

Official Content

You will need your access token (Basic one), seller id, and a transaction in which you can keep information about subscriptions.
First, you have to save a new subscription, which will be edited later, after the user completes the payment. (Set name, currency, dates, etc.).
You also need to initialize a PreApproval SDT with information to create the subscription.

&Suscription.SusName = 'GX Suscription Basic'
&Suscription.SusCurrency_id = currency_id.Mexico
&Suscription.SusStartDate = now()    
&Suscription.SusEndDate = &Suscription.SusStartDate.AddDays(10)
&Suscription.SusAmount = 10
&Suscription.SusFrequency = 1
&Suscription.SusFrequencyType = frequency_type.days
&Suscription.SusPayer_email = !'test_user_email@testuser.com'

&preapprovalINSDTtype: PreApprovalINSDT
&preapprovalINSDT= new()
&preapprovalINSDT.external_reference = &Suscription.SuscId.ToString().Trim()                
&preapprovalINSDT.back_url =  &BaseURL.Trim() + Sample.Standard.PreferenceBackURLPanelSuccess.Link()
&preapprovalINSDT.collector_id = &Collector_Id
&preapprovalINSDT.reason = &Suscription.SusName.Trim()
&preapprovalINSDT.payer_email = &Suscription.SusPayer_email.Trim()
 
&preapprovalINSDT.auto_recurring.currency_id = &Suscription.SusCurrency_id
&preapprovalINSDT.auto_recurring.frequency = &Suscription.SusFrequency
&preapprovalINSDT.auto_recurring.frequency_type = &Suscription.SusFrequencyType
&preapprovalINSDT.auto_recurring.transaction_amount = &Suscription.SusAmount
&preapprovalINSDT.auto_recurring.start_date = ToDateTimeUTC(&Suscription.SusStartDate)
&preapprovalINSDT.auto_recurring.end_date = ToDateTimeUTC(&Suscription.SusEndDate)
&preapprovalINSDT.notification_url = &Notification_Url.Trim()

back_url refers to the URL in your application to which the user will be redirected after the transaction is completed in MercadoPago's website.

To create the subscription, you need to call

MercadoPago.Preference.CreatepreApproval(&Access_Token,&preapprovalINSDT,&preapprovalOUTSDT,&Message,&ErrorCode)

If Success (ErrorCode = 0), update the subscription information (&preapprovalOUTSDT contains information about the subscription)

Finally, redirect the user to init_point (or sandbox_init_point), where the subscription can be completed (from MercadoPago’s site).

link(&preapprovalOUTSDT.init_point)


Was this page helpful?
What Is This?
Your feedback about this content is important. Let us know what you think.