@nomba/node-sdk 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +577 -2
- package/dist/index.d.ts +86 -0
- package/dist/index.js +53 -0
- package/dist/interfaces/http/IHttpClient.d.ts +17 -0
- package/dist/interfaces/http/IHttpClient.js +5 -0
- package/dist/interfaces/http/index.d.ts +1 -0
- package/dist/interfaces/http/index.js +1 -0
- package/dist/interfaces/v1/accounts/IAccountsService.d.ts +62 -0
- package/dist/interfaces/v1/accounts/IAccountsService.js +5 -0
- package/dist/interfaces/v1/accounts/index.d.ts +1 -0
- package/dist/interfaces/v1/accounts/index.js +1 -0
- package/dist/interfaces/v1/betting/IBettingService.d.ts +20 -0
- package/dist/interfaces/v1/betting/IBettingService.js +5 -0
- package/dist/interfaces/v1/betting/index.d.ts +1 -0
- package/dist/interfaces/v1/betting/index.js +1 -0
- package/dist/interfaces/v1/cable/ICableService.d.ts +21 -0
- package/dist/interfaces/v1/cable/ICableService.js +5 -0
- package/dist/interfaces/v1/cable/index.d.ts +1 -0
- package/dist/interfaces/v1/cable/index.js +1 -0
- package/dist/interfaces/v1/charge/IChargeService.d.ts +94 -0
- package/dist/interfaces/v1/charge/IChargeService.js +5 -0
- package/dist/interfaces/v1/charge/index.d.ts +1 -0
- package/dist/interfaces/v1/charge/index.js +1 -0
- package/dist/interfaces/v1/checkout/ICheckoutService.d.ts +79 -0
- package/dist/interfaces/v1/checkout/ICheckoutService.js +5 -0
- package/dist/interfaces/v1/checkout/index.d.ts +1 -0
- package/dist/interfaces/v1/checkout/index.js +1 -0
- package/dist/interfaces/v1/data/IDataService.d.ts +14 -0
- package/dist/interfaces/v1/data/IDataService.js +5 -0
- package/dist/interfaces/v1/data/index.d.ts +1 -0
- package/dist/interfaces/v1/data/index.js +1 -0
- package/dist/interfaces/v1/direct-debits/IDirectDebitsService.d.ts +54 -0
- package/dist/interfaces/v1/direct-debits/IDirectDebitsService.js +5 -0
- package/dist/interfaces/v1/direct-debits/index.d.ts +1 -0
- package/dist/interfaces/v1/direct-debits/index.js +1 -0
- package/dist/interfaces/v1/electricity/IElectricityService.d.ts +20 -0
- package/dist/interfaces/v1/electricity/IElectricityService.js +5 -0
- package/dist/interfaces/v1/electricity/index.d.ts +1 -0
- package/dist/interfaces/v1/electricity/index.js +1 -0
- package/dist/interfaces/v1/globals/collections/IGlobalCollectionsService.d.ts +29 -0
- package/dist/interfaces/v1/globals/collections/IGlobalCollectionsService.js +5 -0
- package/dist/interfaces/v1/globals/collections/index.d.ts +1 -0
- package/dist/interfaces/v1/globals/collections/index.js +1 -0
- package/dist/interfaces/v1/globals/payouts/IGlobalPayoutService.d.ts +91 -0
- package/dist/interfaces/v1/globals/payouts/IGlobalPayoutService.js +5 -0
- package/dist/interfaces/v1/globals/payouts/index.d.ts +1 -0
- package/dist/interfaces/v1/globals/payouts/index.js +1 -0
- package/dist/interfaces/v1/requery/IRequeryService.d.ts +31 -0
- package/dist/interfaces/v1/requery/IRequeryService.js +5 -0
- package/dist/interfaces/v1/requery/index.d.ts +1 -0
- package/dist/interfaces/v1/requery/index.js +1 -0
- package/dist/interfaces/v1/terminals/ITerminalsService.d.ts +51 -0
- package/dist/interfaces/v1/terminals/ITerminalsService.js +5 -0
- package/dist/interfaces/v1/terminals/index.d.ts +1 -0
- package/dist/interfaces/v1/terminals/index.js +1 -0
- package/dist/interfaces/v1/transactions/ITransactionsService.d.ts +93 -0
- package/dist/interfaces/v1/transactions/ITransactionsService.js +5 -0
- package/dist/interfaces/v1/transactions/index.d.ts +1 -0
- package/dist/interfaces/v1/transactions/index.js +1 -0
- package/dist/interfaces/v1/virtual-accounts/IVirtualAccountsService.d.ts +65 -0
- package/dist/interfaces/v1/virtual-accounts/IVirtualAccountsService.js +5 -0
- package/dist/interfaces/v1/virtual-accounts/index.d.ts +1 -0
- package/dist/interfaces/v1/virtual-accounts/index.js +1 -0
- package/dist/interfaces/v1/webhooks/IWebhooksService.d.ts +40 -0
- package/dist/interfaces/v1/webhooks/IWebhooksService.js +5 -0
- package/dist/interfaces/v1/webhooks/index.d.ts +1 -0
- package/dist/interfaces/v1/webhooks/index.js +1 -0
- package/dist/interfaces/v2/airtime/IAirtimeV2Service.d.ts +31 -0
- package/dist/interfaces/v2/airtime/IAirtimeV2Service.js +5 -0
- package/dist/interfaces/v2/airtime/index.d.ts +1 -0
- package/dist/interfaces/v2/airtime/index.js +1 -0
- package/dist/interfaces/v2/betting/IBettingV2Service.d.ts +31 -0
- package/dist/interfaces/v2/betting/IBettingV2Service.js +5 -0
- package/dist/interfaces/v2/betting/index.d.ts +1 -0
- package/dist/interfaces/v2/betting/index.js +1 -0
- package/dist/interfaces/v2/cable/ICableV2Service.d.ts +31 -0
- package/dist/interfaces/v2/cable/ICableV2Service.js +5 -0
- package/dist/interfaces/v2/cable/index.d.ts +1 -0
- package/dist/interfaces/v2/cable/index.js +1 -0
- package/dist/interfaces/v2/data/IDataV2Service.d.ts +31 -0
- package/dist/interfaces/v2/data/IDataV2Service.js +5 -0
- package/dist/interfaces/v2/data/index.d.ts +1 -0
- package/dist/interfaces/v2/data/index.js +1 -0
- package/dist/interfaces/v2/electricity/IElectricityV2Service.d.ts +32 -0
- package/dist/interfaces/v2/electricity/IElectricityV2Service.js +5 -0
- package/dist/interfaces/v2/electricity/index.d.ts +1 -0
- package/dist/interfaces/v2/electricity/index.js +1 -0
- package/dist/interfaces/v2/transfers/ITransfersService.d.ts +71 -0
- package/dist/interfaces/v2/transfers/ITransfersService.js +5 -0
- package/dist/interfaces/v2/transfers/index.d.ts +1 -0
- package/dist/interfaces/v2/transfers/index.js +1 -0
- package/dist/lib/errors.d.ts +62 -0
- package/dist/lib/errors.js +92 -0
- package/dist/lib/outcome.d.ts +37 -0
- package/dist/lib/outcome.js +126 -0
- package/dist/lib/paginate.d.ts +21 -0
- package/dist/lib/paginate.js +25 -0
- package/dist/lib/sdk-version.d.ts +5 -0
- package/dist/lib/sdk-version.generated.d.ts +1 -0
- package/dist/lib/sdk-version.generated.js +1 -0
- package/dist/lib/sdk-version.js +5 -0
- package/dist/lib/token-store.d.ts +49 -0
- package/dist/lib/token-store.js +26 -0
- package/dist/lib/util.d.ts +31 -0
- package/dist/lib/util.js +31 -0
- package/dist/lib/webhooks.d.ts +43 -0
- package/dist/lib/webhooks.js +64 -0
- package/dist/nomba.d.ts +96 -0
- package/dist/nomba.js +130 -0
- package/dist/services/http/http-client.service.d.ts +61 -0
- package/dist/services/http/http-client.service.js +351 -0
- package/dist/services/v1/accounts/accounts.service.d.ts +76 -0
- package/dist/services/v1/accounts/accounts.service.js +96 -0
- package/dist/services/v1/betting/betting.service.d.ts +25 -0
- package/dist/services/v1/betting/betting.service.js +30 -0
- package/dist/services/v1/cable/cable.service.d.ts +26 -0
- package/dist/services/v1/cable/cable.service.js +33 -0
- package/dist/services/v1/charge/charge.service.d.ts +113 -0
- package/dist/services/v1/charge/charge.service.js +161 -0
- package/dist/services/v1/checkout/checkout.service.d.ts +92 -0
- package/dist/services/v1/checkout/checkout.service.js +146 -0
- package/dist/services/v1/data/data.service.d.ts +20 -0
- package/dist/services/v1/data/data.service.js +22 -0
- package/dist/services/v1/direct-debits/direct-debits.service.d.ts +69 -0
- package/dist/services/v1/direct-debits/direct-debits.service.js +91 -0
- package/dist/services/v1/electricity/electricity.service.d.ts +26 -0
- package/dist/services/v1/electricity/electricity.service.js +31 -0
- package/dist/services/v1/globals/collections.service.d.ts +44 -0
- package/dist/services/v1/globals/collections.service.js +55 -0
- package/dist/services/v1/globals/payout.service.d.ts +105 -0
- package/dist/services/v1/globals/payout.service.js +154 -0
- package/dist/services/v1/requery/requery.service.d.ts +31 -0
- package/dist/services/v1/requery/requery.service.js +41 -0
- package/dist/services/v1/terminals/terminals.service.d.ts +38 -0
- package/dist/services/v1/terminals/terminals.service.js +58 -0
- package/dist/services/v1/transactions/transactions.service.d.ts +48 -0
- package/dist/services/v1/transactions/transactions.service.js +98 -0
- package/dist/services/v1/virtual-accounts/virtual-accounts.service.d.ts +40 -0
- package/dist/services/v1/virtual-accounts/virtual-accounts.service.js +55 -0
- package/dist/services/v1/webhooks/webhooks.service.d.ts +35 -0
- package/dist/services/v1/webhooks/webhooks.service.js +59 -0
- package/dist/services/v2/airtime/airtime.service.d.ts +42 -0
- package/dist/services/v2/airtime/airtime.service.js +55 -0
- package/dist/services/v2/betting/betting.service.d.ts +43 -0
- package/dist/services/v2/betting/betting.service.js +56 -0
- package/dist/services/v2/cable/cable.service.d.ts +43 -0
- package/dist/services/v2/cable/cable.service.js +56 -0
- package/dist/services/v2/data/data.service.d.ts +42 -0
- package/dist/services/v2/data/data.service.js +55 -0
- package/dist/services/v2/electricity/electricity.service.d.ts +44 -0
- package/dist/services/v2/electricity/electricity.service.js +57 -0
- package/dist/services/v2/transfers/transfers.service.d.ts +75 -0
- package/dist/services/v2/transfers/transfers.service.js +97 -0
- package/dist/types/common/common.types.d.ts +74 -0
- package/dist/types/common/common.types.js +5 -0
- package/dist/types/common/outcome.types.d.ts +53 -0
- package/dist/types/common/outcome.types.js +5 -0
- package/dist/types/v1/accounts/accounts.types.d.ts +37 -0
- package/dist/types/v1/accounts/accounts.types.js +8 -0
- package/dist/types/v1/betting/betting.types.d.ts +26 -0
- package/dist/types/v1/betting/betting.types.js +5 -0
- package/dist/types/v1/cable/cable.types.d.ts +24 -0
- package/dist/types/v1/cable/cable.types.js +5 -0
- package/dist/types/v1/charge/charge.types.d.ts +102 -0
- package/dist/types/v1/charge/charge.types.js +5 -0
- package/dist/types/v1/checkout/checkout.types.d.ts +139 -0
- package/dist/types/v1/checkout/checkout.types.js +5 -0
- package/dist/types/v1/data/data.types.d.ts +14 -0
- package/dist/types/v1/data/data.types.js +5 -0
- package/dist/types/v1/direct-debits/direct-debits.types.d.ts +104 -0
- package/dist/types/v1/direct-debits/direct-debits.types.js +5 -0
- package/dist/types/v1/electricity/electricity.types.d.ts +21 -0
- package/dist/types/v1/electricity/electricity.types.js +5 -0
- package/dist/types/v1/globals/collections.types.d.ts +49 -0
- package/dist/types/v1/globals/collections.types.js +5 -0
- package/dist/types/v1/globals/payout.types.d.ts +183 -0
- package/dist/types/v1/globals/payout.types.js +5 -0
- package/dist/types/v1/requery/requery.types.d.ts +49 -0
- package/dist/types/v1/requery/requery.types.js +5 -0
- package/dist/types/v1/terminals/terminals.types.d.ts +44 -0
- package/dist/types/v1/terminals/terminals.types.js +5 -0
- package/dist/types/v1/transactions/transactions.types.d.ts +87 -0
- package/dist/types/v1/transactions/transactions.types.js +5 -0
- package/dist/types/v1/virtual-accounts/virtual-accounts.types.d.ts +64 -0
- package/dist/types/v1/virtual-accounts/virtual-accounts.types.js +5 -0
- package/dist/types/v1/webhooks/webhooks.types.d.ts +54 -0
- package/dist/types/v1/webhooks/webhooks.types.js +5 -0
- package/dist/types/v2/airtime/airtime.types.d.ts +31 -0
- package/dist/types/v2/airtime/airtime.types.js +5 -0
- package/dist/types/v2/betting/betting.types.d.ts +33 -0
- package/dist/types/v2/betting/betting.types.js +5 -0
- package/dist/types/v2/cable/cable.types.d.ts +32 -0
- package/dist/types/v2/cable/cable.types.js +5 -0
- package/dist/types/v2/data/data.types.d.ts +32 -0
- package/dist/types/v2/data/data.types.js +5 -0
- package/dist/types/v2/electricity/electricity.types.d.ts +34 -0
- package/dist/types/v2/electricity/electricity.types.js +5 -0
- package/dist/types/v2/transfers/transfers.types.d.ts +99 -0
- package/dist/types/v2/transfers/transfers.types.js +5 -0
- package/package.json +42 -5
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/services/v2/cable
|
|
3
|
+
* @description CableV2 (v2): POST /v2/bill/cabletv[/{subAccountId}]
|
|
4
|
+
* @see https://developer.nomba.com/docs/api-reference/bills
|
|
5
|
+
*/
|
|
6
|
+
import { REJECTED, settle } from "../../../lib/outcome.js";
|
|
7
|
+
import { pathId } from "../../../lib/util.js";
|
|
8
|
+
// The v2 reference documents code "200" (done) or "201" (still processing), and data.status SUCCESS or
|
|
9
|
+
// PENDING_BILLING; anything else is to be treated as pending. The guides show "00" for success too, so we
|
|
10
|
+
// accept both. Sandbox calls (2026-09-29) returned "200" + SUCCESS.
|
|
11
|
+
const OUTCOMES = {
|
|
12
|
+
codes: { "00": "success", "200": "success", "201": "pending", ...REJECTED },
|
|
13
|
+
statuses: { SUCCESS: "success", PENDING_BILLING: "pending" },
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Cable TV subscription payments (v2 has purchase endpoints only). A call that throws a NombaError with a
|
|
17
|
+
* 4xx status was rejected and did nothing. Any other failure (5xx, network error, timeout) leaves the
|
|
18
|
+
* outcome unknown: keep the same `merchantTxRef`, wait for the webhook or requery, and never retry under a
|
|
19
|
+
* new reference.
|
|
20
|
+
*/
|
|
21
|
+
export class CableV2Service {
|
|
22
|
+
http;
|
|
23
|
+
constructor(http) {
|
|
24
|
+
this.http = http;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* `POST /v2/bill/cabletv`. Pays a cable TV subscription from the parent account.
|
|
28
|
+
* @param params The provider, smartcard/customer id and plan, and the `merchantTxRef` used for idempotency.
|
|
29
|
+
* @param options Outcome closures and per-call overrides; without them, success resolves the result and
|
|
30
|
+
* a rejection or pending outcome throws.
|
|
31
|
+
* @returns The payment result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
32
|
+
* @throws {NombaError} The payment was rejected (4xx).
|
|
33
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
34
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
35
|
+
*/
|
|
36
|
+
async subscribeCableTv(params, options = {}) {
|
|
37
|
+
return this.#pay("/v2/bill/cabletv", params, options);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* `POST /v2/bill/cabletv/{subAccountId}`. Pays from a sub account.
|
|
41
|
+
* @param subAccountId The sub account to pay from.
|
|
42
|
+
* @param params The provider, smartcard/customer id and plan, and the `merchantTxRef` used for idempotency.
|
|
43
|
+
* @param options Outcome closures and per-call overrides; without them, success resolves the result and
|
|
44
|
+
* a rejection or pending outcome throws.
|
|
45
|
+
* @returns The payment result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
46
|
+
* @throws {NombaError} The payment was rejected (4xx).
|
|
47
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
48
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
49
|
+
*/
|
|
50
|
+
async subscribeCableTvFromSubAccount(subAccountId, params, options = {}) {
|
|
51
|
+
return this.#pay(`/v2/bill/cabletv/${pathId(subAccountId)}`, params, options);
|
|
52
|
+
}
|
|
53
|
+
#pay(path, params, options) {
|
|
54
|
+
return settle(this.http, "POST", path, { body: params }, OUTCOMES, params.merchantTxRef, options);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/services/v2/data
|
|
3
|
+
* @description DataV2 (v2): POST /v2/bill/data
|
|
4
|
+
* @see https://developer.nomba.com/docs/api-reference/airtime-and-data-vending
|
|
5
|
+
*/
|
|
6
|
+
import type { IHttpClient } from "../../../interfaces/http/IHttpClient.js";
|
|
7
|
+
import type { IDataV2Service } from "../../../interfaces/v2/data/index.js";
|
|
8
|
+
import type { CallOptions } from "../../../types/common/common.types.js";
|
|
9
|
+
import type { DataPurchaseParams, DataPurchaseV2Result } from "../../../types/v2/data/data.types.js";
|
|
10
|
+
/**
|
|
11
|
+
* Data bundle purchases (v2). A call that throws a NombaError with a 4xx status was rejected and did
|
|
12
|
+
* nothing. Any other failure (5xx, network error, timeout) leaves the outcome unknown: keep the same
|
|
13
|
+
* `merchantTxRef`, wait for the webhook or requery, and never retry under a new reference.
|
|
14
|
+
*/
|
|
15
|
+
export declare class DataV2Service implements IDataV2Service {
|
|
16
|
+
#private;
|
|
17
|
+
private readonly http;
|
|
18
|
+
constructor(http: IHttpClient);
|
|
19
|
+
/**
|
|
20
|
+
* `POST /v2/bill/data`. Buys a data bundle from the parent account.
|
|
21
|
+
* @param params The phone number, network and data plan, and the `merchantTxRef` used for idempotency.
|
|
22
|
+
* @param options Outcome closures and per-call overrides; without them, success resolves the result and
|
|
23
|
+
* a rejection or pending outcome throws.
|
|
24
|
+
* @returns The purchase result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
25
|
+
* @throws {NombaError} The purchase was rejected (4xx).
|
|
26
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
27
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
28
|
+
*/
|
|
29
|
+
buyData<R = DataPurchaseV2Result>(params: DataPurchaseParams, options?: CallOptions<DataPurchaseV2Result, R>): Promise<DataPurchaseV2Result | R>;
|
|
30
|
+
/**
|
|
31
|
+
* `POST /v2/bill/data/{subAccountId}`. Buys a data bundle from a sub account.
|
|
32
|
+
* @param subAccountId The sub account to buy from.
|
|
33
|
+
* @param params The phone number, network and data plan, and the `merchantTxRef` used for idempotency.
|
|
34
|
+
* @param options Outcome closures and per-call overrides; without them, success resolves the result and
|
|
35
|
+
* a rejection or pending outcome throws.
|
|
36
|
+
* @returns The purchase result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
37
|
+
* @throws {NombaError} The purchase was rejected (4xx).
|
|
38
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
39
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
40
|
+
*/
|
|
41
|
+
buyDataFromSubAccount<R = DataPurchaseV2Result>(subAccountId: string, params: DataPurchaseParams, options?: CallOptions<DataPurchaseV2Result, R>): Promise<DataPurchaseV2Result | R>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/services/v2/data
|
|
3
|
+
* @description DataV2 (v2): POST /v2/bill/data
|
|
4
|
+
* @see https://developer.nomba.com/docs/api-reference/airtime-and-data-vending
|
|
5
|
+
*/
|
|
6
|
+
import { REJECTED, settle } from "../../../lib/outcome.js";
|
|
7
|
+
import { pathId } from "../../../lib/util.js";
|
|
8
|
+
// The v2 reference documents code "200" (done) or "201" (still processing), and data.status SUCCESS or
|
|
9
|
+
// PENDING_BILLING; anything else is to be treated as pending. A sandbox call (2026-09-29) returned "200" +
|
|
10
|
+
// SUCCESS. The guides show "00" for success too, so we accept both.
|
|
11
|
+
const OUTCOMES = {
|
|
12
|
+
codes: { "00": "success", "200": "success", "201": "pending", ...REJECTED },
|
|
13
|
+
statuses: { SUCCESS: "success", PENDING_BILLING: "pending" },
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Data bundle purchases (v2). A call that throws a NombaError with a 4xx status was rejected and did
|
|
17
|
+
* nothing. Any other failure (5xx, network error, timeout) leaves the outcome unknown: keep the same
|
|
18
|
+
* `merchantTxRef`, wait for the webhook or requery, and never retry under a new reference.
|
|
19
|
+
*/
|
|
20
|
+
export class DataV2Service {
|
|
21
|
+
http;
|
|
22
|
+
constructor(http) {
|
|
23
|
+
this.http = http;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* `POST /v2/bill/data`. Buys a data bundle from the parent account.
|
|
27
|
+
* @param params The phone number, network and data plan, and the `merchantTxRef` used for idempotency.
|
|
28
|
+
* @param options Outcome closures and per-call overrides; without them, success resolves the result and
|
|
29
|
+
* a rejection or pending outcome throws.
|
|
30
|
+
* @returns The purchase result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
31
|
+
* @throws {NombaError} The purchase was rejected (4xx).
|
|
32
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
33
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
34
|
+
*/
|
|
35
|
+
async buyData(params, options = {}) {
|
|
36
|
+
return this.#buy("/v2/bill/data", params, options);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* `POST /v2/bill/data/{subAccountId}`. Buys a data bundle from a sub account.
|
|
40
|
+
* @param subAccountId The sub account to buy from.
|
|
41
|
+
* @param params The phone number, network and data plan, and the `merchantTxRef` used for idempotency.
|
|
42
|
+
* @param options Outcome closures and per-call overrides; without them, success resolves the result and
|
|
43
|
+
* a rejection or pending outcome throws.
|
|
44
|
+
* @returns The purchase result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
45
|
+
* @throws {NombaError} The purchase was rejected (4xx).
|
|
46
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
47
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
48
|
+
*/
|
|
49
|
+
async buyDataFromSubAccount(subAccountId, params, options = {}) {
|
|
50
|
+
return this.#buy(`/v2/bill/data/${pathId(subAccountId)}`, params, options);
|
|
51
|
+
}
|
|
52
|
+
#buy(path, params, options) {
|
|
53
|
+
return settle(this.http, "POST", path, { body: params }, OUTCOMES, params.merchantTxRef, options);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/services/v2/electricity
|
|
3
|
+
* @description ElectricityV2 (v2): POST /v2/bill/electricity[/{subAccountId}]
|
|
4
|
+
* @see https://developer.nomba.com/docs/api-reference/bills
|
|
5
|
+
*/
|
|
6
|
+
import type { IHttpClient } from "../../../interfaces/http/IHttpClient.js";
|
|
7
|
+
import type { IElectricityV2Service } from "../../../interfaces/v2/electricity/index.js";
|
|
8
|
+
import type { CallOptions } from "../../../types/common/common.types.js";
|
|
9
|
+
import type { ElectricityPaymentParams, ElectricityPaymentV2Result } from "../../../types/v2/electricity/electricity.types.js";
|
|
10
|
+
/**
|
|
11
|
+
* Electricity bill payments (v2 has purchase endpoints only). A call that throws a NombaError with a 4xx
|
|
12
|
+
* status was rejected and did nothing. Any other failure (5xx, network error, timeout) leaves the outcome
|
|
13
|
+
* unknown: keep the same `merchantTxRef`, wait for the webhook or requery, and never retry under a new
|
|
14
|
+
* reference.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ElectricityV2Service implements IElectricityV2Service {
|
|
17
|
+
#private;
|
|
18
|
+
private readonly http;
|
|
19
|
+
constructor(http: IHttpClient);
|
|
20
|
+
/**
|
|
21
|
+
* `POST /v2/bill/electricity`. Pays an electricity bill from the parent account. Prepaid meters get the
|
|
22
|
+
* token in `meta.phcnToken`.
|
|
23
|
+
* @param params The disco, meter number and amount, and the `merchantTxRef` used for idempotency.
|
|
24
|
+
* @param options Outcome closures and per-call overrides; without them, success resolves the result and
|
|
25
|
+
* a rejection or pending outcome throws.
|
|
26
|
+
* @returns The payment result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
27
|
+
* @throws {NombaError} The payment was rejected (4xx).
|
|
28
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
29
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
30
|
+
*/
|
|
31
|
+
payElectricity<R = ElectricityPaymentV2Result>(params: ElectricityPaymentParams, options?: CallOptions<ElectricityPaymentV2Result, R>): Promise<ElectricityPaymentV2Result | R>;
|
|
32
|
+
/**
|
|
33
|
+
* `POST /v2/bill/electricity/{subAccountId}`. Pays from a sub account.
|
|
34
|
+
* @param subAccountId The sub account to pay from.
|
|
35
|
+
* @param params The disco, meter number and amount, and the `merchantTxRef` used for idempotency.
|
|
36
|
+
* @param options Outcome closures and per-call overrides; without them, success resolves the result and
|
|
37
|
+
* a rejection or pending outcome throws.
|
|
38
|
+
* @returns The payment result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
39
|
+
* @throws {NombaError} The payment was rejected (4xx).
|
|
40
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
41
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
42
|
+
*/
|
|
43
|
+
payElectricityFromSubAccount<R = ElectricityPaymentV2Result>(subAccountId: string, params: ElectricityPaymentParams, options?: CallOptions<ElectricityPaymentV2Result, R>): Promise<ElectricityPaymentV2Result | R>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/services/v2/electricity
|
|
3
|
+
* @description ElectricityV2 (v2): POST /v2/bill/electricity[/{subAccountId}]
|
|
4
|
+
* @see https://developer.nomba.com/docs/api-reference/bills
|
|
5
|
+
*/
|
|
6
|
+
import { REJECTED, settle } from "../../../lib/outcome.js";
|
|
7
|
+
import { pathId } from "../../../lib/util.js";
|
|
8
|
+
// The v2 reference documents code "200" (done) or "201" (still processing), and data.status SUCCESS or
|
|
9
|
+
// PENDING_BILLING; anything else is to be treated as pending. The guides show "00" for success too, so we
|
|
10
|
+
// accept both. Sandbox calls (2026-09-29) returned "200" + SUCCESS.
|
|
11
|
+
const OUTCOMES = {
|
|
12
|
+
codes: { "00": "success", "200": "success", "201": "pending", ...REJECTED },
|
|
13
|
+
statuses: { SUCCESS: "success", PENDING_BILLING: "pending" },
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Electricity bill payments (v2 has purchase endpoints only). A call that throws a NombaError with a 4xx
|
|
17
|
+
* status was rejected and did nothing. Any other failure (5xx, network error, timeout) leaves the outcome
|
|
18
|
+
* unknown: keep the same `merchantTxRef`, wait for the webhook or requery, and never retry under a new
|
|
19
|
+
* reference.
|
|
20
|
+
*/
|
|
21
|
+
export class ElectricityV2Service {
|
|
22
|
+
http;
|
|
23
|
+
constructor(http) {
|
|
24
|
+
this.http = http;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* `POST /v2/bill/electricity`. Pays an electricity bill from the parent account. Prepaid meters get the
|
|
28
|
+
* token in `meta.phcnToken`.
|
|
29
|
+
* @param params The disco, meter number and amount, and the `merchantTxRef` used for idempotency.
|
|
30
|
+
* @param options Outcome closures and per-call overrides; without them, success resolves the result and
|
|
31
|
+
* a rejection or pending outcome throws.
|
|
32
|
+
* @returns The payment result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
33
|
+
* @throws {NombaError} The payment was rejected (4xx).
|
|
34
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
35
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
36
|
+
*/
|
|
37
|
+
async payElectricity(params, options = {}) {
|
|
38
|
+
return this.#pay("/v2/bill/electricity", params, options);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* `POST /v2/bill/electricity/{subAccountId}`. Pays from a sub account.
|
|
42
|
+
* @param subAccountId The sub account to pay from.
|
|
43
|
+
* @param params The disco, meter number and amount, and the `merchantTxRef` used for idempotency.
|
|
44
|
+
* @param options Outcome closures and per-call overrides; without them, success resolves the result and
|
|
45
|
+
* a rejection or pending outcome throws.
|
|
46
|
+
* @returns The payment result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
47
|
+
* @throws {NombaError} The payment was rejected (4xx).
|
|
48
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
49
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
50
|
+
*/
|
|
51
|
+
async payElectricityFromSubAccount(subAccountId, params, options = {}) {
|
|
52
|
+
return this.#pay(`/v2/bill/electricity/${pathId(subAccountId)}`, params, options);
|
|
53
|
+
}
|
|
54
|
+
#pay(path, params, options) {
|
|
55
|
+
return settle(this.http, "POST", path, { body: params }, OUTCOMES, params.merchantTxRef, options);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/services/v2/transfers
|
|
3
|
+
* @description Transfers (v2): POST /v2/transfers[/{subAccountId}]/*
|
|
4
|
+
* @see https://developer.nomba.com/docs/api-reference/transfers
|
|
5
|
+
*/
|
|
6
|
+
import type { IHttpClient } from "../../../interfaces/http/IHttpClient.js";
|
|
7
|
+
import type { ITransfersService } from "../../../interfaces/v2/transfers/ITransfersService.js";
|
|
8
|
+
import type { CallOptions } from "../../../types/common/common.types.js";
|
|
9
|
+
import type { Bank, BankAccountLookupParams, BankAccountLookupResult, BankTransferParams, BankTransferResult, WalletTransferParams, WalletTransferResult } from "../../../types/v2/transfers/transfers.types.js";
|
|
10
|
+
/**
|
|
11
|
+
* Money movement. A call that throws a NombaError with a 4xx status was rejected and did nothing. Any other
|
|
12
|
+
* failure (5xx, network error, timeout) leaves the outcome unknown: keep the same `merchantTxRef`, wait for the
|
|
13
|
+
* webhook or requery, and never send the transfer again under a new reference.
|
|
14
|
+
*/
|
|
15
|
+
export declare class TransfersService implements ITransfersService {
|
|
16
|
+
private readonly http;
|
|
17
|
+
constructor(http: IHttpClient);
|
|
18
|
+
/**
|
|
19
|
+
* `GET /v1/transfers/banks`. Lists the banks usable as a transfer destination.
|
|
20
|
+
* @returns The supported banks, each with its name and code.
|
|
21
|
+
* @throws {NombaError} A non-2xx response.
|
|
22
|
+
*/
|
|
23
|
+
listBanks(): Promise<Bank[]>;
|
|
24
|
+
/**
|
|
25
|
+
* `POST /v1/transfers/bank/lookup`. Resolves a bank account number to its account name.
|
|
26
|
+
* @param params The bank code and account number to look up.
|
|
27
|
+
* @returns The resolved account name.
|
|
28
|
+
* @throws {NombaError} The lookup was rejected, e.g. an invalid account number.
|
|
29
|
+
*/
|
|
30
|
+
lookupBankAccount(params: BankAccountLookupParams): Promise<BankAccountLookupResult>;
|
|
31
|
+
/**
|
|
32
|
+
* `POST /v2/transfers/bank`. Sends a bank transfer from the parent account.
|
|
33
|
+
* @param params The destination bank, account number and amount; `merchantTxRef` is the idempotency key.
|
|
34
|
+
* @param options Outcome closures; without them, success resolves the result and pending/failure throws.
|
|
35
|
+
* @returns The transfer result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
36
|
+
* @throws {NombaError} The transfer was rejected (4xx) and never happened.
|
|
37
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
38
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
39
|
+
*/
|
|
40
|
+
bankTransfer<R = BankTransferResult>(params: BankTransferParams, options?: CallOptions<BankTransferResult, R>): Promise<BankTransferResult | R>;
|
|
41
|
+
/**
|
|
42
|
+
* `POST /v2/transfers/bank/{subAccountId}`. Sends a bank transfer from a sub account. You must ask
|
|
43
|
+
* Nomba to profile you for sub account transfers.
|
|
44
|
+
* @param subAccountId The sub account to transfer from.
|
|
45
|
+
* @param params The destination bank, account number and amount; `merchantTxRef` is the idempotency key.
|
|
46
|
+
* @param options Outcome closures; without them, success resolves the result and pending/failure throws.
|
|
47
|
+
* @returns The transfer result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
48
|
+
* @throws {NombaError} The transfer was rejected (4xx) and never happened.
|
|
49
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
50
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
51
|
+
*/
|
|
52
|
+
bankTransferFromSubAccount<R = BankTransferResult>(subAccountId: string, params: BankTransferParams, options?: CallOptions<BankTransferResult, R>): Promise<BankTransferResult | R>;
|
|
53
|
+
/**
|
|
54
|
+
* `POST /v2/transfers/wallet`. Sends a wallet-to-wallet transfer from the parent account to another
|
|
55
|
+
* Nomba account.
|
|
56
|
+
* @param params The destination wallet and amount; `merchantTxRef` is the idempotency key.
|
|
57
|
+
* @param options Outcome closures; without them, success resolves the result and pending/failure throws.
|
|
58
|
+
* @returns The transfer result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
59
|
+
* @throws {NombaError} The transfer was rejected (4xx) and never happened.
|
|
60
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
61
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
62
|
+
*/
|
|
63
|
+
walletTransfer<R = WalletTransferResult>(params: WalletTransferParams, options?: CallOptions<WalletTransferResult, R>): Promise<WalletTransferResult | R>;
|
|
64
|
+
/**
|
|
65
|
+
* `POST /v2/transfers/wallet/{subAccountId}`. Sends a wallet-to-wallet transfer from a sub account.
|
|
66
|
+
* @param subAccountId The sub account to transfer from.
|
|
67
|
+
* @param params The destination wallet and amount; `merchantTxRef` is the idempotency key.
|
|
68
|
+
* @param options Outcome closures; without them, success resolves the result and pending/failure throws.
|
|
69
|
+
* @returns The transfer result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
70
|
+
* @throws {NombaError} The transfer was rejected (4xx) and never happened.
|
|
71
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
72
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
73
|
+
*/
|
|
74
|
+
walletTransferFromSubAccount<R = WalletTransferResult>(subAccountId: string, params: WalletTransferParams, options?: CallOptions<WalletTransferResult, R>): Promise<WalletTransferResult | R>;
|
|
75
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/services/v2/transfers
|
|
3
|
+
* @description Transfers (v2): POST /v2/transfers[/{subAccountId}]/*
|
|
4
|
+
* @see https://developer.nomba.com/docs/api-reference/transfers
|
|
5
|
+
*/
|
|
6
|
+
import { REJECTED, settle } from "../../../lib/outcome.js";
|
|
7
|
+
import { pathId } from "../../../lib/util.js";
|
|
8
|
+
// Documented for every transfer endpoint: code "200" done, "201" accepted and still processing; data.status
|
|
9
|
+
// SUCCESS or PENDING_BILLING. The docs say to treat any other status as pending, so it is never success or
|
|
10
|
+
// failed: it reaches onPending, or throws UnconfirmedOutcomeError when no onPending is passed. That includes
|
|
11
|
+
// REFUND and the other requery statuses, which this endpoint does not document.
|
|
12
|
+
const TRANSFER_OUTCOMES = {
|
|
13
|
+
codes: { "00": "success", "200": "success", "201": "pending", ...REJECTED },
|
|
14
|
+
statuses: { SUCCESS: "success", PENDING_BILLING: "pending" },
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Money movement. A call that throws a NombaError with a 4xx status was rejected and did nothing. Any other
|
|
18
|
+
* failure (5xx, network error, timeout) leaves the outcome unknown: keep the same `merchantTxRef`, wait for the
|
|
19
|
+
* webhook or requery, and never send the transfer again under a new reference.
|
|
20
|
+
*/
|
|
21
|
+
export class TransfersService {
|
|
22
|
+
http;
|
|
23
|
+
constructor(http) {
|
|
24
|
+
this.http = http;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* `GET /v1/transfers/banks`. Lists the banks usable as a transfer destination.
|
|
28
|
+
* @returns The supported banks, each with its name and code.
|
|
29
|
+
* @throws {NombaError} A non-2xx response.
|
|
30
|
+
*/
|
|
31
|
+
listBanks() {
|
|
32
|
+
return this.http.request("GET", "/v1/transfers/banks");
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* `POST /v1/transfers/bank/lookup`. Resolves a bank account number to its account name.
|
|
36
|
+
* @param params The bank code and account number to look up.
|
|
37
|
+
* @returns The resolved account name.
|
|
38
|
+
* @throws {NombaError} The lookup was rejected, e.g. an invalid account number.
|
|
39
|
+
*/
|
|
40
|
+
lookupBankAccount(params) {
|
|
41
|
+
return this.http.request("POST", "/v1/transfers/bank/lookup", {
|
|
42
|
+
body: params,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* `POST /v2/transfers/bank`. Sends a bank transfer from the parent account.
|
|
47
|
+
* @param params The destination bank, account number and amount; `merchantTxRef` is the idempotency key.
|
|
48
|
+
* @param options Outcome closures; without them, success resolves the result and pending/failure throws.
|
|
49
|
+
* @returns The transfer result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
50
|
+
* @throws {NombaError} The transfer was rejected (4xx) and never happened.
|
|
51
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
52
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
53
|
+
*/
|
|
54
|
+
async bankTransfer(params, options = {}) {
|
|
55
|
+
return settle(this.http, "POST", "/v2/transfers/bank", { body: params }, TRANSFER_OUTCOMES, params.merchantTxRef, options);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* `POST /v2/transfers/bank/{subAccountId}`. Sends a bank transfer from a sub account. You must ask
|
|
59
|
+
* Nomba to profile you for sub account transfers.
|
|
60
|
+
* @param subAccountId The sub account to transfer from.
|
|
61
|
+
* @param params The destination bank, account number and amount; `merchantTxRef` is the idempotency key.
|
|
62
|
+
* @param options Outcome closures; without them, success resolves the result and pending/failure throws.
|
|
63
|
+
* @returns The transfer result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
64
|
+
* @throws {NombaError} The transfer was rejected (4xx) and never happened.
|
|
65
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
66
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
67
|
+
*/
|
|
68
|
+
async bankTransferFromSubAccount(subAccountId, params, options = {}) {
|
|
69
|
+
return settle(this.http, "POST", `/v2/transfers/bank/${pathId(subAccountId)}`, { body: params }, TRANSFER_OUTCOMES, params.merchantTxRef, options);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* `POST /v2/transfers/wallet`. Sends a wallet-to-wallet transfer from the parent account to another
|
|
73
|
+
* Nomba account.
|
|
74
|
+
* @param params The destination wallet and amount; `merchantTxRef` is the idempotency key.
|
|
75
|
+
* @param options Outcome closures; without them, success resolves the result and pending/failure throws.
|
|
76
|
+
* @returns The transfer result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
77
|
+
* @throws {NombaError} The transfer was rejected (4xx) and never happened.
|
|
78
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
79
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
80
|
+
*/
|
|
81
|
+
async walletTransfer(params, options = {}) {
|
|
82
|
+
return settle(this.http, "POST", "/v2/transfers/wallet", { body: params }, TRANSFER_OUTCOMES, params.merchantTxRef, options);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* `POST /v2/transfers/wallet/{subAccountId}`. Sends a wallet-to-wallet transfer from a sub account.
|
|
86
|
+
* @param subAccountId The sub account to transfer from.
|
|
87
|
+
* @param params The destination wallet and amount; `merchantTxRef` is the idempotency key.
|
|
88
|
+
* @param options Outcome closures; without them, success resolves the result and pending/failure throws.
|
|
89
|
+
* @returns The transfer result, or whatever `options.onSuccess`/`onPending`/`onFailed` returns.
|
|
90
|
+
* @throws {NombaError} The transfer was rejected (4xx) and never happened.
|
|
91
|
+
* @throws {OutcomeUnknownError} The outcome could not be confirmed as success or failure.
|
|
92
|
+
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
93
|
+
*/
|
|
94
|
+
async walletTransferFromSubAccount(subAccountId, params, options = {}) {
|
|
95
|
+
return settle(this.http, "POST", `/v2/transfers/wallet/${pathId(subAccountId)}`, { body: params }, TRANSFER_OUTCOMES, params.merchantTxRef, options);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/types/common
|
|
3
|
+
* @description Types shared by the HTTP client and every service
|
|
4
|
+
*/
|
|
5
|
+
import type { TokenStore } from "../../lib/token-store.js";
|
|
6
|
+
import type { OutcomeEvent, OutcomeHandlers } from "./outcome.types.js";
|
|
7
|
+
export type Environment = "production" | "sandbox";
|
|
8
|
+
export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE";
|
|
9
|
+
export type Query = Record<string, string | number | boolean | undefined>;
|
|
10
|
+
export interface NombaOptions {
|
|
11
|
+
clientId: string;
|
|
12
|
+
clientSecret: string;
|
|
13
|
+
/** The parent accountId of the business. */
|
|
14
|
+
accountId: string;
|
|
15
|
+
/** Credentials and environment must match. Defaults to "production". */
|
|
16
|
+
environment?: Environment;
|
|
17
|
+
/** Where the token is kept. Defaults to an in-memory store; see TokenStore for multi-instance setups. */
|
|
18
|
+
tokenStore?: TokenStore;
|
|
19
|
+
/**
|
|
20
|
+
* Called when the token store fails. Requests keep working from this process's own copy of the
|
|
21
|
+
* token, so store errors never fail a call. Defaults to console.warn.
|
|
22
|
+
*/
|
|
23
|
+
onStoreError?: (error: unknown) => void;
|
|
24
|
+
/** Per-request timeout in milliseconds. Defaults to 30000. */
|
|
25
|
+
timeoutMs?: number;
|
|
26
|
+
/** Total tries per GET request (or any request hitting 429), including the first. Defaults to 3; 1 turns retries off. Mutating calls always make one attempt; see OutcomeUnknownError. */
|
|
27
|
+
maxAttempts?: number;
|
|
28
|
+
/** Delay before the first retry in milliseconds; it doubles each time. Defaults to 500. */
|
|
29
|
+
retryDelayMs?: number;
|
|
30
|
+
/** The fetch used for every call, e.g. to add a proxy or tracing. Defaults to the global fetch. */
|
|
31
|
+
fetch?: typeof fetch;
|
|
32
|
+
/** Called before each HTTP attempt. For logging and metrics; errors it throws are logged, never raised. */
|
|
33
|
+
onRequest?: (info: RequestInfo) => void;
|
|
34
|
+
/** Called after each HTTP attempt that got a response. Errors it throws are logged, never raised. */
|
|
35
|
+
onResponse?: (info: ResponseInfo) => void;
|
|
36
|
+
/** Called once per money-moving call with how it ended, e.g. to alert on pending or failed payments. */
|
|
37
|
+
onOutcome?: (event: OutcomeEvent) => void;
|
|
38
|
+
}
|
|
39
|
+
export type RequestInfo = {
|
|
40
|
+
method: string;
|
|
41
|
+
path: string;
|
|
42
|
+
attempt: number;
|
|
43
|
+
};
|
|
44
|
+
export type ResponseInfo = RequestInfo & {
|
|
45
|
+
httpStatus: number;
|
|
46
|
+
code?: string;
|
|
47
|
+
durationMs: number;
|
|
48
|
+
};
|
|
49
|
+
/** Options for one authenticated call made through IHttpClient.request. */
|
|
50
|
+
export type HttpRequestOptions = {
|
|
51
|
+
body?: unknown;
|
|
52
|
+
query?: Query;
|
|
53
|
+
/** Body codes that are not errors. Defaults to ["00"]. */
|
|
54
|
+
okCodes?: string[];
|
|
55
|
+
codeField?: string;
|
|
56
|
+
descriptionField?: string;
|
|
57
|
+
/** Resolve `{ code, data }` instead of `data`, so the caller can classify the body code. */
|
|
58
|
+
envelope?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Tracked in `OutcomeUnknownError` so callers know which transaction to requery. Services derive
|
|
61
|
+
* this from params (e.g., `merchantTxRef`). A random UUID is generated if omitted.
|
|
62
|
+
*/
|
|
63
|
+
idempotencyKey?: string;
|
|
64
|
+
};
|
|
65
|
+
/** What request() resolves with `envelope: true`. */
|
|
66
|
+
export type ResponseEnvelope<T> = {
|
|
67
|
+
code: string;
|
|
68
|
+
data: T;
|
|
69
|
+
};
|
|
70
|
+
/** The API also accepts lowercase values (glo, mtn, ...). */
|
|
71
|
+
export type Upper = "GLO" | "MTN" | "9MOBILE" | "AIRTEL";
|
|
72
|
+
export type Network = Upper | Lowercase<Upper>;
|
|
73
|
+
/** Options for a money-moving call: outcome closures (`onSuccess`, `onPending`, `onFailed`). */
|
|
74
|
+
export type CallOptions<T, R = T> = OutcomeHandlers<T, R>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/types/common/outcome
|
|
3
|
+
* @description How a money-moving call ended, and the closures a caller can pass to handle it
|
|
4
|
+
*/
|
|
5
|
+
import type { NombaError } from "../../lib/errors.js";
|
|
6
|
+
import type { HttpMethod } from "./common.types.js";
|
|
7
|
+
/**
|
|
8
|
+
* - success: done; safe to fulfil the order.
|
|
9
|
+
* - pending: not final, or not one the docs list. Do not act on it: wait for the webhook or requery.
|
|
10
|
+
* - failed: a definite rejection or a documented REFUND. Safe to tell the customer it failed.
|
|
11
|
+
*/
|
|
12
|
+
export type Outcome = "success" | "pending" | "failed";
|
|
13
|
+
/** The body codes and `data.status` values one endpoint documents. Anything missing is pending. */
|
|
14
|
+
export type OutcomeTable = {
|
|
15
|
+
codes: Readonly<Record<string, Outcome>>;
|
|
16
|
+
statuses?: Readonly<Record<string, Outcome>>;
|
|
17
|
+
/** Where the status lives in `data`. Defaults to `data.status` when it is a string. */
|
|
18
|
+
statusOf?: (data: unknown) => string | undefined;
|
|
19
|
+
};
|
|
20
|
+
export type PendingInfo<T> = {
|
|
21
|
+
/** The response `data`, when a readable response came back. */
|
|
22
|
+
data?: T;
|
|
23
|
+
code?: string;
|
|
24
|
+
status?: string;
|
|
25
|
+
idempotencyKey?: string;
|
|
26
|
+
/** Why the call is pending when no readable response came back (OutcomeUnknownError, UnconfirmedOutcomeError). */
|
|
27
|
+
cause?: unknown;
|
|
28
|
+
};
|
|
29
|
+
export type FailedInfo<_T = unknown> = {
|
|
30
|
+
error: NombaError;
|
|
31
|
+
data?: undefined;
|
|
32
|
+
code: string;
|
|
33
|
+
status?: undefined;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Closures for one money-moving call. The call resolves to what the matching closure returns. A missing
|
|
37
|
+
* closure keeps the default: resolve `data`, or throw on a rejection or an undocumented code/status.
|
|
38
|
+
* Errors thrown inside a closure reach the caller untouched.
|
|
39
|
+
*/
|
|
40
|
+
export type OutcomeHandlers<T, R = T> = {
|
|
41
|
+
onSuccess?: (data: T) => R | Promise<R>;
|
|
42
|
+
onPending?: (info: PendingInfo<T>) => R | Promise<R>;
|
|
43
|
+
onFailed?: (info: FailedInfo<T>) => R | Promise<R>;
|
|
44
|
+
};
|
|
45
|
+
/** What NombaOptions.onOutcome receives for every money-moving call. */
|
|
46
|
+
export type OutcomeEvent = {
|
|
47
|
+
method: HttpMethod;
|
|
48
|
+
path: string;
|
|
49
|
+
outcome: Outcome;
|
|
50
|
+
code?: string;
|
|
51
|
+
status?: string;
|
|
52
|
+
idempotencyKey?: string;
|
|
53
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/types/accounts
|
|
3
|
+
* @description Nomba SDK for Node.js
|
|
4
|
+
* @description Accounts types
|
|
5
|
+
* @author Nomba Financial Services
|
|
6
|
+
* @version 1.0.0
|
|
7
|
+
*/
|
|
8
|
+
export type AccountStatus = "ACTIVE" | "INACTIVE" | "SUSPENDED" | "PND" | "BLACKLISTED";
|
|
9
|
+
export type AccountType = "virtual" | "outlet";
|
|
10
|
+
export type SubAccountLookup = {
|
|
11
|
+
/** The id of the sub account. */
|
|
12
|
+
accountId?: string;
|
|
13
|
+
/** The unique reference you passed when creating the sub account. */
|
|
14
|
+
accountRef?: string;
|
|
15
|
+
};
|
|
16
|
+
export type AccountBalance = {
|
|
17
|
+
/** Decimal string, e.g. "281946.0" */
|
|
18
|
+
amount: string;
|
|
19
|
+
currency: "NGN";
|
|
20
|
+
timeCreated: string;
|
|
21
|
+
};
|
|
22
|
+
export type AccountDetails = {
|
|
23
|
+
createdAt: string;
|
|
24
|
+
accountId: string;
|
|
25
|
+
accountHolderId: string;
|
|
26
|
+
accountRef: string;
|
|
27
|
+
bvn: string;
|
|
28
|
+
status: AccountStatus;
|
|
29
|
+
type: AccountType;
|
|
30
|
+
accountName: string;
|
|
31
|
+
currency: "NGN";
|
|
32
|
+
banks: {
|
|
33
|
+
bankAccountNumber: string;
|
|
34
|
+
bankName: string;
|
|
35
|
+
bankAccountName: string;
|
|
36
|
+
}[];
|
|
37
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/types/v1/betting
|
|
3
|
+
* @description Betting v1 validation types
|
|
4
|
+
*/
|
|
5
|
+
export type BettingProvider = {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
biller_id: string;
|
|
9
|
+
lookup_id: string;
|
|
10
|
+
amount?: string;
|
|
11
|
+
};
|
|
12
|
+
export type BettingProvidersResult = {
|
|
13
|
+
code: string;
|
|
14
|
+
description: string;
|
|
15
|
+
message: string;
|
|
16
|
+
data: BettingProvider[];
|
|
17
|
+
};
|
|
18
|
+
export type BettingCustomerLookupParams = {
|
|
19
|
+
bettingProvider: string;
|
|
20
|
+
customerId: string;
|
|
21
|
+
};
|
|
22
|
+
export type BettingCustomerLookupResult = {
|
|
23
|
+
code: string;
|
|
24
|
+
/** Customer name associated with the betting account */
|
|
25
|
+
data: string;
|
|
26
|
+
};
|