diff --git a/.changeset/new-flies-design.md b/.changeset/new-flies-design.md new file mode 100644 index 0000000..a58eea8 --- /dev/null +++ b/.changeset/new-flies-design.md @@ -0,0 +1,5 @@ +--- +"marupay": patch +--- + +rename `request` to `purchase` for better understanding diff --git a/README.md b/README.md index bd901d9..2a38027 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ app.get('/purchase', async (req, res) => { const handler = getPaymentHandler(chosenHandler)(paymentConfig[chosenHandler]!); // Make a purchase request - const paymentInfo = await handler.request({ + const paymentInfo = await handler.purchase({ accountNumber: "+2526512312341", // must start with `+` followed by country code amount: 500, currency: Currency.SLSH, @@ -99,7 +99,7 @@ app.listen(port, () => { ### Responses -The `credit` and `request` methods both returns a `PaymentInfo` object. It'll return these details: +The `credit` and `purchase` methods both returns a `PaymentInfo` object. It'll return these details: - **`transactionId`:** This identifier is obtained from the vendor's transaction ID. It uniquely identifies the transaction in the vendor's system. diff --git a/apps/docs/pages/guide/credit.mdx b/apps/docs/pages/guide/credit.mdx index b234a18..0104656 100644 --- a/apps/docs/pages/guide/credit.mdx +++ b/apps/docs/pages/guide/credit.mdx @@ -7,12 +7,12 @@ Once you have configured the payment handlers, you can utilize this configuratio Here's a quick example of how you can use the configuration when making a credit request: ```typescript -app.get('/purchase', async (req, res) => { +app.get('/credit', async (req, res) => { try { const chosenHandler: HandlerName = 'edahab'; const handler = getPaymentHandler(chosenHandler)(paymentConfig[chosenHandler]!); - const paymentInfo = await handler.request({ + const paymentInfo = await handler.credit({ accountNumber: "+2526512312341", // must start with `+` followed by country code amount: 500, currency: Currency.SLSH, diff --git a/apps/docs/pages/guide/purchase.mdx b/apps/docs/pages/guide/purchase.mdx index 80eeb78..fbffa63 100644 --- a/apps/docs/pages/guide/purchase.mdx +++ b/apps/docs/pages/guide/purchase.mdx @@ -1,15 +1,15 @@ -# Making Our First Request -*Request is sending a C2B or charging a customer.* +# Making Our First Purchase +*Purchase is sending a C2B or charging a customer.* -Now, let's add a route for making a credit request: +Now, let's add a route for making a purchase request: ```typescript -app.get('/credit', async (req, res) => { +app.get('/purchase', async (req, res) => { try { const chosenHandler: HandlerName = 'edahab'; const handler = getPaymentHandler(chosenHandler)(paymentConfig[chosenHandler]!); - const paymentInfo = await handler.request({ + const paymentInfo = await handler.purchase({ accountNumber: "+2526512312341", // must start with `+` followed by country code amount: 500, currency: Currency.SLSH, diff --git a/examples/express-ts/index.ts b/examples/express-ts/index.ts index aac182e..1ca9983 100644 --- a/examples/express-ts/index.ts +++ b/examples/express-ts/index.ts @@ -34,7 +34,7 @@ app.get('/purchase', async (req, res) => { const handler = getPaymentHandler(chosenHandler)(paymentConfig[chosenHandler]!); // Make a purchase request - const paymentInfo = await handler.request({ + const paymentInfo = await handler.purchase({ accountNumber: "+2526512312341", // must start with `+` followed by country code amount: 500, currency: Currency.SLSH, diff --git a/packages/marupay/README.md b/packages/marupay/README.md index a09125a..1dc1785 100644 --- a/packages/marupay/README.md +++ b/packages/marupay/README.md @@ -58,7 +58,7 @@ app.get('/purchase', async (req, res) => { const handler = getPaymentHandler(chosenHandler)(paymentConfig[chosenHandler]!); // Make a purchase request - const paymentInfo = await handler.request({ + const paymentInfo = await handler.purchase({ accountNumber: "+2526512312341", // must start with `+` followed by country code amount: 500, currency: Currency.SLSH, @@ -98,7 +98,7 @@ app.listen(port, () => { ``` ### Responses -The `credit` and `request` methods both returns a `PaymentInfo` object. It'll return these details: +The `credit` and `purchase` methods both returns a `PaymentInfo` object. It'll return these details: - **`transactionId`:** This identifier is obtained from the vendor's transaction ID. It uniquely identifies the transaction in the vendor's system. diff --git a/packages/marupay/src/handler.ts b/packages/marupay/src/handler.ts index c86e5a8..b2379c5 100644 --- a/packages/marupay/src/handler.ts +++ b/packages/marupay/src/handler.ts @@ -12,58 +12,71 @@ interface IPaymentInfo { export const baseConfigSchema = z.object({}); export type BaseConfigOptions = z.infer; -export const baseRequestSchema = z.object({ +export const basePurchaseSchema = z.object({ accountNumber: z.string().startsWith('+'), amount: z.number(), currency: z.nativeEnum(Currency), description: z.string().optional(), }); -export type BaseRequestOptions = z.infer; +export type BasePurchaseOptions = z.infer; type HandlerParams< HandlerConfigSchema extends ZodSchema, - HandlerRequestSchema extends ZodSchema, + HandlerPurchaseSchema extends ZodSchema, HandlerCreditSchema extends ZodSchema, IConfig extends z.infer & BaseConfigOptions, - IRequest extends z.infer & BaseRequestOptions, - ICredit extends z.infer & BaseRequestOptions, + IPurchase extends z.infer & BasePurchaseOptions, + ICredit extends z.infer & BasePurchaseOptions, DefaultConfig extends Partial > = { schema: { config: HandlerConfigSchema; - request: HandlerRequestSchema; + purchase: HandlerPurchaseSchema; credit: HandlerCreditSchema; }; defaultConfig: DefaultConfig; - request: (arg: { ctx: IConfig; options: IRequest }) => Promise, + purchase: (arg: { ctx: IConfig; options: IPurchase }) => Promise, credit: (arg: { ctx: IConfig; options: ICredit }) => Promise }; export const defineHandler = < HandlerConfigSchema extends ZodSchema, - HandlerRequestSchema extends ZodSchema, + HandlerPurchaseSchema extends ZodSchema, HandlerCreditSchema extends ZodSchema, IConfig extends z.infer & BaseConfigOptions, - IRequest extends z.infer & BaseRequestOptions, - ICredit extends z.infer & BaseRequestOptions, + IPurchase extends z.infer & BasePurchaseOptions, + ICredit extends z.infer & BasePurchaseOptions, DefaultConfig extends Partial ->({ schema, defaultConfig, request, credit }: HandlerParams) => { +>({ + schema, + defaultConfig, + purchase, + credit +}: HandlerParams< + HandlerConfigSchema, + HandlerPurchaseSchema, + HandlerCreditSchema, + IConfig, + IPurchase, + ICredit, + DefaultConfig +>) => { return (config: Omit & Partial) => { console.log(`config: ${JSON.stringify(config)}`); const ctx = safeParse(schema.config, { ...defaultConfig, ...config }) as IConfig; console.log(`parsed config: ${JSON.stringify(config)}`); - const requestPayment = async (options: Parameters['0']['options']) => { - options = safeParse(baseRequestSchema, options) as IRequest; - const paymentInfo = await request({ ctx, options }); + const purchasePayment = async (options: Parameters['0']['options']) => { + options = safeParse(basePurchaseSchema, options) as IPurchase; + const paymentInfo = await purchase({ ctx, options }); return { ...paymentInfo, }; }; const creditPayment = async (options: Parameters['0']['options']) => { - options = safeParse(baseRequestSchema, options) as ICredit; + options = safeParse(basePurchaseSchema, options) as ICredit; console.log(`credit options: ${JSON.stringify(options)}`); const creditInfo = await credit({ ctx, options }); return { @@ -72,7 +85,7 @@ export const defineHandler = < }; return { - request: requestPayment, + purchase: purchasePayment, credit: creditPayment }; }; diff --git a/packages/marupay/src/handlers/constants.ts b/packages/marupay/src/handlers/constants.ts index bab868f..f27a7c9 100644 --- a/packages/marupay/src/handlers/constants.ts +++ b/packages/marupay/src/handlers/constants.ts @@ -2,4 +2,4 @@ import { z } from "zod"; export const SO_ACCOUNT_NUMBER = '+252'; -export const soRequestNumber = z.string().startsWith(SO_ACCOUNT_NUMBER); +export const soPurchaseNumber = z.string().startsWith(SO_ACCOUNT_NUMBER); diff --git a/packages/marupay/src/handlers/edahab/api.ts b/packages/marupay/src/handlers/edahab/api.ts index bd9944c..8a33c39 100644 --- a/packages/marupay/src/handlers/edahab/api.ts +++ b/packages/marupay/src/handlers/edahab/api.ts @@ -1,4 +1,4 @@ -export interface RequestPaymentReq { +export interface PurchasePaymentReq { apiKey: string; edahabNumber: string; amount: number; @@ -7,7 +7,7 @@ export interface RequestPaymentReq { ReturnUrl?: string; } -export interface RequestPaymentRes { +export interface PurchasePaymentRes { InvoiceStatus: string; TransactionId: string; InvoiceId: number; @@ -33,7 +33,7 @@ export interface CreditPaymentRes { } -export type RequestData = { +export type PurchaseData = { apiKey: string, currency: string, description?: string, @@ -41,5 +41,5 @@ export type RequestData = { agentCode?: string, } -export type RequestPaymentData = RequestData & { edahabNumber: string } -export type CreditPaymentData = RequestData & { phoneNumber: string, transactionAmount: number, transactionId: string } \ No newline at end of file +export type PurchasePaymentData = PurchaseData & { edahabNumber: string } +export type CreditPaymentData = PurchaseData & { phoneNumber: string, transactionAmount: number, transactionId: string } \ No newline at end of file diff --git a/packages/marupay/src/handlers/edahab/edahab.ts b/packages/marupay/src/handlers/edahab/edahab.ts index 30eeed6..d999416 100644 --- a/packages/marupay/src/handlers/edahab/edahab.ts +++ b/packages/marupay/src/handlers/edahab/edahab.ts @@ -6,13 +6,57 @@ import * as API from './api'; import { hashSecretKey } from './hash'; import { PaymentCtx, PaymentOptions } from '../types'; import { prepareRequest } from './prepareRequest'; -import { SO_ACCOUNT_NUMBER, soRequestNumber } from '../constants' +import { SO_ACCOUNT_NUMBER, soPurchaseNumber } from '../constants' import { safeParse } from '../../utils/safeParser'; -const edahabRequest = z.object({ - accountNumber: soRequestNumber, +const edahabPurchase = z.object({ + accountNumber: soPurchaseNumber, }); +const requestFn = async (url: string, data: any, referenceId: string) => { + const response = await axios.post(url, data); + const { TransactionId, InvoiceStatus, StatusCode, StatusDescription } = response.data; + const responseCode = `${StatusCode}`; + if (responseCode !== '0') { + console.log(`${StatusDescription}`); + throw responseCode; + } + return { + transactionId: TransactionId, + paymentStatus: InvoiceStatus, + referenceId, + raw: response.data, + }; +}; + +const creditFn = async (url: string, data: any, referenceId: string) => { + const response = await axios.post(url, data).catch((e) => { + return { + data: { + PhoneNumber: data.phoneNumber, + TransactionId: referenceId, + TransactionStatus: 'error', + TransactionMesage: e.message, + } as API.CreditPaymentRes, + }; + }); + + const { TransactionId, TransactionMesage, TransactionStatus } = response.data; + const responseCode = `${TransactionStatus}`; + + if (responseCode === 'error') { + console.log(`credit error: ${TransactionMesage}`); + throw TransactionMesage; + } + + return { + transactionId: TransactionId, + paymentStatus: TransactionStatus, + referenceId: generateUuid(), + raw: response.data, + }; +}; + export const createEdahabHandler = defineHandler({ schema: { config: z.object({ @@ -25,8 +69,8 @@ export const createEdahabHandler = defineHandler({ creditUrl: z.string(), }), }), - request: edahabRequest, - credit: edahabRequest, + purchase: edahabPurchase, + credit: edahabPurchase, }, defaultConfig: { links: { @@ -35,28 +79,13 @@ export const createEdahabHandler = defineHandler({ creditUrl: '/api/agentPayment?hash=', }, }, - request: async ({ ctx, options }: { ctx: PaymentCtx, options: PaymentOptions }) => { - const parsedData = safeParse(edahabRequest.pick({ accountNumber: true }), { accountNumber: options.accountNumber }); + purchase: async ({ ctx, options }: { ctx: PaymentCtx, options: PaymentOptions }) => { + const parsedData = safeParse(edahabPurchase.pick({ accountNumber: true }), { accountNumber: options.accountNumber }); const accountNumber = parsedData.accountNumber.replace(SO_ACCOUNT_NUMBER, ''); - const requestFn = async (url: string, data: API.RequestPaymentData, referenceId: string) => { - const response = await axios.post(url, data); - const { TransactionId, InvoiceStatus, StatusCode, StatusDescription } = response.data; - const responseCode = `${StatusCode}`; - if (responseCode !== '0') { - console.log(`${StatusDescription}`); - throw responseCode; - } - return { - transactionId: TransactionId, - paymentStatus: InvoiceStatus, - referenceId, - raw: response.data, - }; - }; const { links } = ctx; const referenceId = generateUuid(); - const requestData = prepareRequest('request', { ...options, accountNumber }, ctx, referenceId) as API.RequestPaymentData; + const requestData = prepareRequest('request', { ...options, accountNumber }, ctx, referenceId) as API.PurchasePaymentData; const hashCode = hashSecretKey(requestData, ctx.secretKey); const requestUrl = `${links.baseUrl + links.requestUrl + hashCode}`; @@ -64,35 +93,8 @@ export const createEdahabHandler = defineHandler({ return await requestFn(requestUrl, requestData, referenceId); }, credit: async ({ ctx, options }: { ctx: PaymentCtx, options: PaymentOptions }) => { - const parsedData = safeParse(edahabRequest.pick({ accountNumber: true }), { accountNumber: options.accountNumber }); + const parsedData = safeParse(edahabPurchase.pick({ accountNumber: true }), { accountNumber: options.accountNumber }); const accountNumber = parsedData.accountNumber.replace(SO_ACCOUNT_NUMBER, ''); - const requestFn = async (url: string, data: API.CreditPaymentData, referenceId: string) => { - const response = await axios.post(url, data).catch((e) => { - return { - data: { - PhoneNumber: data.phoneNumber, - TransactionId: referenceId, - TransactionStatus: 'error', - TransactionMesage: e.message, - } as API.CreditPaymentRes, - }; - }); - - const { TransactionId, TransactionMesage, TransactionStatus } = response.data; - const responseCode = `${TransactionStatus}`; - - if (responseCode === 'error') { - console.log(`credit error: ${TransactionMesage}`); - throw TransactionMesage; - } - - return { - transactionId: TransactionId, - paymentStatus: TransactionStatus, - referenceId: generateUuid(), - raw: response.data, - }; - }; const { links } = ctx; const referenceId = generateUuid(); const requestData = prepareRequest('credit', { ...options, accountNumber, }, ctx, referenceId) as API.CreditPaymentData; @@ -100,7 +102,7 @@ export const createEdahabHandler = defineHandler({ const hashCode = hashSecretKey(requestData, ctx.secretKey); const creditUrl = `${links.baseUrl + links.creditUrl + hashCode}`; - return await requestFn(creditUrl, requestData, referenceId); + return await creditFn(creditUrl, requestData, referenceId); }, }); diff --git a/packages/marupay/src/handlers/edahab/hash.ts b/packages/marupay/src/handlers/edahab/hash.ts index 06e9197..53d985d 100644 --- a/packages/marupay/src/handlers/edahab/hash.ts +++ b/packages/marupay/src/handlers/edahab/hash.ts @@ -1,7 +1,7 @@ import * as API from './api' import CryptoJS from 'crypto-js'; -export const hashSecretKey = (data: API.RequestPaymentData | API.CreditPaymentData, secretKey: string) => { +export const hashSecretKey = (data: API.PurchasePaymentData | API.CreditPaymentData, secretKey: string) => { const hash = JSON.stringify(data) + secretKey; return CryptoJS.SHA256(hash).toString( diff --git a/packages/marupay/src/handlers/edahab/prepareRequest.ts b/packages/marupay/src/handlers/edahab/prepareRequest.ts index b4041e1..1521915 100644 --- a/packages/marupay/src/handlers/edahab/prepareRequest.ts +++ b/packages/marupay/src/handlers/edahab/prepareRequest.ts @@ -1,8 +1,8 @@ import { PaymentCtx, PaymentOptions } from '../types'; import * as API from './api'; -export const prepareRequest = (paymentType: "request" | "credit", data: PaymentOptions, ctx: PaymentCtx, referenceId: string): API.RequestData | API.RequestPaymentData | API.CreditPaymentData => { - var requestData: API.RequestData; +export const prepareRequest = (paymentType: "request" | "credit", data: PaymentOptions, ctx: PaymentCtx, referenceId: string): API.PurchaseData | API.PurchasePaymentData | API.CreditPaymentData => { + var requestData: API.PurchaseData; if (paymentType === 'request') { requestData = { @@ -12,7 +12,7 @@ export const prepareRequest = (paymentType: "request" | "credit", data: PaymentO currency: data.currency, agentCode: ctx.merchantId, description: data.description, - } as API.RequestPaymentData; + } as API.PurchasePaymentData; } else if (paymentType === 'credit') { requestData = { apiKey: ctx.apiKey, diff --git a/packages/marupay/src/handlers/waafi/api.ts b/packages/marupay/src/handlers/waafi/api.ts index 6765f89..3616a64 100644 --- a/packages/marupay/src/handlers/waafi/api.ts +++ b/packages/marupay/src/handlers/waafi/api.ts @@ -1,4 +1,4 @@ -export type RequestPaymentReq = { +export type PurchasePaymentReq = { accountNo: string; amount: number; currency: string; @@ -14,7 +14,7 @@ export type CreditPaymentReq = { accountHolder?: string; } -export type RequestPaymentRes = { +export type PurchasePaymentRes = { schemaVersion: string; timestamp: string; requestId: string; @@ -40,32 +40,32 @@ export type ResponseParams = { txAmount: string; }; -export type RequestData = { +export type PurchaseData = { schemaVersion: '1.0'; requestId: '7102205824'; timestamp: '2022-02-04 Africa'; channelName: 'WEB'; serviceName: string; - serviceParams: RequestServiceParams; + serviceParams: PurchaseServiceParams; } -export type RequestServiceParams = { +export type PurchaseServiceParams = { merchantUid: string; apiUserId: string; apiKey: string; paymentMethod: string; browserInfo: string; - payerInfo: RequestPayerInfo; - transactionInfo: RequestTransactionInfo; + payerInfo: PurchasePayerInfo; + transactionInfo: PurchaseTransactionInfo; } -export type RequestPayerInfo = { +export type PurchasePayerInfo = { accountNo: string; accountType?: string; accountHolder?: string; } -export type RequestTransactionInfo = { +export type PurchaseTransactionInfo = { referenceId: string; invoiceId: string; amount: number; diff --git a/packages/marupay/src/handlers/waafi/prepareRequest.ts b/packages/marupay/src/handlers/waafi/prepareRequest.ts index ef3b111..1ddf454 100644 --- a/packages/marupay/src/handlers/waafi/prepareRequest.ts +++ b/packages/marupay/src/handlers/waafi/prepareRequest.ts @@ -2,8 +2,8 @@ import { PaymentCtx, PaymentOptions } from '../types'; import * as API from './api'; import { generateUuid } from '../../utils/generateUuid'; -export const prepareRequest = (paymentType: "request" | "credit", data: PaymentOptions, ctx: PaymentCtx, referenceId: string): API.RequestData => { - const serviceParams: API.RequestServiceParams = { +export const prepareRequest = (paymentType: "request" | "credit", data: PaymentOptions, ctx: PaymentCtx, referenceId: string): API.PurchaseData => { + const serviceParams: API.PurchaseServiceParams = { merchantUid: ctx.merchantId, apiUserId: ctx.secretKey, apiKey: ctx.apiKey, @@ -22,7 +22,7 @@ export const prepareRequest = (paymentType: "request" | "credit", data: PaymentO paymentMethod: 'MWALLET_ACCOUNT', }; - const requestData: API.RequestData = { + const requestData: API.PurchaseData = { serviceName: paymentType == 'request' ? 'API_PURCHASE' : 'API_CREDITACCOUNT', serviceParams, schemaVersion: '1.0', diff --git a/packages/marupay/src/handlers/waafi/waafi.ts b/packages/marupay/src/handlers/waafi/waafi.ts index e8ab995..b7313ec 100644 --- a/packages/marupay/src/handlers/waafi/waafi.ts +++ b/packages/marupay/src/handlers/waafi/waafi.ts @@ -6,10 +6,10 @@ import * as API from './api'; import { PaymentCtx, PaymentOptions } from '../types'; import { prepareRequest } from './prepareRequest'; import { safeParse } from '../../utils/safeParser'; -import { soRequestNumber } from 'handlers/constants'; +import { soPurchaseNumber } from 'handlers/constants'; -const waafiRequest = z.object({ - accountNumber: soRequestNumber, +const waafiPurchase = z.object({ + accountNumber: soPurchaseNumber, }); export const createWaafiHandler = defineHandler({ @@ -22,10 +22,10 @@ export const createWaafiHandler = defineHandler({ baseUrl: z.string(), }), }), - request: waafiRequest, + purchase: waafiPurchase, credit: z.object({ accountType: z.enum(['MERCHANT', 'CUSTOMER']).optional(), - ...waafiRequest.shape, + ...waafiPurchase.shape, }).optional(), }, defaultConfig: { @@ -33,60 +33,39 @@ export const createWaafiHandler = defineHandler({ baseUrl: 'https://api.waafipay.net/asm', }, }, - request: async ({ ctx, options }: { ctx: PaymentCtx, options: PaymentOptions }) => { - const parsedData = safeParse(waafiRequest.pick({ accountNumber: true }), { accountNumber: options.accountNumber }); + purchase: async ({ ctx, options }: { ctx: PaymentCtx, options: PaymentOptions }) => { + const parsedData = safeParse(waafiPurchase.pick({ accountNumber: true }), { accountNumber: options.accountNumber }); const accountNumber = parsedData.accountNumber.replace("+", ''); - const requestFn = async (url: string, data: API.RequestData) => { - const response = await axios.post(url, data); - const { responseCode, responseMsg, errorCode, params } = response.data; + const requestUrl = `${ctx.links.baseUrl}`; + const PurchaseData = prepareRequest('request', { ...options, accountNumber }, ctx, generateUuid()); - if (responseCode !== '2001' || params == null) { - console.log(`WAAFI: API-RES: ${responseMsg} ERROR-CODE: ${errorCode}`); - throw responseCode; - } - return { - transactionId: params.transactionId, - paymentStatus: params.state, - referenceId: params.referenceId, - raw: response.data, - }; - }; - - const referenceId = generateUuid(); - const { links } = ctx; - - const requestUrl = `${links.baseUrl}`; - const requestData = prepareRequest('request', { ...options, accountNumber }, ctx, referenceId); - - return await requestFn(requestUrl, requestData); + return await sendRequest(requestUrl, PurchaseData); }, credit: async ({ ctx, options }: { ctx: PaymentCtx, options: PaymentOptions }) => { - const parsedData = safeParse(waafiRequest.pick({ accountNumber: true }), { accountNumber: options.accountNumber }); + const parsedData = safeParse(waafiPurchase.pick({ accountNumber: true }), { accountNumber: options.accountNumber }); const accountNumber = parsedData.accountNumber.replace("+", ''); - const requestFn = async (url: string, data: API.RequestData) => { - const response = await axios.post(url, data); - const { responseCode, responseMsg, errorCode, params } = response.data; + const requestUrl = `${ctx.links.baseUrl}`; + const PurchaseData = prepareRequest('credit', { ...options, accountNumber }, ctx, generateUuid()); - if (responseCode !== '2001' || params == null) { - console.log(`WAAFI: API-RES: ${responseMsg} ERROR-CODE: ${errorCode}`); - throw responseCode; - } - return { - transactionId: params.transactionId, - paymentStatus: params.state, - referenceId: referenceId.toString(), - raw: response.data, - }; - }; + return await sendRequest(requestUrl, PurchaseData); + }, +}); - const referenceId = generateUuid(); - const { links } = ctx; +export type WaafiHandler = ReturnType - const requestUrl = `${links.baseUrl}`; - const requestData = prepareRequest('credit', { ...options, accountNumber }, ctx, referenceId); +async function sendRequest(url: string, data: API.PurchaseData) { + const response = await axios.post(url, data); + const { responseCode, responseMsg, errorCode, params } = response.data; - return await requestFn(requestUrl, requestData); - }, -}); + if (responseCode !== '2001' || params == null) { + console.log(`WAAFI: API-RES: ${responseMsg} ERROR-CODE: ${errorCode}`); + throw responseCode; + } -export type WaafiHandler = ReturnType \ No newline at end of file + return { + transactionId: params.transactionId, + paymentStatus: params.state, + referenceId: params.referenceId.toString(), + raw: response.data, + }; +}