import { mountPaymentWidget, normalizeIntent } from "@zopay/js";
import "@zopay/js/styles.css";
// 1. Tu backend mintea el intent.
const intent = await fetch("/api/zopay/checkout/session", { method: "POST" })
.then(r => r.json());
// 2. Montar el widget. El callback `checkStatus` proxea estado a tu backend.
const handle = mountPaymentWidget(document.getElementById("pay")!, {
intent,
checkStatus: async () => {
const res = await fetch(`/api/zopay/status/${intent.id}`);
return normalizeIntent(await res.json());
},
onSuccess: (info) => console.log("paid", info.txHash, info.amountReceived),
onError: (info) => console.error("failed", info),
onExpire: () => console.warn("timed out; revisa manualmente"),
theme: "light",
});
// React/Vue: limpia en unmount.
// useEffect(() => () => handle.destroy(), []);
// Trigger inmediato de status check.
// handle.refresh();