Introduction
Learn how to connect your website or app to the Wire Gh Pay API.
API basics
You need a free Wire Gh account. Open Wire Pay from your dashboard and your test keys are ready at once, so you can start calling the API right away.
The Wire Gh Pay API lets you collect payments, confirm them, manage customers and send refunds from your own code. It is a REST API: you send standard HTTP requests with JSON bodies, and every response is JSON.
All requests must use HTTPS. Requests over plain HTTP are refused.
Base URL
Send every request to:
https://api.wiregh.comThe same base URL serves test and live mode. The key you send decides which one you are using.
Test and live mode
Every business has two sets of keys. Use your test keys while you build. Test payments move no real money, and you can trigger every outcome with our test numbers. Live keys appear on your dashboard after your business is approved, and they collect real money.
| Key | Starts with | Where to use it |
|---|---|---|
| Test public key | wg_pk_test_ | Your website or app, for the popup |
| Test secret key | wg_sk_test_ | Your server only |
| Live public key | wg_pk_live_ | Your website or app, for the popup |
| Live secret key | wg_sk_live_ | Your server only |
Records are kept apart by mode. A transaction made with a test key can only be seen with a test key.
Requests and responses
Send request bodies as JSON with the header Content-Type: application/json. Every response has the same envelope:
{
"status": true,
"message": "Verification successful",
"data": { }
}statusistruewhen the request worked andfalsewhen it did not.messageis a short summary you can log or show.dataholds the result. List endpoints also returnmeta, see pagination.
All amounts are whole numbers in pesewas, the smallest unit of the Ghana cedi. GHS 1.00 is 100, and GHS 250.50 is 25050. Decimals are refused.
Every response carries an x-request-id header. Include it when you contact support about a request.
Authentication
Authenticate every request by sending your secret key as a Bearer token in the Authorization header:
Authorization: Bearer wg_sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxcurl https://api.wiregh.com/balance \
-H "Authorization: Bearer YOUR_SECRET_KEY" \
-X GETconst response = await fetch('https://api.wiregh.com/balance', {
method: 'GET',
headers: {
Authorization: 'Bearer YOUR_SECRET_KEY'
}
});
const result = await response.json();
console.log(result);<?php
$ch = curl_init('https://api.wiregh.com/balance');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_SECRET_KEY',
],
]);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
print_r($result);Your secret key can move money on your account. Use it only on your server. Never put it in a web page, a mobile app, a public code repository or a support message. If it leaks, open API & Sandbox on your dashboard and regenerate it at once.
Your public key is safe to use in the browser, but it can only start a payment with the popup and read the list of networks. A request with a missing or wrong key gets a 401 response.
For extra protection you can require signed requests on your secret keys and limit each secret key to the IP addresses of your servers. Both switches are on the API and Sandbox page of your dashboard.
Rate limits
Limits keep the API fast and protect your account from abuse. When you go over a limit you get a 429 response with a Retry-After header that says how many seconds to wait.
| Limit | Requests per minute |
|---|---|
| Per secret key | 300 |
| Per public key | 120 |
| Per IP address | 600 |
An IP address that sends many requests with wrong keys is blocked for a while. Repeated failed charges on one Mobile Money number are also paused for an hour, to protect your customers.
If you need higher limits, contact support.
Pagination
List endpoints return results a page at a time, newest first. Use these query parameters:
Query parameters
perPageIntegeroptional- Records per page, from 1 to 100. Defaults to 50.
pageIntegeroptional- The page to return. Defaults to 1.
The meta object tells you where you are:
"meta": {
"total": 120,
"perPage": 50,
"page": 1,
"pageCount": 3
}Errors
When a request fails, status is false, message explains what went wrong, and code is a stable value you can check in your code:
{
"status": false,
"message": "amount must be a whole number in pesewas (e.g. 5000 for GHS 50.00).",
"code": "invalid_request"
}HTTP status codes
| Code | Meaning |
|---|---|
200 | The request worked. |
400 | Something in the request is wrong or missing. Read message. |
401 | The key is missing, wrong, or the wrong type for this endpoint. |
403 | The request is not allowed, for example live mode is not activated yet. |
404 | The record or endpoint does not exist. |
409 | The request clashes with one already in progress. |
429 | Too many requests. Wait for the number of seconds in Retry-After. |
500, 503 | A problem on our side. Wait a moment and retry with the same Idempotency-Key. |
Error codes
| Code | HTTP | Meaning |
|---|---|---|
invalid_request | 400 | A parameter is missing or not valid. message names it. |
invalid_json | 400 | The request body is not valid JSON. |
duplicate_reference | 400 | You already used this reference. References must be unique. |
transaction_closed | 400 | The transaction is already complete, failed or abandoned. |
expired | 400 | The transaction expired before it was paid. Start a new one. |
attempts_exceeded | 400 | The transaction has had too many charge attempts. |
otp_not_expected | 400 | This charge is not waiting for an OTP. |
unsupported_channel | 400 | This payment channel cannot be used here. |
starter_limit_reached | 400 | A Starter business has reached its collection limit. Upgrade to a Registered business. |
not_refundable | 400 | Only successful transactions can be refunded. |
refund_exceeds | 400 | The refund is more than the amount not yet refunded. |
insufficient_balance | 400 | Your balance cannot cover this refund. |
unauthorized | 401 | No Authorization header was sent. |
invalid_key | 401 | The key is not valid. Check that you copied it fully. |
wrong_key_type | 401 | This endpoint needs your secret key, not your public key. |
bad_signature | 401 | The request signature is missing, old or wrong. See signed requests. |
https_required | 403 | The request was not sent over HTTPS. |
live_not_enabled | 403 | Your business is not approved for live payments yet. |
merchant_inactive | 403 | Your business account is suspended. Contact support. |
ip_not_allowed | 403 | This key only accepts requests from certain IP addresses. |
ip_blocked | 403 | Requests from this IP address are blocked. |
not_found | 404 | The record or endpoint does not exist. |
method_not_allowed | 405 | The endpoint exists but not with this HTTP method. |
charge_in_progress | 409 | A charge is already running for this transaction. Verify it or wait. |
idempotency_conflict | 409 | This Idempotency-Key was used with a different request, or that request is still running. |
body_too_large | 413 | The request body is larger than 64KB. |
rate_limited | 429 | Too many requests. Slow down and retry later. |
velocity_limit | 429 | Too many failed charges on this number. Try again later. |
otp_attempts | 429 | Too many wrong OTP attempts on this charge. |
provider_unavailable | 503 | The Mobile Money network is not responding. Retry shortly. |
server_error | 500 | Something went wrong on our side. message includes a reference for support. |