faaiz-testing v1.0.1
Installation
Use npm package manager to install foree-checkout
npm i foree-checkoutUsage
Import the installed npm package (i.e. foree-checkout) into your project (angular, react or any JavaScript framework)
import initiateCheckout,getForeeCheckoutURL from ‘foree-checkout’;In case of angular, include in ngModule
Add EventListner or HostListener in you app.js or where you call initiateCheckout() function
For Angular
@HostListener('window:message', ['$event'])
onMessage(e) {
let URL=getForeeCheckoutURL();
if(e.origin !== URL) return ;
console.log(e)
}For React
window.addEventListener("window:message", ['$event']);
function onMessage(e) {
let URL=getForeeCheckoutURL();
if(e.origin !== URL) return ;
console.log(e)
}Call initiateCheckout() function and sends two arguments data, a dictionary that contains the payload, and test_mode a boolean where true means Test environment or false means Live environment.
var data = {
'key': '<API Key>',
'amount': '<Amount>',
'is_generated': <0/1>,
'reference_number': '<Reference Number>',
'customer_email_address': '<Customer Email Address>',
'customer_phone_number': '<Customer Phone Number>',
'consumer_name': '<Customer Name>'
}
initiateCheckout(data, false);is_generated takes 0 or 1 as the possible values. Pass 1 in case the bill/invoice is already generated and no new bill/invoice to be made with the given data. 0 in case a new bill/invoice is to be created with the given data
In case of payment success or failure, response is received in onMessage event in EventListner or HostListener with the data in the following format
Success data
{
bill_status: "paid"
initiator: "Foree Bill"
instrument_institution: "ABC Bank"
instrument_number: "01201234111222"
instrument_type: "bank_account"
message: "Your payment has been processed successfully"
paid_amount: 125.00
payment_channel: "Internet Banking"
reference_number: "50"
status: 1
transaction_date_time: "2021-01-20 18:32:52"
transaction_ref_id: "1611149880942"
}Failure data
{
message: "Your payment could not be processed",
reference_number: "50",
status: "2"
}