Accept Payments
Collect Mobile Money payments with the Wire Gh checkout, either in a popup on your page or on our hosted payment page.
Both options use the same secure Wire Gh checkout. Your customer pays with Mobile Money, approving a prompt on their phone, or from their Wire Gh wallet. You never handle their payment details.
| Option | How it works | Best for |
|---|---|---|
| Popup | The checkout opens over your page and closes when the customer pays. | Websites that want customers to stay on the page |
| Redirect | You send the customer to the checkout page and we send them back to you. | The simplest server side setup, and apps that open a browser |
| Charge API | You build the payment screens and charge from your server. | Apps that need full control of the experience |
Popup
The popup adds the Wire Gh checkout to your page with one script. It needs your public key, never your secret key.
Add the script and a form
<form id="paymentForm">
<input type="email" id="email" placeholder="Email address" required>
<input type="number" id="amount" placeholder="Amount (GHS)" required>
<button type="submit">Pay now</button>
</form>
<script src="https://checkout.wiregh.com/v1/inline.js"></script>Open the popup
When the customer submits the form, create a WireGhPop and call newTransaction:
const form = document.getElementById('paymentForm');
form.addEventListener('submit', function (event) {
event.preventDefault();
const pop = new WireGhPop();
pop.newTransaction({
key: 'wg_pk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // your PUBLIC key
email: document.getElementById('email').value,
amount: Math.round(document.getElementById('amount').value * 100), // in pesewas
metadata: { order_id: '1042' },
onSuccess: function (transaction) {
// Send the reference to your server and verify it there before giving value
window.location.href = '/order/confirm?reference=' + transaction.reference;
},
onCancel: function () {
alert('Payment window closed.');
},
onError: function (error) {
console.log(error.message);
}
});
});onSuccess runs in the customer's browser, and anything in a browser can be changed. Before you deliver anything, send the reference to your server and verify the transaction with your secret key.
Options
newTransaction options
keyStringrequired- Your public key, starting with
wg_pk_test_orwg_pk_live_. emailStringrequired- Customer's email address.
amountIntegerrequired- Amount in pesewas.
currencyStringoptional- Only
GHS. Defaults toGHS. referenceStringoptional- Your own unique reference. We create one if you leave it out.
firstNameStringoptional- Customer's first name.
lastNameStringoptional- Customer's last name.
phoneStringoptional- Customer's phone number.
metadataObjectoptional- Extra information to keep with the transaction.
channelsArrayoptional- Channels to offer:
mobile_moneyandwiregh_wallet. Leave it out to offer both. onSuccessFunctionoptional- Called with
{ reference, status, transaction }when the payment succeeds. onCancelFunctionoptional- Called when the customer closes the popup without paying.
onLoadFunctionoptional- Called when the checkout has loaded.
onErrorFunctionoptional- Called with
{ message }if the checkout cannot start, for example with a wrong key.
Set the amount on your server
For the strongest setup, start the transaction on your server with Initialize Transaction, then open the popup with the access_code you got back. The amount is then fixed by your server and cannot be changed in the browser.
// accessCode comes from POST /transaction/initialize on your server
const pop = new WireGhPop();
pop.resumeTransaction(accessCode, {
onSuccess: function (transaction) {
window.location.href = '/order/confirm?reference=' + transaction.reference;
},
onCancel: function () {
console.log('Customer closed the popup');
}
});Classic setup
If you prefer a single setup call, this form also works:
const handler = WireGhPop.setup({
key: 'wg_pk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
email: 'customer@email.com',
amount: 20000,
ref: 'ORDER_1042',
callback: function (response) {
window.location.href = '/order/confirm?reference=' + response.reference;
},
onClose: function () {
console.log('Window closed');
}
});
handler.openIframe();Redirect
With the redirect option, your server starts the payment and sends the customer to our payment page. You do not need any JavaScript.
- Initialize the transactionCall Initialize Transaction with the email, amount and an optional
callback_url. - Redirect to the checkoutSend the customer to
data.authorization_url. The link works for 30 minutes. - Handle the callbackAfter a successful payment we send the customer to your callback URL with
?trxref=REFERENCE&reference=REFERENCEadded. Verify that reference on your server, then show the result.
// Express route: start the payment and redirect the customer
app.post('/pay', async (req, res) => {
const response = await fetch('https://api.wiregh.com/transaction/initialize', {
method: 'POST',
headers: {
Authorization: 'Bearer ' + process.env.WIREGH_SECRET_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: req.body.email,
amount: 20000,
callback_url: 'https://yourshop.com/order/confirm'
})
});
const result = await response.json();
if (!result.status) return res.status(400).send(result.message);
res.redirect(result.data.authorization_url);
});<?php
// pay.php: start the payment and redirect the customer
$ch = curl_init('https://api.wiregh.com/transaction/initialize');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode([
'email' => $_POST['email'],
'amount' => 20000,
'callback_url' => 'https://yourshop.com/order/confirm.php',
]),
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('WIREGH_SECRET_KEY'),
'Content-Type: application/json',
],
]);
$result = json_decode(curl_exec($ch), true);
curl_close($ch);
if (empty($result['status'])) {
exit($result['message'] ?? 'Could not start payment');
}
header('Location: ' . $result['data']['authorization_url']);
exit;If you do not send callback_url, we use the callback URL saved on your API & Sandbox page.
The checkout has a cancel link. To send customers somewhere specific when they cancel, add "cancel_action": "https://yourshop.com/cart" to metadata.
Wire Gh wallet payments
Customers who have a Wire Gh account can pay from their wallet balance on the checkout and the popup. You do not need to change any code: the Wire Gh Wallet tab appears next to Mobile Money automatically.
- The customer enters their Wire Gh phone numberWe send a one time code by SMS to the phone on their Wire Gh account. The message names your business and the amount.
- They enter the code and their wallet PINBoth are checked on the Wire Gh checkout. Your website and your servers never see the PIN.
- The payment completes at onceThere is no prompt to wait for. You get a
charge.successwebhook and the popup or redirect finishes as usual.
When you verify, a wallet payment has channel set to wiregh_wallet and authorization.bank set to Wire Gh Wallet. Refunds go straight back to the customer's wallet.
Wallet payments are not available on the Charge API, so that a customer's wallet PIN is only ever entered on a Wire Gh page. To offer only one method, send channels, for example ["mobile_money"].
After the payment
Whichever option you use, finish the same way:
- Verify the transaction on your server before you give value.
- Set up webhooks so you still hear about payments when a customer closes their browser before returning to you.