Scan to pay
The customer pays in their InnBucks or PayGo app. Your page shows a short code and a QR code; the customer scans the QR or types the code in the app, and approves the payment there.
| Method | Currency | Code |
|---|---|---|
| InnBucks | USD | PZW212 |
| PayGo | ZiG | PZW210 |
In the checkout element
Section titled “In the checkout element”There is nothing to code. After the customer presses Pay, the element shows
the code and the QR code, and waits while they pay in their app. That can
take a few minutes. The element then shows the result and sends finished.
With your own method picker
Section titled “With your own method picker”Use the scan element when you build the method picker yourself.
confirmScanPayment() returns a scan_code next action, and the element
shows the code and the QR. Nothing is paid until the customer pays in their
app, so follow it with waitForTransaction() and a long timeout, such as five
minutes.
<form id="scan-form" data-reference-number="REF-1" data-provider="InnBucks"> <div id="scan"></div> <button type="submit">Pay</button> <p id="payment-message"></p></form><script type="module" src="/src/scan-pay.ts"></script>import { loadPesepay, type ScanProvider } from "@pesepay/js";
const form = document.querySelector<HTMLFormElement>("#scan-form")!;const message = document.querySelector<HTMLElement>("#payment-message")!;// Your server created the transaction and wrote its reference number here.const referenceNumber = form.dataset.referenceNumber!;// "InnBucks" for USD or "PayGo" for ZiG.const provider = form.dataset.provider as ScanProvider;
async function start(): Promise<void> { // Null if the runtime could not load, for example behind a content blocker. const pesepay = await loadPesepay(); if (!pesepay) { message.textContent = "Payments are unavailable. Please try again later."; return; }
const scan = pesepay.elements().create("scan", { provider }); scan.mount("#scan");
form.addEventListener("submit", async (event) => { event.preventDefault();
// The element now shows a short code and a QR code for the customer's app. const sent = await pesepay.confirmScanPayment(referenceNumber, { element: scan }); if (sent.error) { message.textContent = sent.error.message; return; } if (sent.transaction.nextAction?.type !== "scan_code") { message.textContent = sent.transaction.outcome; return; }
// Nothing is paid until the customer pays in their app, which can take // a few minutes. const paid = await pesepay.waitForTransaction(referenceNumber, { timeoutMs: 300_000, }); message.textContent = paid.error ? paid.error.message : paid.transaction.outcome; });}
void start();import { useState } from "react";import type { ScanProvider } from "@pesepay/js";import { Elements, ScanElement, useElements, usePesepay } from "@pesepay/react";
interface ScanFormProps { referenceNumber: string; /** "InnBucks" for USD or "PayGo" for ZiG. */ provider: ScanProvider;}
export function ScanForm(props: ScanFormProps) { return ( <Elements> <PayByScan {...props} /> </Elements> );}
function PayByScan({ referenceNumber, provider }: ScanFormProps) { const pesepay = usePesepay(); const elements = useElements(); const [message, setMessage] = useState("");
async function pay(): Promise<void> { const scan = elements?.getElement("scan"); if (!pesepay || !scan) return;
// The element now shows a short code and a QR code for the customer's app. const sent = await pesepay.confirmScanPayment(referenceNumber, { element: scan }); if (sent.error) { setMessage(sent.error.message); return; } if (sent.transaction.nextAction?.type !== "scan_code") { setMessage(sent.transaction.outcome); return; }
// Nothing is paid until the customer pays in their app, which can take // a few minutes. const paid = await pesepay.waitForTransaction(referenceNumber, { timeoutMs: 300_000, }); setMessage(paid.error ? paid.error.message : paid.transaction.outcome); }
return ( <form onSubmit={(event) => { event.preventDefault(); void pay(); }} > <ScanElement options={{ provider }} /> <button type="submit">Pay</button> <p>{message}</p> </form> );}<script setup lang="ts">import { ref } from "vue";import type { Elements as PesepayElements, Pesepay, ScanProvider } from "@pesepay/js";import { Elements, ScanElement } from "@pesepay/vue";
const props = defineProps<{ referenceNumber: string; /** "InnBucks" for USD or "PayGo" for ZiG. */ provider: ScanProvider;}>();const message = ref("");
async function pay( pesepay: Pesepay | null, elements: PesepayElements | null,): Promise<void> { const scan = elements?.getElement("scan"); if (!pesepay || !scan) return;
// The element now shows a short code and a QR code for the customer's app. const sent = await pesepay.confirmScanPayment(props.referenceNumber, { element: scan, }); if (sent.error) { message.value = sent.error.message; return; } if (sent.transaction.nextAction?.type !== "scan_code") { message.value = sent.transaction.outcome; return; }
// Nothing is paid until the customer pays in their app, which can take a // few minutes. const paid = await pesepay.waitForTransaction(props.referenceNumber, { timeoutMs: 300_000, }); message.value = paid.error ? paid.error.message : paid.transaction.outcome;}</script>
<template> <Elements v-slot="{ pesepay, elements }"> <form @submit.prevent="pay(pesepay, elements)"> <ScanElement :options="{ provider: props.provider }" /> <button type="submit">Pay</button> <p>{{ message }}</p> </form> </Elements></template>import { Component, computed, input, signal } from "@angular/core";import type { Elements as PesepayElements, Pesepay, ScanProvider } from "@pesepay/js";import { Elements, ScanElement } from "@pesepay/angular";
@Component({ selector: "app-scan-pay", imports: [Elements, ScanElement], template: ` <pesepay-elements #checkout="pesepayElements"> <form (submit)="pay($event, checkout.instance(), checkout.elements())"> <pesepay-scan-element [options]="options()" /> <button type="submit">Pay</button> <p>{{ message() }}</p> </form> </pesepay-elements> `,})export class ScanPayComponent { readonly referenceNumber = input.required<string>(); /** "InnBucks" for USD or "PayGo" for ZiG. */ readonly provider = input.required<ScanProvider>(); protected readonly options = computed(() => ({ provider: this.provider() })); readonly message = signal("");
async pay( event: Event, pesepay: Pesepay | null, elements: PesepayElements | null, ): Promise<void> { event.preventDefault(); const scan = elements?.getElement("scan"); if (!pesepay || !scan) return;
// The element now shows a short code and a QR code for the customer's app. const sent = await pesepay.confirmScanPayment(this.referenceNumber(), { element: scan, }); if (sent.error) { this.message.set(sent.error.message); return; } if (sent.transaction.nextAction?.type !== "scan_code") { this.message.set(sent.transaction.outcome); return; }
// Nothing is paid until the customer pays in their app, which can take // a few minutes. const paid = await pesepay.waitForTransaction(this.referenceNumber(), { timeoutMs: 300_000, }); this.message.set(paid.error ? paid.error.message : paid.transaction.outcome); }}A timeout error from waitForTransaction() means the SDK stopped looking,
not that the payment failed: the customer may still pay. Your result
callback gets the outcome either way.
The QR image is a data: URL for InnBucks and an image on PayGo’s host for
PayGo. If your page sends a Content-Security-Policy, allow both in img-src;
see Accept a payment.
What’s next
Section titled “What’s next”- Accept a payment: every outcome, and fulfilling from your server