pockytsdk
v1.0.8
Published
pockytsdk is a JSSDK that allows developers to integrate with the Pockyt platform.
Downloads
3
Readme
pockytsdk
pockytsdk is a JSSDK that allows developers to integrate with the Pockyt platform.
Table of Contents
Documentation
For a in-depth explaination of the endpoints please refer to: https://docs.pockyt.io/
Usage
const pockytSDK = require("pockytsdk");
const PockytServices = pockytSDK.PockytServices;
// example of InStorePayments
const apiToken = "your_api_token_here"
const baseURL = "https://the_base_url_here.com"
const InstorePayments = new PockytServices.InstorePayments(baseURL, apiToken);
// Refer to the documentation for json parameters
const jsonData = {
"merchantNo": "200043",
"storeNo": "300014",
"amount": "13",
"currency": "USD",
"settleCurrency": "USD",
"reference": "test202001011206",
"verifySign": "c29c8240bf99510d4d53a0ca36f9c135"
}
InstorePayments.createNewTransaction(jsonData)
.then(res => console.log(res))
.catch(err => console.error(err));
Classes and Functions
All functions are apart of the PockytServices variables. For an example of how to call the classes and functions, please refer to the example above where we call the the InStorePayments class and use the createNewTransaction function.
ApiClient
const axios = require('axios');
const crypto = require('crypto');
// Handles all the logic for making requests to the API
// All classes should extend this class for requests
// If you don't include a verifySign hash in the data object, one will be generated for you based on that data object
class ApiClient {
constructor(baseUrl, apiToken) {
this.baseUrl = baseUrl;
this.apiToken = apiToken;
}
async getVerifySign(data) {
const sortedParams = Object.keys(data).sort().map(key => `${key}=${data[key]}`).join('&');
const apiTokenMD5Hash = crypto.createHash('md5').update(this.apiToken).digest('hex');
const finalString = `${sortedParams}&${apiTokenMD5Hash}`;
return crypto.createHash('md5').update(finalString).digest('hex');
}
async handleData(data) {
if (data){
return {
...data,
...(data.verifySign === undefined ? { verifySign: await this.getVerifySign(data) } : {})
}
}
return {}
}
async apiRequest(method, endpoint, data) {
var options = {}
try{
const url = `${this.baseUrl}/${endpoint}`;
options = {
method: method,
url: url,
data: await this.handleData(data)
};
const res = await axios(options)
return res.data;
}catch(err){
throw err;
}
}
}
module.exports = { ApiClient };
The ApiClient class is the parent class of all subsequent classes. This contains the logic for making the actual requests. You can also directly call this class for custom requests that aren't explicitly handled by the other child classes.
Some key features to note are:
- The verify sign hash is calculated for you
- If you specify a verify sign entry in your JSON data the class will use the provided verify sign instead of calculating one
- If you provide an empty data object, the request body will remain empty. No verify sign will be generated.
InStorePayments
class InstorePayments extends ApiClient {
constructor(baseUrl, apiToken) {
super(baseUrl, apiToken);
}
async createQRCode(data) {
return await this.apiRequest("POST", "app-instore/v3/create-trans-qrcode", data);
}
async createNewTransaction(data){
return await this.apiRequest("POST", "app-instore/v3/add", data);
}
async processPayment(data){
return await this.apiRequest("POST", "app-instore/v3/prepay", data);
}
}
Extends from ApiClient and handles all in-store payment endpoints.
Online payments
class OnlinePayments extends ApiClient {
constructor(baseUrl, apiToken) {
super(baseUrl,apiToken);
}
async securePay(data){
return await this.apiRequest("POST", "online/v3/secure-pay", data);
}
async process(data){
return await this.apiRequest("POST", "creditpay/v3/process", data);
}
async prepay(data){
return await this.apiRequest("POST", "micropay/v3/prepay", data);
}
async registerCustomer (data){
return await this.apiRequest("POST", "v1/customers/create", data);
}
async retrieveCustomerInfo (data){
return await this.apiRequest("POST", "v1/customers/retrieve", data);
}
async updateCustomerInfo (data){
return await this.apiRequest("POST", "v1/customers/update", data);
}
}
Extends from ApiClient and handles all online payment endpoints.
Payouts
class Payouts extends ApiClient {
constructor(baseUrl, apiToken) {
super(baseUrl,apiToken);
}
async registerPayee(data){
return await this.apiRequest("POST", "v3/payee/register", data);
}
async deletePayee(data){
return await this.apiRequest("POST", "v3/payee/delete", data);
}
async retrievePayee(data){
return await this.apiRequest("POST", "v3/payee/retrieve", data);
}
async retrievePayeeBalance(data){
return await this.apiRequest("POST", "v3/payouts/balance", data);
}
async retrievePayeeFundingAccounts(data){
return await this.apiRequest("POST", "v3/payee/payout-accounts", data);
}
async updatePayee(data){
return await this.apiRequest("POST", "v3/payee/update", data);
}
async addPayeePayoutMethod(data){
return await this.apiRequest("POST", "v3/payee/account/create/bank-account", data);
}
async deletePayeePayoutMethod(data){
return await this.apiRequest("POST", "v3/payee/account/delete", data);
}
async transferPayout(data){
return await this.apiRequest("POST", "v3/payouts/pay", data);
}
async inquirePayoutDetails(data){
return await this.apiRequest("POST", "v3/payouts/inquiry", data);
}
async foreignExchangeRate(data){
return await this.apiRequest("POST", "v3/payouts/fxrate", data);
}
async internationalTransferMethods(data){
return await this.apiRequest("POST", "v3/payee/account/configurations", data);
}
}
Extends from ApiClient and handles all payout payment endpoints.
Disputes
class Dispute extends ApiClient {
constructor(baseUrl, apiToken) {
super(baseUrl,apiToken);
}
async refund(data){
return await this.apiRequest("POST", "app-data-search/v3/refund", data);
}
async cancel(data){
return await this.apiRequest("POST", "app-data-search/v3/cancel", data);
}
}
Extends from ApiClient and handles all disputes (refunds/cancelations) endpoints.
Reporting
const ApiClient = require("./apiClient").ApiClient;
// For a detailed explanation on the endpoints refer to: https://docs.pockyt.io/reference/refund-and-query-apis
class Reporting extends ApiClient {
constructor(baseUrl, apiToken) {
super(baseUrl,apiToken);
}
async querySpecificTransactions(data){
return await this.apiRequest("POST", "app-data-search/v3/tran-query", data);
}
async addNotesToTransaction(data){
return await this.apiRequest("POST", "app-data-search/v3/notes/add", data);
}
async listBulkTransactions(data){
return await this.apiRequest("POST", "app-data-search/v3/transaction-list", data);
}
async settlementStatus(data){
return await this.apiRequest("POST", "app-data-search/v3/withdrawal-list", data);
}
}
module.exports = { Reporting };
Extends from ApiClient and handles all reporting endpoints.
Transactions
const ApiClient = require("./apiClient").ApiClient;
class Transactions extends ApiClient {
constructor(baseUrl, apiToken) {
super(baseUrl, apiToken);
}
async getTranCurrencies() {
return await this.apiRequest("GET", "api/transaction/get-tran-currencies", {});
}
async getSettleCurrencies() {
return await this.apiRequest("GET", "api/transaction/get-settle-currencies", {});
}
async getAllPaymentMethods() {
return await this.apiRequest("GET", "api/transaction/get-all-payment-methods", {});
}
}
module.exports = { Transactions };
Extends from ApiClient and provides the different currency options. The request body for these endpoints will be empty. It does not take in JSON data and does not require an api token. No verify sign token will be generated either.