Skip to content

Mobile money approval

The customer types their phone number and approves the payment from their phone. The two methods approve it in different ways:

MethodHow the customer approves itUSDZiG
EcoCashEnters their PIN in a prompt on their phonePZW211PZW201
O’mariTypes the code from an SMS into the same field on your pagePZW216PZW217

The method follows the transaction’s currency.

There is nothing to code.

  • EcoCash. After the customer presses Pay, the element shows “Check your phone” with a countdown and waits for their answer. The customer enters their PIN on their phone, never on your page.
  • O’mari. The first press sends an SMS code, and the field asks for it. The customer types the code and presses Pay again.

Either way the element then shows the result and sends finished. An unknown outcome means no answer came in time: the customer may still approve, so don’t let them pay again (see Accept a payment).

Use the mobile element when you build the method picker yourself. Your code differs by method:

  • EcoCash: confirm once. confirmMobilePayment() returns at processing, and the element waits for the customer’s answer itself. Each step arrives as a status event: awaiting_approval, then succeeded, failed, reversed or unknown. There is no resend: while a prompt is live, EcoCash refuses another.
  • O’mari: confirm twice. The first confirm sends the SMS and returns nextAction.type === "enter_otp", and the element’s change events report step: "otp", your cue to relabel the button. Confirm again with the same reference and element, then wait with waitForTransaction().
checkout.html
<form id="mobile-form" data-reference-number="REF-1" data-provider="EcoCash">
<div id="phone"></div>
<button type="submit">Pay</button>
<p id="payment-message"></p>
</form>
<script type="module" src="/src/mobile-pay.ts"></script>
src/mobile-pay.ts
import { loadPesepay, type MobileProvider } from "@pesepay/js";
const form = document.querySelector<HTMLFormElement>("#mobile-form")!;
const button = form.querySelector<HTMLButtonElement>("button")!;
const message = document.querySelector<HTMLElement>("#payment-message")!;
// Your server created the transaction and wrote its reference number here.
const referenceNumber = form.dataset.referenceNumber!;
// "EcoCash" or "Omari": the method the customer picked.
const provider = form.dataset.provider as MobileProvider;
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 mobile = pesepay.elements().create("mobile", { provider });
mobile.on("change", (event) => {
message.textContent = event.error?.message ?? "";
// O'mari has sent its SMS code, and the field now asks for it.
if (event.step === "otp") button.textContent = "Confirm code";
});
// EcoCash: the element shows "Check your phone" and waits for the
// customer's answer itself, reporting it here.
mobile.on("status", ({ status }) => {
if (status !== "awaiting_approval") message.textContent = status;
});
mobile.mount("#phone");
form.addEventListener("submit", async (event) => {
event.preventDefault();
const result = await pesepay.confirmMobilePayment(referenceNumber, {
element: mobile,
});
if (result.error) {
message.textContent = result.error.message;
return;
}
// O'mari, first submit: the customer types the code and submits again.
if (result.transaction.nextAction?.type === "enter_otp") return;
// O'mari, second submit: wait for the result. EcoCash reports through
// the status event instead.
if (provider === "Omari") {
const paid =
result.transaction.outcome === "processing"
? await pesepay.waitForTransaction(referenceNumber)
: result;
message.textContent = paid.error ? paid.error.message : paid.transaction.outcome;
}
});
}
void start();

A transaction gets one O’mari SMS. If the page reloads after it went out, create the element with resumeOtpFor: referenceNumber to start it on the code step, but only when you know no code has been submitted. To pay again after a failure, with either method, create a new transaction and a new element.