Charge
The Charge API lets you collect a Mobile Money payment from inside your own website or app, without sending your customer to the Wire Gh checkout. Your server sends the number, the customer approves the prompt on their phone, and you confirm the result. Read the Charge API guide for the full flow.
Create Charge
Create a transaction and charge the Mobile Money number in one call. Look at data.status to know what to do next:
| Status | What to do |
|---|---|
success | Payment is complete. Verify it, then give value. |
pay_offline | A prompt was sent to the customer's phone. Show display_text and wait for the charge.success webhook, or check again with Check Pending Charge. |
send_otp | Ask the customer for the code sent to their phone and send it with Submit OTP. |
failed | The charge did not go through. gateway_response says why. Start a new charge to try again. |
Headers
authorizationStringrequired- Set value to
Bearer YOUR_SECRET_KEY. content-typeStringrequired- Set value to
application/json. idempotency-keyStringoptional- A unique value you choose so a retried request is processed only once. See idempotent requests.
Body parameters
emailStringrequired- Customer's email address.
amountIntegerrequired- Amount in pesewas. The minimum is
100. mobile_moneyObjectrequired- The number to charge:
{"phone": "0551234987", "provider": "mtn"}.providerismtn,telecelorairteltigoand must match the number's network; leave it out and we pick it from the number. See networks. referenceStringoptional- Your own unique reference. We create one if you leave it out.
metadataObjectoptional- Extra information to keep with the transaction.
currencyStringoptional- Only
GHSis supported.
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 POSTconst response = await fetch('https://api.wiregh.com/charge', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_SECRET_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: 'customer@email.com',
amount: 5000,
mobile_money: {
phone: '0551234987',
provider: 'mtn'
}
})
});
const result = await response.json();
console.log(result);<?php
$ch = curl_init('https://api.wiregh.com/charge');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode([
'email' => 'customer@email.com',
'amount' => 5000,
'mobile_money' => [
'phone' => '0551234987',
'provider' => 'mtn',
],
]),
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_SECRET_KEY',
'Content-Type: application/json',
],
]);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
print_r($result);{
"status": true,
"message": "Charge successful",
"data": {
"reference": "WG2611096D4HQE52FMY9KW",
"status": "success",
"display_text": null,
"gateway_response": "Approved",
"retry_allowed": false
}
}{
"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
}
}{
"status": true,
"message": "Charge attempted",
"data": {
"reference": "WG261109D245CYBPSRZPQK",
"status": "failed",
"display_text": "Declined by customer",
"gateway_response": "Declined by customer",
"retry_allowed": false
}
}{
"status": false,
"message": "mobile_money.phone does not belong to the telecel network.",
"code": "invalid_request"
}Submit OTP
Send the one time code your customer received, when a charge returned send_otp.
Headers
authorizationStringrequired- Set value to
Bearer YOUR_SECRET_KEY. content-typeStringrequired- Set value to
application/json. idempotency-keyStringoptional- A unique value you choose so a retried request is processed only once. See idempotent requests.
Body parameters
otpStringrequired- The code the customer entered.
referenceStringrequired- Reference of the charge that asked for the code.
curl https://api.wiregh.com/charge/submit_otp \
-H "Authorization: Bearer YOUR_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{
"otp": "123456",
"reference": "WG2611096D4HQE52FMY9KW"
}' \
-X POSTconst response = await fetch('https://api.wiregh.com/charge/submit_otp', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_SECRET_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
otp: '123456',
reference: 'WG2611096D4HQE52FMY9KW'
})
});
const result = await response.json();
console.log(result);<?php
$ch = curl_init('https://api.wiregh.com/charge/submit_otp');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode([
'otp' => '123456',
'reference' => 'WG2611096D4HQE52FMY9KW',
]),
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_SECRET_KEY',
'Content-Type: application/json',
],
]);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
print_r($result);{
"status": true,
"message": "Charge successful",
"data": {
"reference": "WG2611096D4HQE52FMY9KW",
"status": "success",
"display_text": null,
"gateway_response": "Approved",
"retry_allowed": false
}
}Check Pending Charge
Check the latest status of a charge, for example while your customer is approving a pay_offline prompt. Wait at least 10 seconds between checks; the webhook will usually reach you first.
Headers
authorizationStringrequired- Set value to
Bearer YOUR_SECRET_KEY.
Path parameters
referenceStringrequired- Reference of the charge.
curl https://api.wiregh.com/charge/WG2611096D4HQE52FMY9KW \
-H "Authorization: Bearer YOUR_SECRET_KEY" \
-X GETconst response = await fetch('https://api.wiregh.com/charge/WG2611096D4HQE52FMY9KW', {
method: 'GET',
headers: {
Authorization: 'Bearer YOUR_SECRET_KEY'
}
});
const result = await response.json();
console.log(result);<?php
$ch = curl_init('https://api.wiregh.com/charge/WG2611096D4HQE52FMY9KW');
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);{
"status": true,
"message": "Charge successful",
"data": {
"reference": "WG2611096D4HQE52FMY9KW",
"status": "success",
"display_text": null,
"gateway_response": "Approved",
"retry_allowed": false
}
}