Guides

How to handle failed and pending Mobile Money payments in Ghana

A Mobile Money payment is pending from the moment the prompt is sent until the customer approves it on their phone, and it fails if they decline, enter the wrong PIN, have too little money, or simply don't respond. Good software treats pending as normal, never assumes success, lets the customer try again, and makes sure a retry can't charge twice.

Step by step

  1. 1

    Expect delays

    Prompts can take a while to arrive, and customers take time to find their phone. Don't time out after a few seconds.

  2. 2

    Never assume

    Fulfil only on a paid status or a verified webhook.

  3. 3

    Make retries safe

    Send an Idempotency-Key header when you create a payment. Sending the same key again returns the same payment and never creates a second one.

  4. 4

    Offer another way

    If the prompt doesn't arrive, give the customer the payment page, where they can use another network or a card.

  5. 5

    Close old payments

    Set an expiry so yesterday's unpaid checkout can't be paid at an old price.

  6. 6

    Read the failure

    A failed charge carries a failure message. Show the customer something useful, not a code.

Create safely, then follow the result

// Node.js: the same Idempotency-Key always returns the same charge
const res = await fetch("https://berrapay.com/api/v1/charges", {
  method: "POST",
  headers: {
    Authorization: "Bearer " + process.env.BERRAPAY_KEY,
    "Content-Type": "application/json",
    "Idempotency-Key": "order-" + order.id + "-try-" + order.attempt,
  },
  body: JSON.stringify({ amount: order.total, phone: order.phone, network: order.network }),
});
const charge = await res.json();
if (charge.status === "failed") tellCustomer(charge.failure); // why it wasn't approved
else if (charge.status === "pending") showWaiting(charge.pay_url); // they can also pay from this page

What each state means

StateWhat happenedWhat to do
pendingThe prompt is out and the customer hasn't answeredShow a waiting screen and listen for the result
succeeded or paidThe customer approved and the money is confirmedFulfil the order, once
failedDeclined, wrong PIN, not enough money or no responseTell the customer plainly and offer to try again
expiredThe time to pay ran outCreate a new payment if they still want to buy

Common questions

How long should I wait before giving up?

A phone charge can be approved for 15 minutes. Keep the order open at least that long.

The customer says they were charged but I see failed.

Check the payment in berrapay first. If the money did leave their wallet and didn't arrive, report it from the payment or at berrapay.com/dispute.

How do I avoid charging twice when my request times out?

Retry with the same Idempotency-Key. You get the original payment back.

Ask an AI assistant about this

Opens the assistant in a new tab with a question about this page already typed. You can change it before sending.

Related

Send. Collect. Get paid.

One app to pay anyone in Ghana and get paid by everyone. No setup fee and no monthly fee.

Get started free