Skip to main content

Pay-Fi Sdk

Learn how to use Pay-Fi SDK Quick.

Getting Started

BASE URL

https://api.payfi.ng/

SDK URL

https://payfi-sdk-js.s3.amazonaws.com/payfi.js

Parameters Table

The Table Below is states the parameters and how to use them

ParamRequiredDescription
apiKeyYESPublic Key attached to your account
amountYESAmount in Kobo
referenceYESA unique transaction reference
callbackNOFunction that runs when payment is successful
onCloseNOFunction called if the customer closes the payment window

Step 1

First initialize the sdk as shown below

      const payfi = new Payfi({
apiKey: 'pk_ce082ddd-c15f-',
callbackUrl: "http://test.com",
callback: reference => {
document.getElementById("btn").removeAttribute("disabled")
console.log('callback called', reference);
},
onClose: () => {
document.getElementById("btn").removeAttribute("disabled")
console.log('modal close')
}
});

Step 2

Initiate payment process passing the amount and reference.

   payfi.pay({ amount, reference: `${Date.now()}` })

RE-QUERY

https://api.payfi.ng/v1/merchant/purchase/verify-by-reference

HEADER

  {
"payfi-sec-key":"secret key"
}

BODY

  {
"reference":"testing-now-igho"
}

Example Implementation

<script src="https://payfi-sdk-js.s3.amazonaws.com/payfi.js"></script>
<script type="text/javascript">
let amount;
const buttonElement = document.getElementById("btn");
const handleInputChange = e => {
amount = document.getElementById("amount").value;
}
const handleFormSubmit = () => {
payfi.pay({ amount, reference: `${Date.now()}` })
}
const payfi = new Payfi(
{
apiKey: 'pk_ce082ddd-c15f',
callbackUrl: "http://test.com",
callback: reference => {
console.log('callback called', reference);
},
onClose: () => {
console.log('modal close')
}
});
</script>

SETTING UP WEBHOOK

After every successful transaction, payfi will notify you via a webhook call, to set up your webhook you need to add this on the merchant portal https://merchant.payfi.ng

Payfi will call your webhook with this request:

 {
"event": "payfi.events.payment",
"status": "approved",
"message": "string",
"txRef": "42_1639832966"
}

HEADER

  {
"payfi-secret-key":"your secret key",
}

Please check the header for this secret key before offering value