Skip to content
Wire Ghdocs

Charge API

Collect Mobile Money payments inside your own website or app, with your own screens, without sending customers to the Wire Gh checkout.

Server side only

The Charge API uses your secret key, so every call must come from your server. Your app collects the number and sends it to your server, and your server calls Wire Gh.

Mobile Money only

The Charge API takes Mobile Money. Wire Gh wallet payments need the customer's wallet PIN, which is only ever entered on the Wire Gh checkout or popup, never in a merchant's app.

How it works

  1. Collect the detailsIn your app, ask for the customer's Mobile Money number. You can show the network for them: it follows from the first three digits (see networks).
  2. Create the chargeYour server calls Create Charge with the email, amount and number.
  3. Guide the customerMost charges come back as pay_offline: the customer gets a prompt on their phone and approves it with their Mobile Money PIN. Show them display_text while they do this.
  4. Confirm the resultListen for the charge.success webhook, or check with Check Pending Charge. Then verify and give value.

Create a charge

POST/charge
curl https://api.wiregh.com/charge \
-H "Authorization: Bearer YOUR_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{
  "email": "customer@email.com",
  "amount": 5000,
  "mobile_money": {
    "phone": "0551234987",
    "provider": "mtn"
  }
}' \
-X POST

Handle the response

The data.status field tells you the next step:

StatusMeaningNext step
pay_offlineA prompt is on the customer's phone.Show display_text. Wait for the webhook, or check again after 10 seconds.
send_otpThe network sent the customer a code.Collect it and call Submit OTP.
successThe payment is complete.Verify and give value.
failedThe charge did not go through.Show gateway_response, for example "Declined by customer", and offer to try again with a new charge.
Example: waiting for approval
{
  "status": true,
  "message": "Charge attempted, awaiting customer approval",
  "data": {
    "reference": "WG261109798FAXRFERYSSG",
    "status": "pay_offline",
    "display_text": "Approve the prompt on your phone to complete this payment.",
    "gateway_response": "Awaiting customer approval",
    "retry_allowed": false
  }
}

A customer has up to 30 minutes from the start of the transaction to approve the prompt. If they never do, the transaction fails with gateway_response "Timed out waiting for customer" and a charge.failed webhook is sent.

Full example

// 1. Charge the number (on your server)
const charge = await wireGh('POST', '/charge', {
  email: 'customer@email.com',
  amount: 5000,
  mobile_money: { phone: '0551234987', provider: 'mtn' },
  metadata: { order_id: '1042' }
});

// 2. Act on the status
switch (charge.data.status) {
  case 'success':
    // Paid. Verify, then give value.
    break;
  case 'pay_offline':
    // Show charge.data.display_text and wait for the charge.success webhook
    break;
  case 'send_otp':
    // Ask the customer for the code, then call /charge/submit_otp
    break;
  default:
    // failed: show charge.data.gateway_response and let them try again
}

async function wireGh(method, path, body) {
  const res = await fetch('https://api.wiregh.com' + path, {
    method,
    headers: {
      Authorization: 'Bearer ' + process.env.WIREGH_SECRET_KEY,
      'Content-Type': 'application/json'
    },
    body: body ? JSON.stringify(body) : undefined
  });
  return res.json();
}

Good practice

  • Send an Idempotency-Key with every charge, so a network retry never charges your customer twice.
  • Do not check the status in a tight loop. Webhooks are faster and lighter, and repeated checks count towards your rate limit.
  • After five failed charges in an hour, a number is paused for an hour. Show the customer a clear message rather than retrying.
  • Use the test numbers to try every status before you go live.