Before you start, you need an Afara account and your public key. Follow Create your account and Get your API keys first. Use your test public key (it starts with
TPK_) until you are ready to go live.How a payment works
1
Your customer clicks Pay
Your page collects the customer’s email address and the amount, then opens the Afara widget.
2
They choose how to pay
The widget shows the payment methods available to you, such as card, bank transfer, USSD and QR.
3
The widget tells your page it worked
When the payment succeeds, the widget closes and your page receives a payment reference.
4
You confirm the payment
Your server checks the reference with Afara before delivering the order. See Verify a payment.
Add the widget
Paste the code below into your page and replace the two things marked in the comments. It works on any website, including WordPress, Wix and plain HTML sites that let you add custom code.Amounts are in kobo. NGN 5,000 is
500000. That is why the examples multiply the Naira amount by 100.Widget options
string
required
Your public key. Use
TPK_... to test and PK_... for live payments.string
required
The customer’s email address.
integer
required
The amount to charge, in kobo. Must be a whole number.
string
default:"NGN"
The currency code. Defaults to
NGN.string
Your own unique reference for this payment, for example an order number. Use a new one for every payment.
object
Extra details you want stored with the payment, for example a customer name or an order ID.
function
Runs when the payment succeeds. Receives a
response object that includes the payment reference.function
Runs when the customer closes the widget.
Test it
1
Open your page
Load the page, enter any email address and a small amount, and click Pay now.
2
Pay with a test card
Use a test card. No real money moves in test mode.
3
Check the dashboard
Open Transactions in the merchant portal. Your test payment appears there.
If something is not working
Nothing happens when I click Pay
Nothing happens when I click Pay
Make sure the script tag that loads the widget is on the page before the code that calls it. Open your browser’s developer tools and look for red errors in the Console.
I see an error about the key or email
I see an error about the key or email
The widget needs a public key and a valid email address. Check that the key is copied in full and starts with
TPK_ or PK_.The amount is wrong
The amount is wrong
The amount must be a whole number in kobo. If a customer should pay NGN 2,500, send
250000.AfaraPayPop is not defined
AfaraPayPop is not defined
The widget script has not loaded. Check the script address and that your site allows scripts from
sdk.afarapartners.com. The name is case sensitive: AfaraPayPop.Verify a payment
Confirm the payment on your server before you deliver the order.
Test cards
Card numbers to try every outcome.