Node Library

Paga-Connect

Paga-connect is a NodeJS module that helps you make API calls when processing Paga Transactions.

1. Create Paga Business Account

You need to create a Paga business account

2. Installation

Use the package manager npm to install paga-connect.

npm install paga-connect

3. Usage

To use Paga-connect, you would need to import it

const PagaConnect = require('paga-connect')

To Initialize the module, you use a builder to set all required values

let pagaConnectClient = PagaConnect.Builder()
    .setClientId("<Paga_Client_ID>")
    .setSecret("<Paga_Client_Secret>")
    .setRedirectUri("<Your_Callback_URL>")
    .setScope("USER_DEPOSIT_FROM_CARD+MERCHANT_PAYMENT+USER_DETAILS_REQUEST")
    .setUserData("FIRST_NAME+LAST_NAME+USERNAME+EMAIL+ACCOUNT_BALANCE")
    .setIsTest(true)
    .build();

As shown above, you set the client id and secret key given to you by Paga, then set your redirect URL, scope, and User data are arrays of strings and are required to inform Paga-connect which data and operations you would need and initiate for the user.

4. Paga Connect Functions

Authorisation Code

To obtain your authorisation code, click here

Merchant Payments

This is the operation executed to make a payment to you on behalf of the customer. To make use of this function, call the getAccessToken in PagaConnectClient which will return a JSON with the access token which will be used to complete payment.

To get Access tokens, Use the authorization code gotten from the call to the backend :

const getAccessToken = pagaConnectClient.getAccessToken(authorizationCode)
		.then(function(res)){
          const{result} = res;
          console.log(result}
      })
     .catch(function(error)) {
            console.log(error);
       })

Access Token is used in making merchant payment like this:

const accessToken = getAccessToken();
pagaConnectClient.merchantPayment(accessToken,referenceNumber,amount,merchantCustomerReference,merchantProductCode,currency)
	.then(function(res) {
	console.log(res);
}).catch(function(error) {
	console.log(error);
})

Money Transfer

This operation allows you to credit a user's Paga account. To make use of this function, call the moneyTransfer inside the ConnectClient which will return a JSON.

const accessToken = getAccessToken();
pagaConnectClient.moneyTransfer(accessToken,referenceNumber, amount,skipMessaging,recipientCredential)                 		 
		.then(function(res) {
		console.log(res);
}).catch(function(error) {
	console.log(error);
})

Get User Details

This operation allows the client to get the user's personal details. The data requested is included in the authentication and authorization request in the data parameter. Additionally, the scope parameter must contain the USER_DETAILS_REQUEST option. To make use of this function, call the getUserDetails inside the ConnectClient which will return a JSON with user details.

const accessToken = getAccessToken();
await pagaConnectClient.getUserDetails(accessToken)
		.then(function(res) {
		console.log(res);
}).catch(function(error) {
	console.log(error);
})

What’s Next