UNPKG

afrimomo-sdk

Version:

A unified SDK for African payment providers

87 lines 3.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createPawapayClient = createPawapayClient; exports.createPaychanguClient = createPaychanguClient; exports.getOneKhusaTokenUrl = getOneKhusaTokenUrl; exports.createOnekhusaClient = createOnekhusaClient; const httpClient_1 = require("./httpClient"); const PROVIDER_URLS = { pawapay: { production: "https://api.pawapay.io/v1", sandbox: "https://api.sandbox.pawapay.io/v1", }, paychangu: { production: "https://api.paychangu.com", sandbox: "https://api.paychangu.com", }, onekhusa: { production: "https://api.onekhusa.com/live/v1", sandbox: "https://api.onekhusa.com/sandbox/v1", tokenUrl: { production: "https://api.onekhusa.com/live/oauth/token", sandbox: "https://api.onekhusa.com/sandbox/oauth/token", }, }, }; function getBaseUrl(provider, environment, customSandboxUrl, customProductionUrl) { if (environment === "PRODUCTION") { return customProductionUrl || PROVIDER_URLS[provider].production; } return customSandboxUrl || PROVIDER_URLS[provider].sandbox; } function createPawapayClient(jwt, environment = "DEVELOPMENT", sandboxUrl, productionUrl) { const config = { baseUrl: getBaseUrl("pawapay", environment, sandboxUrl, productionUrl), serviceName: "PawaPay", timeoutMs: 30000, }; const auth = { type: "bearer", token: jwt, }; return new httpClient_1.HttpClient(config, auth); } function createPaychanguClient(secretKey, environment = "DEVELOPMENT", sandboxUrl, productionUrl) { const config = { baseUrl: getBaseUrl("paychangu", environment, sandboxUrl, productionUrl), serviceName: "PayChangu", timeoutMs: 30000, }; const auth = { type: "bearer", token: secretKey, }; return new httpClient_1.HttpClient(config, auth); } function getOneKhusaTokenUrl(environment, customSandboxUrl, customProductionUrl) { if (environment === "PRODUCTION") { return customProductionUrl ? `${customProductionUrl}/oauth/token` : PROVIDER_URLS.onekhusa.tokenUrl.production; } return customSandboxUrl ? `${customSandboxUrl}/oauth/token` : PROVIDER_URLS.onekhusa.tokenUrl.sandbox; } function createOnekhusaClient(tokenProvider, organisationId, environment = "DEVELOPMENT", sandboxUrl, productionUrl) { const config = { baseUrl: getBaseUrl("onekhusa", environment, sandboxUrl, productionUrl), serviceName: "OneKhusa", timeoutMs: 30000, }; const auth = { type: "custom", getAuthHeader: async () => { const token = await tokenProvider.getToken(); return `Bearer ${token}`; }, }; const requestHook = { onRequest: (config) => { config.headers["Organisation-Id"] = organisationId; return config; }, }; return new httpClient_1.HttpClient(config, auth, requestHook); } //# sourceMappingURL=providerClients.js.map