Redirection after payment

Using the Return URL, it's possible for the payment to be completely processed in the Asaas interface, with your customer being redirected back to your site after the payment is completed.

The Return URL works with payments, payment links, and subscriptions, and you can choose between automatic redirectionautoRedirect or not. If automatic redirection is not chosen, after the payment is completed by your customer, a button with the text "Go to the site" will be shown.

The autoRedirect works for payments via credit card, debit card (only on the invoice), and Pix, as these are the means of payment that allow for instant payment confirmation.

The URL provided must necessarily be from the same domain registered in your commercial data, which you can find in "Account Settings" under the "Information" tab.

Creating an invoice with automatic redirection

The way to create a payment is the same, just an additional attribute, the callback, is needed. If it is informed, your payment will be set up to send the customer back to your site after the payment.

POST /v3/payments
Check the complete reference of this endpoint

{
  "customer": "cus_000005219613",
  "billingType": "PIX",
  "value": 2000.00,
  "dueDate": "2023-07-21",
  "callback":{
    "successUrl": "https://yoursite.com/redirect",
    "autoRedirect": false // only send if automatic redirect is disabled
  }
}

📘

If you have set autoRedirect as false, a button with the text "Go to the site" will be displayed to your customer after the payment is completed.

After creating a payment with Return URL, you can redirect your customer to the URL in the invoiceUrl attribute of the response JSON. At the moment the payment is completed, they will be sent to the URL you defined.

If the customer accesses the invoice link (invoiceUrl) again at another time, they will no longer be redirected to your site since the payment will have already been completed previously. In this case, they will just see a paid invoice.

📘

You can add the parameter ?autoRedirect=true to the invoice URL if you want the user to always be redirected when accessing the invoiceUrl.

You can also update a Payment by sending the same attributes on the payment update endpoint.

Creating a payment link with automatic redirection

Similarly, you can create a payment link that redirects the customer to the informed link upon successful payment.

POST /v3/paymentLinks
Check the complete reference of this endpoint

{
  "name": "My payment link",
  "billingType": "UNDEFINED",
  "value": 2000.00,
  "chargeType": "DETACHED",
  "callback":{
    "successUrl": "https://yoursite.com/redirect",
    "autoRedirect": false // only send if automatic redirect is disabled
  }
}

📘

Just like with the invoice, if you have set autoRedirect as false, a button with the message "go to the site" will be shown on the approved payment screen.

After creating the Payment Link with Success URL, you can redirect your customer to the returned url. The moment the payment is confirmed, they will be sent to the URL you defined.

You can also update a Payment Link by sending the same attributes in the payment link update endpoint.