Skip to main content
import { createPoller } from "@zopay/js";

const poller = createPoller(options);
createPoller expone la máquina de estados de polling sin el widget renderizado. Útil cuando quieres una UI completamente custom pero no quieres reimplementar el ciclo de “pegar al endpoint, mapear estado, disparar callbacks”.

Signature

function createPoller(options: CreatePollerOptions): Poller;

Opciones

CampoTipoDescripción
checkStatus() => Promise<StatusInfo>Callback que devuelve el estado actual. Igual contrato que en mountPaymentWidget.
pollIntervalMsnumberIntervalo entre polls.
timeoutMsnumberTiempo máximo antes de marcar la sesión como expirada.
onSuccess(info: StatusInfo) => voidDisparado cuando el estado pasa a completed.
onError(info: StatusInfo) => voidDisparado en estados de fallo.
onExpire() => voidDisparado al cumplirse timeoutMs sin éxito.

API del poller

{
  start(): void;
  stop(): void;
  refresh(): void;
  getPhase(): "idle" | "polling" | "completed" | "failed" | "expired";
  getLastStatus(): StatusInfo | null;
}

Ejemplo

import { createPoller } from "@zopay/js";

const poller = createPoller({
  checkStatus: async () => {
    const res = await fetch(`/api/zopay/status/${intent.id}`);
    return normalizeIntent(await res.json());
  },
  pollIntervalMs: 3000,
  timeoutMs: 15 * 60 * 1000,
  onSuccess: (info) => {
    document.getElementById("amount-received").textContent = String(info.amountReceived);
    showSuccessScreen(info);
  },
  onError:   (info) => showErrorScreen(info),
  onExpire:  ()     => showExpiredScreen(),
});

poller.start();

// En algún botón "verificar ahora":
button.onclick = () => poller.refresh();

// Al desmontar:
poller.stop();

Cuándo elegir poller vs widget

  • Widget (mountPaymentWidget) — flujo típico: ZoPay te da QR + selector + polling listo. Menos código.
  • Poller (createPoller) — UI 100% custom: quieres tu propio QR / branding / animaciones pero sin reimplementar el ciclo de polling.