UNPKG

pawapay-sdk

Version:

A comprehensive TypeScript/JavaScript SDK for integrating with the pawaPay API, enabling seamless mobile money operations such as deposits, payouts, refunds, wallet balance checks, and more.

1 lines 13.3 kB
{"version":3,"sources":["../src/index.ts","../src/client.ts"],"sourcesContent":["export * from \"./client.ts\"\nexport type {\n PawaPayError,\n DepositConfig,\n DepositResponse,\n RequestPayPageConfig,\n RequestPayPageResponse,\n RequestRefundConfig,\n RequestRefundResponse,\n WalletBalance,\n ActiveConfigurationResponse,\n AvailableCorrespondentResponse,\n PredictCorrespondentResponse,\n PublicKeysResponse,\n ResendDepositResponse,\n PayoutCallback,\n PawaPayResponse,\n RequestOptions,\n DepositStatus,\n ResendRefundCallbackResponse,\n RequestPayoutConfig,\n RequestPayoutRespose,\n CheckPayoutStatusResponse,\n CancelEnqueuedPayoutResponse,\n RequestBulkPayoutConfig,\n RequestBuildPayoutResponse,\n ResendPayoutCallbackResponse,\n RefundCallback,\n CheckRefundStatusResponse\n} from \"./types/index.t.ts\"","import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';\nimport {\n DepositConfig,\n PawaPayError,\n DepositResponse,\n PawaPayResponse,\n RequestOptions,\n DepositStatus,\n ResendDepositResponse,\n WalletBalance,\n PublicKeysResponse,\n ActiveConfigurationResponse,\n AvailableCorrespondentResponse,\n PredictCorrespondentResponse,\n RequestPayPageConfig,\n RequestPayPageResponse,\n RequestRefundConfig,\n RequestRefundResponse,\n ResendRefundCallbackResponse,\n RequestPayoutConfig,\n RequestPayoutRespose,\n CheckPayoutStatusResponse,\n CancelEnqueuedPayoutResponse,\n RequestBulkPayoutConfig,\n RequestBuildPayoutResponse,\n ResendPayoutCallbackResponse,\n CheckRefundStatusResponse\n} from './types/index.t.ts';\n\n\n\ntype ClientConfig = {\n environment?: \"live\" | \"sandbox\",\n overrideUrl?: string\n}\n\nexport class PawaPayClient {\n private apiClient: AxiosInstance;\n protected apiKey: string;\n private config?: ClientConfig;\n\n constructor(apiKey: string, config?: ClientConfig,) {\n this.apiKey = apiKey;\n this.config = config\n this.apiClient = axios.create({\n baseURL: config?.overrideUrl ?? config?.environment == \"live\" ? 'https://api.pawapay.io' : 'https://api.sandbox.pawapay.io',\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${this.apiKey}`\n }\n });\n }\n\n private async request<T, E>(config: AxiosRequestConfig, options?: RequestOptions)\n : Promise<PawaPayResponse<T, E>> {\n try {\n const response = await this.apiClient.request<T>(config);\n return {\n success: true,\n data: response.data,\n status: response.status,\n headers: response.headers\n }\n } catch (error) {\n if (axios.isAxiosError(error)) {\n return {\n success: false,\n error: error.response?.data || error.message,\n status: error.response?.status || 500\n }\n }\n return {\n success: false,\n error: {\n errorMessage: 'Unknown error occurred'\n } as E,\n status: 500\n };\n }\n }\n\n // --- Deposits\n\n async requestDeposit(data: DepositConfig, { options }: { options?: RequestOptions } = {})\n : Promise<PawaPayResponse<DepositResponse, PawaPayError>> {\n\n return this.request({\n method: 'POST',\n url: '/deposits',\n data,\n }, options)\n }\n\n\n async checkDepositStatus(depositId: string, { options }: { options?: RequestOptions } = {})\n : Promise<PawaPayResponse<DepositStatus[], PawaPayError>> {\n return this.request({\n method: 'GET',\n url: `/deposits/${depositId}`\n }, options)\n }\n\n async resendDepositCallback(depositId: string, { options }: { options?: RequestOptions } = {})\n : Promise<PawaPayResponse<ResendDepositResponse, PawaPayError>> {\n const data = { depositId }\n return this.request({\n method: 'POST',\n url: '/deposits/resend-callback',\n data,\n }, options)\n }\n\n // --- PAYOUTS\n\n async requestPayout(data: RequestPayoutConfig, { options }: { options?: RequestOptions } = {})\n : Promise<PawaPayResponse<RequestPayoutRespose, PawaPayError>> {\n return this.request({\n method: 'POST',\n url: '/payouts',\n data\n }, options)\n }\n\n async checkPayoutStatus(payoutId: string, { options }: { options?: RequestOptions } = {})\n : Promise<PawaPayResponse<CheckPayoutStatusResponse[], PawaPayError>> {\n return this.request({\n method: 'GET',\n url: `/payouts/${payoutId}`\n }, options)\n }\n\n async resendPayoutCallback(payoutId: string, { options }: { options?: RequestOptions } = {})\n : Promise<PawaPayResponse<ResendPayoutCallbackResponse, PawaPayError>> {\n const data = { payoutId }\n return this.request({\n method: 'POST',\n url: '/payouts/resend-callback',\n data\n }, options)\n }\n\n async cancelEnqueuedPayout(payoutId: string, { options }: { options?: RequestOptions } = {})\n : Promise<PawaPayResponse<CancelEnqueuedPayoutResponse, PawaPayError>> {\n return this.request({\n method: 'POST',\n url: `/payouts/fail-enqueued/${payoutId}`,\n }, options)\n }\n\n async requestBulkPayout(data: RequestBulkPayoutConfig[], { options }: { options?: RequestOptions } = {})\n : Promise<PawaPayResponse<RequestBuildPayoutResponse[], PawaPayError>> {\n return this.request({\n method: 'POST',\n url: '/payouts/bulk',\n data,\n }, options)\n }\n\n // --- REFUND\n async requestRefund(refundConfig: RequestRefundConfig, { options }: { options?: RequestOptions } = {})\n : Promise<PawaPayResponse<RequestRefundResponse, PawaPayError>> {\n return this.request({\n method: \"POST\",\n url: '/refunds',\n data: refundConfig\n }, options)\n }\n\n async checkRefundStatus(refundId: string, { options }: { options?: RequestOptions } = {})\n : Promise<PawaPayResponse<CheckRefundStatusResponse[], PawaPayError>> {\n return this.request({\n method: 'GET',\n url: `/refunds/${refundId}`\n }, options)\n }\n\n async resendRefundCallback(refundId: string, { options }: { options?: RequestOptions } = {})\n : Promise<PawaPayResponse<ResendRefundCallbackResponse, PawaPayError>> {\n return this.request({\n method: 'POST',\n url: '/refund/resend-callback',\n data: { refundId }\n }, options)\n }\n\n // --- PAYMENT PAGE\n\n async requestPaymentPage(payload: RequestPayPageConfig, { options }: { options?: RequestOptions } = {})\n : Promise<PawaPayResponse<RequestPayPageResponse, PawaPayError>> {\n return this.request({\n method: 'POST',\n url: '/v1/widget/sessions',\n data: payload\n })\n }\n\n // --- WALLETS\n\n async checkWalletBalances({ options }: { options?: RequestOptions } = {})\n : Promise<PawaPayResponse<WalletBalance, PawaPayError>> {\n return this.request({\n method: 'GET',\n url: '/v1/wallet-balances'\n }, options)\n }\n\n async checkWalletBalancesByCountry(country: string, { options }: { options?: RequestOptions } = {})\n : Promise<PawaPayResponse<WalletBalance, PawaPayError>> {\n return this.request({\n method: 'GET',\n url: `/v1/wallet-balances/${country}`\n })\n }\n\n // --- TOOLKIT\n\n async getActiveConfiguration({ options }: { options?: RequestOptions } = {})\n : Promise<PawaPayResponse<ActiveConfigurationResponse, PawaPayError>> {\n return this.request({\n method: `GET`,\n url: `/active-conf`\n }, options)\n }\n\n async getAvailableCorrespondent({ options }: { options?: RequestOptions } = {})\n : Promise<PawaPayResponse<AvailableCorrespondentResponse[], PawaPayError>> {\n return this.request({\n method: 'GET',\n url: '/availability'\n }, options)\n }\n\n predictCorrespondent(msisdn: string, { options }: { options?: RequestOptions } = {})\n : Promise<PawaPayResponse<PredictCorrespondentResponse, PawaPayError>> {\n const data = { msisdn }\n return this.request({\n method: 'GET',\n url: '/v1/predict-correspondent',\n data\n }, options)\n }\n\n getPublicKey({ options }: { options?: RequestOptions } = {})\n : Promise<PawaPayResponse<PublicKeysResponse[], PawaPayError>> {\n return this.request({\n method: 'GET',\n url: '/public-key/https'\n }, options)\n }\n}"],"mappings":"gmBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,IAAA,eAAAC,EAAAH,GCAA,IAAAI,EAAyD,sBAoClD,IAAMC,EAAN,KAAMA,CApCb,MAoCaA,CAAAA,EAAAA,sBACDC,UACEC,OACFC,OAERC,YAAYF,EAAgBC,EAAwB,CAChD,KAAKD,OAASA,EACd,KAAKC,OAASA,EACd,KAAKF,UAAYI,EAAAA,QAAMC,OAAO,CAC1BC,QAASJ,GAAQK,aAAeL,GAAQM,aAAe,OAAS,yBAA2B,iCAC3FC,QAAS,CACL,eAAgB,mBAChB,cAAiB,UAAU,KAAKR,MAAM,EAC1C,CACJ,CAAA,CACJ,CAEA,MAAcS,QAAcR,EAA4BS,EACnB,CACjC,GAAI,CACA,IAAMC,EAAW,MAAM,KAAKZ,UAAUU,Q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X,CACxD,OAAO,KAAKD,QAAQ,CAChBW,OAAQ,MACRC,IAAK,qBACT,EAAGX,CAAAA,CACP,CAEA,MAAM6B,6BAA6BC,EAAiB,CAAE9B,QAAAA,CAAO,EAAmC,CAAC,EACrC,CACxD,OAAO,KAAKD,QAAQ,CAChBW,OAAQ,MACRC,IAAK,uBAAuBmB,CAAAA,EAChC,CAAA,CACJ,CAIA,MAAMC,uBAAuB,CAAE/B,QAAAA,CAAO,EAAmC,CAAC,EACA,CACtE,OAAO,KAAKD,QAAQ,CAChBW,OAAQ,MACRC,IAAK,cACT,EAAGX,CAAAA,CACP,CAEA,MAAMgC,0BAA0B,CAAEhC,QAAAA,CAAO,EAAmC,CAAC,EACE,CAC3E,OAAO,KAAKD,QAAQ,CAChBW,OAAQ,MACRC,IAAK,eACT,EAAGX,CAAAA,CACP,CAEAiC,qBAAqBC,EAAgB,CAAElC,QAAAA,CAAO,EAAmC,CAAC,EACP,CACvE,IAAMG,EAAO,CAAE+B,OAAAA,CAAO,EACtB,OAAO,KAAKnC,QAAQ,CAChBW,OAAQ,MACRC,IAAK,4BACLR,KAAAA,CACJ,EAAGH,CAAAA,CACP,CAEAmC,aAAa,CAAEnC,QAAAA,CAAO,EAAmC,CAAC,EACS,CAC/D,OAAO,KAAKD,QAAQ,CAChBW,OAAQ,MACRC,IAAK,mBACT,EAAGX,CAAAA,CACP,CACJ","names":["index_exports","__export","PawaPayClient","__toCommonJS","import_axios","PawaPayClient","apiClient","apiKey","config","constructor","axios","create","baseURL","overrideUrl","environment","headers","request","options","response","success","data","status","error","isAxiosError","message","errorMessage","requestDeposit","method","url","checkDepositStatus","depositId","resendDepositCallback","requestPayout","checkPayoutStatus","payoutId","resendPayoutCallback","cancelEnqueuedPayout","requestBulkPayout","requestRefund","refundConfig","checkRefundStatus","refundId","resendRefundCallback","requestPaymentPage","payload","checkWalletBalances","checkWalletBalancesByCountry","country","getActiveConfiguration","getAvailableCorrespondent","predictCorrespondent","msisdn","getPublicKey"]}