Redirect to dynamic page after Wix Pricing Plan purchase (pharmacyId issue)

I’m having trouble with redirecting users to a dynamic page after a successful purchase using Wix Pricing Plans. After the payment, users see the standard thank you page and receive an automated email, but when they click the link, it briefly loads a post-payment message and then fails to redirect to the intended dynamic page (returns a 404). I’m working in Wix Editor with Dev Mode enabled, using CMS collections and dynamic pages (e.g. /farmacia-hta/{pharmacyId}). Site link: https://www.educacionterapeutica.com. What I’m trying to do is automatically send each user to their own dynamic page based on a unique pharmacyId after purchase, or at least provide a working personalized link. What I’ve tried so far: backend code to activate the license after payment (works), using dynamic URLs in automated emails (e.g. {{pharmacyld}}, not working), and testing static URLs (which do work). Extra context: the system depends on linking each purchase to a CMS item, and I need a reliable way to pass that identifier into the post-payment flow or email.

Can you share the code that you’ve tried?

It’s difficult to tell where it might be working for you, and what might need changing to make it work. The code you’re attempted would be a great starting point :slight_smile:

The code for the post-pago-hta page is:

import wixLocation from ‘wix-location’;

$w.onReady(function () {

**const** query = wixLocation.query || {};

**const** pharmacyld = (query.pharmacyld || "").trim();

**const** target = (query.target || "").trim();



// Opcional: si tienes estos elementos en la página

**if** ($w("#txtEstado")) {

    $w("#txtEstado").text = "Estamos abriendo tu acceso profesional...";

    $w("#txtEstado").show();

}



// Caso 1: viene una ruta completa

**if** (target) {

    wixLocation.to(target);

    **return**;

}



// Caso 2: viene el pharmacyld

**if** (pharmacyld) {

    wixLocation.to(\`/farmacia-hta/${encodeURIComponent(pharmacyld)}\`);

    **return**;

}



// Si no llega nada, muestra mensaje claro

**if** ($w("#txtEstado")) {

    $w("#txtEstado").text =

        "No hemos podido identificar tu farmacia. Revisa el enlace del email o contacta conmigo.";

    $w("#txtEstado").show();

}

});