I’m using Mercado Pago’s CheckoutPro in a Next.js application. Inside my app, I follow a structure similar to this one:
However, my user is not automatically redirected after making a payment with PIX. The redirection works normally for any other payment method because of the back_urls configuration when creating a payment preference:
back_urls: {
success: `${req.headers.get("origin")}/?status=success`,
failure: `${req.headers.get("origin")}/?status=failure`,
pending: `${req.headers.get("origin")}/api/mercado-pago/pending`, // We created a route to handle pending payments
},
After reading more about it, I found out that PIX payments are asynchronous, so Mercado Pago cannot take action when the payment is made. I was instructed to listen to the Mercado Pago webhook to know when the payment is completed. However, I would like to automatically redirect the customer after the payment is done.
I’ve thought about techniques like polling or WebSockets, but I can't apply them since the user is on the Mercado Pago domain during the payment process. Has anyone faced something similar and knows how to handle it?
I tried implementing it using backURL, but it doesn’t trigger automatic redirection for PIX payments.