Skip to content

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.

MethodCurrencyCode
InnBucksUSDPZW212
PayGoZiGPZW210

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.

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.

checkout.html
<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>
src/scan-pay.ts
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();

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.