Skip to content
Wire Ghdocs

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.

OptionHow it worksBest for
PopupThe checkout opens over your page and closes when the customer pays.Websites that want customers to stay on the page
RedirectYou 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 APIYou build the payment screens and charge from your server.Apps that need full control of the experience

The popup adds the Wire Gh checkout to your page with one script. It needs your public key, never your secret key.

<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>

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);
    }
  });
});
Always verify on your server

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.

newTransaction options

keyStringrequired
Your public key, starting with wg_pk_test_ or wg_pk_live_.
emailStringrequired
Customer's email address.
amountIntegerrequired
Amount in pesewas.
currencyStringoptional
Only GHS. Defaults to GHS.
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_money and wiregh_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.

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');
  }
});

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.

  1. Initialize the transactionCall Initialize Transaction with the email, amount and an optional callback_url.
  2. Redirect to the checkoutSend the customer to data.authorization_url. The link works for 30 minutes.
  3. Handle the callbackAfter a successful payment we send the customer to your callback URL with ?trxref=REFERENCE&reference=REFERENCE added. Verify that reference on your server, then show the result.
Start a payment and redirect
// 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);
});

If you do not send callback_url, we use the callback URL saved on your API & Sandbox page.

Cancel button

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.

  1. 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.
  2. They enter the code and their wallet PINBoth are checked on the Wire Gh checkout. Your website and your servers never see the PIN.
  3. The payment completes at onceThere is no prompt to wait for. You get a charge.success webhook 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.

Checkout and popup only

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.