@nomba/node-sdk 0.0.0-stage → 0.1.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 +550 -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 +24 -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 +11 -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 +11 -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 +33 -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 +30 -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 +9 -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 +31 -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 +11 -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 +14 -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 +30 -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 +17 -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 +18 -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 +34 -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 +27 -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 +21 -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 +12 -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 +12 -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 +12 -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 +12 -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 +12 -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 +20 -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 +18 -0
- package/dist/lib/outcome.js +107 -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 +63 -0
- package/dist/nomba.js +97 -0
- package/dist/services/http/http-client.service.d.ts +27 -0
- package/dist/services/http/http-client.service.js +317 -0
- package/dist/services/v1/accounts/accounts.service.d.ts +38 -0
- package/dist/services/v1/accounts/accounts.service.js +58 -0
- package/dist/services/v1/betting/betting.service.d.ts +16 -0
- package/dist/services/v1/betting/betting.service.js +21 -0
- package/dist/services/v1/cable/cable.service.d.ts +16 -0
- package/dist/services/v1/cable/cable.service.js +23 -0
- package/dist/services/v1/charge/charge.service.d.ts +52 -0
- package/dist/services/v1/charge/charge.service.js +99 -0
- package/dist/services/v1/checkout/checkout.service.d.ts +44 -0
- package/dist/services/v1/checkout/checkout.service.js +100 -0
- package/dist/services/v1/data/data.service.d.ts +14 -0
- package/dist/services/v1/data/data.service.js +16 -0
- package/dist/services/v1/direct-debits/direct-debits.service.d.ts +45 -0
- package/dist/services/v1/direct-debits/direct-debits.service.js +69 -0
- package/dist/services/v1/electricity/electricity.service.d.ts +16 -0
- package/dist/services/v1/electricity/electricity.service.js +21 -0
- package/dist/services/v1/globals/collections.service.d.ts +28 -0
- package/dist/services/v1/globals/collections.service.js +38 -0
- package/dist/services/v1/globals/payout.service.d.ts +45 -0
- package/dist/services/v1/globals/payout.service.js +95 -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 +69 -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 +41 -0
- package/dist/services/v1/virtual-accounts/virtual-accounts.service.js +56 -0
- package/dist/services/v1/webhooks/webhooks.service.d.ts +36 -0
- package/dist/services/v1/webhooks/webhooks.service.js +60 -0
- package/dist/services/v2/airtime/airtime.service.d.ts +18 -0
- package/dist/services/v2/airtime/airtime.service.js +35 -0
- package/dist/services/v2/betting/betting.service.d.ts +19 -0
- package/dist/services/v2/betting/betting.service.js +36 -0
- package/dist/services/v2/cable/cable.service.d.ts +19 -0
- package/dist/services/v2/cable/cable.service.js +36 -0
- package/dist/services/v2/data/data.service.d.ts +18 -0
- package/dist/services/v2/data/data.service.js +35 -0
- package/dist/services/v2/electricity/electricity.service.d.ts +19 -0
- package/dist/services/v2/electricity/electricity.service.js +36 -0
- package/dist/services/v2/transfers/transfers.service.d.ts +30 -0
- package/dist/services/v2/transfers/transfers.service.js +67 -0
- package/dist/types/common/common.types.d.ts +78 -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/virtual-accounts
|
|
3
|
+
* @description Nomba SDK for Node.js
|
|
4
|
+
* @description Virtual Accounts resource
|
|
5
|
+
* @author Nomba Financial Services
|
|
6
|
+
* @version 1.0.0
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @copyright 2026 Nomba
|
|
9
|
+
* @homepage https://nomba.com
|
|
10
|
+
* @support https://nomba.com/support
|
|
11
|
+
* @repository https://github.com/kudi-inc/nomba-sdk-node
|
|
12
|
+
* @docs https://developer.nomba.com
|
|
13
|
+
* @see https://developer.nomba.com/docs/api-reference/virtual-accounts
|
|
14
|
+
*/
|
|
15
|
+
import { paginate } from "../../../lib/paginate.js";
|
|
16
|
+
import { pageQuery, pathId } from "../../../lib/util.js";
|
|
17
|
+
export class VirtualAccountsService {
|
|
18
|
+
http;
|
|
19
|
+
constructor(http) {
|
|
20
|
+
this.http = http;
|
|
21
|
+
}
|
|
22
|
+
/** POST /v1/accounts/virtual */
|
|
23
|
+
create(params, options = {}) {
|
|
24
|
+
return this.http.request("POST", "/v1/accounts/virtual", {
|
|
25
|
+
body: params,
|
|
26
|
+
...options,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/** POST /v1/accounts/virtual/{subAccountId}. Funds are collected in that sub account. */
|
|
30
|
+
async createForSubAccount(subAccountId, params, options = {}) {
|
|
31
|
+
return this.http.request("POST", `/v1/accounts/virtual/${pathId(subAccountId)}`, { body: params, ...options });
|
|
32
|
+
}
|
|
33
|
+
/** GET /v1/accounts/virtual/{identifier}. `identifier` is the accountRef or the virtual account number. */
|
|
34
|
+
async get(identifier) {
|
|
35
|
+
return this.http.request("GET", `/v1/accounts/virtual/${pathId(identifier)}`);
|
|
36
|
+
}
|
|
37
|
+
/** PUT /v1/accounts/virtual/{identifier}. `identifier` is the accountRef or the 10 digit account number. */
|
|
38
|
+
async update(identifier, params, options = {}) {
|
|
39
|
+
return this.http.request("PUT", `/v1/accounts/virtual/${pathId(identifier)}`, { body: params, ...options });
|
|
40
|
+
}
|
|
41
|
+
/** DELETE /v1/accounts/virtual/{identifier}. Stops the account accepting payments. */
|
|
42
|
+
async expire(identifier, options = {}) {
|
|
43
|
+
return this.http.request("DELETE", `/v1/accounts/virtual/${pathId(identifier)}`, options);
|
|
44
|
+
}
|
|
45
|
+
/** POST /v1/accounts/virtual/list */
|
|
46
|
+
list(filter = {}, page = {}) {
|
|
47
|
+
return this.http.request("POST", "/v1/accounts/virtual/list", {
|
|
48
|
+
body: filter,
|
|
49
|
+
query: pageQuery(page),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/** Every matching virtual account, across all pages. Starts at `page.cursor` if given. */
|
|
53
|
+
iterate(filter = {}, page = {}) {
|
|
54
|
+
return paginate((cursor) => this.list(filter, cursor ? { ...page, cursor } : page));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/webhooks
|
|
3
|
+
* @description Nomba SDK for Node.js
|
|
4
|
+
* @description Webhooks resource: delivery logs, re-push and replay
|
|
5
|
+
* @author Nomba Financial Services
|
|
6
|
+
* @version 1.0.0
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @copyright 2026 Nomba
|
|
9
|
+
* @homepage https://nomba.com
|
|
10
|
+
* @support https://nomba.com/support
|
|
11
|
+
* @repository https://github.com/kudi-inc/nomba-sdk-node
|
|
12
|
+
* @docs https://developer.nomba.com
|
|
13
|
+
* @see https://developer.nomba.com/docs/api-basics/troubleshoot-webhooks
|
|
14
|
+
*/
|
|
15
|
+
import type { IHttpClient } from "../../../interfaces/http/IHttpClient.js";
|
|
16
|
+
import type { IWebhooksService } from "../../../interfaces/v1/webhooks/IWebhooksService.js";
|
|
17
|
+
import type { RequestOptions } from "../../../types/common/common.types.js";
|
|
18
|
+
import type { EventLog, EventLogsParams, EventsParams, ReplayParams, WebhookList, WebhookSubscription } from "../../../types/v1/webhooks/webhooks.types.js";
|
|
19
|
+
export declare class WebhooksService implements IWebhooksService {
|
|
20
|
+
#private;
|
|
21
|
+
private readonly http;
|
|
22
|
+
constructor(http: IHttpClient);
|
|
23
|
+
/** POST /v1/webhooks/event-logs. Webhooks sent to your system and how your server answered. */
|
|
24
|
+
eventLogs(params?: EventLogsParams): Promise<WebhookList<EventLog>>;
|
|
25
|
+
/** POST /v1/webhooks/events. Your webhook subscriptions. */
|
|
26
|
+
events(params?: EventsParams): Promise<WebhookList<WebhookSubscription>>;
|
|
27
|
+
/**
|
|
28
|
+
* POST /v1/webhooks/re-push. Resends one event. Takes an event log's `hookRequestId`; the request field
|
|
29
|
+
* is spelled `hooksRequestId`, as the guide shows.
|
|
30
|
+
*/
|
|
31
|
+
repush(hookRequestId: string, options?: RequestOptions): Promise<void>;
|
|
32
|
+
/** POST /v1/webhooks/bulk-re-push */
|
|
33
|
+
bulkRepush(hookRequestIds: string[], options?: RequestOptions): Promise<void>;
|
|
34
|
+
/** POST /v1/webhooks/replay. Resends every matching event in the time window. */
|
|
35
|
+
replay(params: ReplayParams, options?: RequestOptions): Promise<void>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/webhooks
|
|
3
|
+
* @description Nomba SDK for Node.js
|
|
4
|
+
* @description Webhooks resource: delivery logs, re-push and replay
|
|
5
|
+
* @author Nomba Financial Services
|
|
6
|
+
* @version 1.0.0
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @copyright 2026 Nomba
|
|
9
|
+
* @homepage https://nomba.com
|
|
10
|
+
* @support https://nomba.com/support
|
|
11
|
+
* @repository https://github.com/kudi-inc/nomba-sdk-node
|
|
12
|
+
* @docs https://developer.nomba.com
|
|
13
|
+
* @see https://developer.nomba.com/docs/api-basics/troubleshoot-webhooks
|
|
14
|
+
*/
|
|
15
|
+
// Documented in the guide only (no API reference page). Its examples answer code "200", not "00", and never
|
|
16
|
+
// mark request fields as required, so every field is optional here.
|
|
17
|
+
const OK_CODES = ["00", "200"];
|
|
18
|
+
export class WebhooksService {
|
|
19
|
+
http;
|
|
20
|
+
constructor(http) {
|
|
21
|
+
this.http = http;
|
|
22
|
+
}
|
|
23
|
+
/** POST /v1/webhooks/event-logs. Webhooks sent to your system and how your server answered. */
|
|
24
|
+
eventLogs(params = {}) {
|
|
25
|
+
return this.http.request("POST", "/v1/webhooks/event-logs", {
|
|
26
|
+
body: params,
|
|
27
|
+
okCodes: OK_CODES,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/** POST /v1/webhooks/events. Your webhook subscriptions. */
|
|
31
|
+
events(params = {}) {
|
|
32
|
+
return this.http.request("POST", "/v1/webhooks/events", {
|
|
33
|
+
body: params,
|
|
34
|
+
okCodes: OK_CODES,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* POST /v1/webhooks/re-push. Resends one event. Takes an event log's `hookRequestId`; the request field
|
|
39
|
+
* is spelled `hooksRequestId`, as the guide shows.
|
|
40
|
+
*/
|
|
41
|
+
repush(hookRequestId, options = {}) {
|
|
42
|
+
return this.#post("re-push", { hooksRequestId: hookRequestId }, options);
|
|
43
|
+
}
|
|
44
|
+
/** POST /v1/webhooks/bulk-re-push */
|
|
45
|
+
bulkRepush(hookRequestIds, options = {}) {
|
|
46
|
+
return this.#post("bulk-re-push", { hooksRequestIds: hookRequestIds }, options);
|
|
47
|
+
}
|
|
48
|
+
/** POST /v1/webhooks/replay. Resends every matching event in the time window. */
|
|
49
|
+
replay(params, options = {}) {
|
|
50
|
+
return this.#post("replay", params, options);
|
|
51
|
+
}
|
|
52
|
+
// These answer with no `data`, so the client resolves to undefined.
|
|
53
|
+
#post(path, body, options) {
|
|
54
|
+
return this.http.request("POST", `/v1/webhooks/${path}`, {
|
|
55
|
+
body,
|
|
56
|
+
okCodes: OK_CODES,
|
|
57
|
+
...options,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/services/v2/airtime
|
|
3
|
+
* @description AirtimeV2 (v2): POST /v2/bill/topup
|
|
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 { IAirtimeV2Service } from "../../../interfaces/v2/airtime/index.js";
|
|
8
|
+
import type { CallOptions } from "../../../types/common/common.types.js";
|
|
9
|
+
import type { AirtimePurchaseParams, AirtimePurchaseV2Result } from "../../../types/v2/airtime/airtime.types.js";
|
|
10
|
+
export declare class AirtimeV2Service implements IAirtimeV2Service {
|
|
11
|
+
#private;
|
|
12
|
+
private readonly http;
|
|
13
|
+
constructor(http: IHttpClient);
|
|
14
|
+
/** POST /v2/bill/topup, from the parent account. */
|
|
15
|
+
buyAirtime<R = AirtimePurchaseV2Result>(params: AirtimePurchaseParams, options?: CallOptions<AirtimePurchaseV2Result, R>): Promise<AirtimePurchaseV2Result | R>;
|
|
16
|
+
/** POST /v2/bill/topup/{subAccountId}. Buys airtime from a sub account. */
|
|
17
|
+
buyAirtimeFromSubAccount<R = AirtimePurchaseV2Result>(subAccountId: string, params: AirtimePurchaseParams, options?: CallOptions<AirtimePurchaseV2Result, R>): Promise<AirtimePurchaseV2Result | R>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/services/v2/airtime
|
|
3
|
+
* @description AirtimeV2 (v2): POST /v2/bill/topup
|
|
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
|
+
export class AirtimeV2Service {
|
|
16
|
+
http;
|
|
17
|
+
constructor(http) {
|
|
18
|
+
this.http = http;
|
|
19
|
+
}
|
|
20
|
+
/** POST /v2/bill/topup, from the parent account. */
|
|
21
|
+
async buyAirtime(params, options = {}) {
|
|
22
|
+
return this.#buy("/v2/bill/topup", params, options);
|
|
23
|
+
}
|
|
24
|
+
/** POST /v2/bill/topup/{subAccountId}. Buys airtime from a sub account. */
|
|
25
|
+
async buyAirtimeFromSubAccount(subAccountId, params, options = {}) {
|
|
26
|
+
return this.#buy(`/v2/bill/topup/${pathId(subAccountId)}`, params, options);
|
|
27
|
+
}
|
|
28
|
+
// merchantTxRef is the default idempotency key, as for every bill payment.
|
|
29
|
+
#buy(path, params, options) {
|
|
30
|
+
return settle(this.http, "POST", path, { body: params }, OUTCOMES, {
|
|
31
|
+
...options,
|
|
32
|
+
idempotencyKey: options.idempotencyKey ?? params.merchantTxRef,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/services/v2/betting
|
|
3
|
+
* @description BettingV2 (v2): POST /v2/bill/betting[/{subAccountId}]
|
|
4
|
+
* @see https://developer.nomba.com/docs/api-reference/bills
|
|
5
|
+
*/
|
|
6
|
+
import type { IHttpClient } from "../../../interfaces/http/IHttpClient.js";
|
|
7
|
+
import type { IBettingV2Service } from "../../../interfaces/v2/betting/index.js";
|
|
8
|
+
import type { CallOptions } from "../../../types/common/common.types.js";
|
|
9
|
+
import type { BettingPaymentParams, BettingPaymentV2Result } from "../../../types/v2/betting/betting.types.js";
|
|
10
|
+
/** v2 has purchase endpoints only. */
|
|
11
|
+
export declare class BettingV2Service implements IBettingV2Service {
|
|
12
|
+
#private;
|
|
13
|
+
private readonly http;
|
|
14
|
+
constructor(http: IHttpClient);
|
|
15
|
+
/** POST /v2/bill/betting, from the parent account. */
|
|
16
|
+
payBetting<R = BettingPaymentV2Result>(params: BettingPaymentParams, options?: CallOptions<BettingPaymentV2Result, R>): Promise<BettingPaymentV2Result | R>;
|
|
17
|
+
/** POST /v2/bill/betting/{subAccountId}. Pays from a sub account. */
|
|
18
|
+
payBettingFromSubAccount<R = BettingPaymentV2Result>(subAccountId: string, params: BettingPaymentParams, options?: CallOptions<BettingPaymentV2Result, R>): Promise<BettingPaymentV2Result | R>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module nomba/services/v2/betting
|
|
3
|
+
* @description BettingV2 (v2): POST /v2/bill/betting[/{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. Sandbox calls (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
|
+
/** v2 has purchase endpoints only. */
|
|
16
|
+
export class BettingV2Service {
|
|
17
|
+
http;
|
|
18
|
+
constructor(http) {
|
|
19
|
+
this.http = http;
|
|
20
|
+
}
|
|
21
|
+
/** POST /v2/bill/betting, from the parent account. */
|
|
22
|
+
async payBetting(params, options = {}) {
|
|
23
|
+
return this.#pay("/v2/bill/betting", params, options);
|
|
24
|
+
}
|
|
25
|
+
/** POST /v2/bill/betting/{subAccountId}. Pays from a sub account. */
|
|
26
|
+
async payBettingFromSubAccount(subAccountId, params, options = {}) {
|
|
27
|
+
return this.#pay(`/v2/bill/betting/${pathId(subAccountId)}`, params, options);
|
|
28
|
+
}
|
|
29
|
+
// merchantTxRef is the default idempotency key, as for every bill payment.
|
|
30
|
+
#pay(path, params, options) {
|
|
31
|
+
return settle(this.http, "POST", path, { body: params }, OUTCOMES, {
|
|
32
|
+
...options,
|
|
33
|
+
idempotencyKey: options.idempotencyKey ?? params.merchantTxRef,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 type { IHttpClient } from "../../../interfaces/http/IHttpClient.js";
|
|
7
|
+
import type { ICableV2Service } from "../../../interfaces/v2/cable/index.js";
|
|
8
|
+
import type { CallOptions } from "../../../types/common/common.types.js";
|
|
9
|
+
import type { CablePaymentV2Result, CableTvSubscriptionParams } from "../../../types/v2/cable/cable.types.js";
|
|
10
|
+
/** v2 has purchase endpoints only. */
|
|
11
|
+
export declare class CableV2Service implements ICableV2Service {
|
|
12
|
+
#private;
|
|
13
|
+
private readonly http;
|
|
14
|
+
constructor(http: IHttpClient);
|
|
15
|
+
/** POST /v2/bill/cabletv, from the parent account. */
|
|
16
|
+
subscribeCableTv<R = CablePaymentV2Result>(params: CableTvSubscriptionParams, options?: CallOptions<CablePaymentV2Result, R>): Promise<CablePaymentV2Result | R>;
|
|
17
|
+
/** POST /v2/bill/cabletv/{subAccountId}. Pays from a sub account. */
|
|
18
|
+
subscribeCableTvFromSubAccount<R = CablePaymentV2Result>(subAccountId: string, params: CableTvSubscriptionParams, options?: CallOptions<CablePaymentV2Result, R>): Promise<CablePaymentV2Result | R>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
/** v2 has purchase endpoints only. */
|
|
16
|
+
export class CableV2Service {
|
|
17
|
+
http;
|
|
18
|
+
constructor(http) {
|
|
19
|
+
this.http = http;
|
|
20
|
+
}
|
|
21
|
+
/** POST /v2/bill/cabletv, from the parent account. */
|
|
22
|
+
async subscribeCableTv(params, options = {}) {
|
|
23
|
+
return this.#pay("/v2/bill/cabletv", params, options);
|
|
24
|
+
}
|
|
25
|
+
/** POST /v2/bill/cabletv/{subAccountId}. Pays from a sub account. */
|
|
26
|
+
async subscribeCableTvFromSubAccount(subAccountId, params, options = {}) {
|
|
27
|
+
return this.#pay(`/v2/bill/cabletv/${pathId(subAccountId)}`, params, options);
|
|
28
|
+
}
|
|
29
|
+
// merchantTxRef is the default idempotency key, as for every bill payment.
|
|
30
|
+
#pay(path, params, options) {
|
|
31
|
+
return settle(this.http, "POST", path, { body: params }, OUTCOMES, {
|
|
32
|
+
...options,
|
|
33
|
+
idempotencyKey: options.idempotencyKey ?? params.merchantTxRef,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
export declare class DataV2Service implements IDataV2Service {
|
|
11
|
+
#private;
|
|
12
|
+
private readonly http;
|
|
13
|
+
constructor(http: IHttpClient);
|
|
14
|
+
/** POST /v2/bill/data, from the parent account. */
|
|
15
|
+
buyData<R = DataPurchaseV2Result>(params: DataPurchaseParams, options?: CallOptions<DataPurchaseV2Result, R>): Promise<DataPurchaseV2Result | R>;
|
|
16
|
+
/** POST /v2/bill/data/{subAccountId}. Buys a data bundle from a sub account. */
|
|
17
|
+
buyDataFromSubAccount<R = DataPurchaseV2Result>(subAccountId: string, params: DataPurchaseParams, options?: CallOptions<DataPurchaseV2Result, R>): Promise<DataPurchaseV2Result | R>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
export class DataV2Service {
|
|
16
|
+
http;
|
|
17
|
+
constructor(http) {
|
|
18
|
+
this.http = http;
|
|
19
|
+
}
|
|
20
|
+
/** POST /v2/bill/data, from the parent account. */
|
|
21
|
+
async buyData(params, options = {}) {
|
|
22
|
+
return this.#buy("/v2/bill/data", params, options);
|
|
23
|
+
}
|
|
24
|
+
/** POST /v2/bill/data/{subAccountId}. Buys a data bundle from a sub account. */
|
|
25
|
+
async buyDataFromSubAccount(subAccountId, params, options = {}) {
|
|
26
|
+
return this.#buy(`/v2/bill/data/${pathId(subAccountId)}`, params, options);
|
|
27
|
+
}
|
|
28
|
+
// merchantTxRef is the default idempotency key, as for every bill payment.
|
|
29
|
+
#buy(path, params, options) {
|
|
30
|
+
return settle(this.http, "POST", path, { body: params }, OUTCOMES, {
|
|
31
|
+
...options,
|
|
32
|
+
idempotencyKey: options.idempotencyKey ?? params.merchantTxRef,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
/** v2 has purchase endpoints only. */
|
|
11
|
+
export declare class ElectricityV2Service implements IElectricityV2Service {
|
|
12
|
+
#private;
|
|
13
|
+
private readonly http;
|
|
14
|
+
constructor(http: IHttpClient);
|
|
15
|
+
/** POST /v2/bill/electricity, from the parent account. Prepaid meters get the token in `meta.phcnToken`. */
|
|
16
|
+
payElectricity<R = ElectricityPaymentV2Result>(params: ElectricityPaymentParams, options?: CallOptions<ElectricityPaymentV2Result, R>): Promise<ElectricityPaymentV2Result | R>;
|
|
17
|
+
/** POST /v2/bill/electricity/{subAccountId}. Pays from a sub account. */
|
|
18
|
+
payElectricityFromSubAccount<R = ElectricityPaymentV2Result>(subAccountId: string, params: ElectricityPaymentParams, options?: CallOptions<ElectricityPaymentV2Result, R>): Promise<ElectricityPaymentV2Result | R>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
/** v2 has purchase endpoints only. */
|
|
16
|
+
export class ElectricityV2Service {
|
|
17
|
+
http;
|
|
18
|
+
constructor(http) {
|
|
19
|
+
this.http = http;
|
|
20
|
+
}
|
|
21
|
+
/** POST /v2/bill/electricity, from the parent account. Prepaid meters get the token in `meta.phcnToken`. */
|
|
22
|
+
async payElectricity(params, options = {}) {
|
|
23
|
+
return this.#pay("/v2/bill/electricity", params, options);
|
|
24
|
+
}
|
|
25
|
+
/** POST /v2/bill/electricity/{subAccountId}. Pays from a sub account. */
|
|
26
|
+
async payElectricityFromSubAccount(subAccountId, params, options = {}) {
|
|
27
|
+
return this.#pay(`/v2/bill/electricity/${pathId(subAccountId)}`, params, options);
|
|
28
|
+
}
|
|
29
|
+
// merchantTxRef is the default idempotency key, as for every bill payment.
|
|
30
|
+
#pay(path, params, options) {
|
|
31
|
+
return settle(this.http, "POST", path, { body: params }, OUTCOMES, {
|
|
32
|
+
...options,
|
|
33
|
+
idempotencyKey: options.idempotencyKey ?? params.merchantTxRef,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
/** GET /v1/transfers/banks */
|
|
19
|
+
listBanks(): Promise<Bank[]>;
|
|
20
|
+
/** POST /v1/transfers/bank/lookup */
|
|
21
|
+
lookupBankAccount(params: BankAccountLookupParams): Promise<BankAccountLookupResult>;
|
|
22
|
+
/** POST /v2/transfers/bank, from the parent account. */
|
|
23
|
+
bankTransfer<R = BankTransferResult>(params: BankTransferParams, options?: CallOptions<BankTransferResult, R>): Promise<BankTransferResult | R>;
|
|
24
|
+
/** POST /v2/transfers/bank/{subAccountId}. You must ask Nomba to profile you for sub account transfers. */
|
|
25
|
+
bankTransferFromSubAccount<R = BankTransferResult>(subAccountId: string, params: BankTransferParams, options?: CallOptions<BankTransferResult, R>): Promise<BankTransferResult | R>;
|
|
26
|
+
/** POST /v2/transfers/wallet, from the parent account to another Nomba account. */
|
|
27
|
+
walletTransfer<R = WalletTransferResult>(params: WalletTransferParams, options?: CallOptions<WalletTransferResult, R>): Promise<WalletTransferResult | R>;
|
|
28
|
+
/** POST /v2/transfers/wallet/{subAccountId} */
|
|
29
|
+
walletTransferFromSubAccount<R = WalletTransferResult>(subAccountId: string, params: WalletTransferParams, options?: CallOptions<WalletTransferResult, R>): Promise<WalletTransferResult | R>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
// The idempotency key tracked for error reporting. Nomba uses merchantTxRef (in the request body) for actual
|
|
17
|
+
// deduplication, and it is stable across your own retries, so it is the default. Callers can override it per call.
|
|
18
|
+
const idempotencyKeyFor = (params) => params.merchantTxRef;
|
|
19
|
+
/**
|
|
20
|
+
* Money movement. A call that throws a NombaError with a 4xx status was rejected and did nothing. Any other
|
|
21
|
+
* failure (5xx, network error, timeout) leaves the outcome unknown: keep the same `merchantTxRef`, wait for the
|
|
22
|
+
* webhook or requery, and never send the transfer again under a new reference.
|
|
23
|
+
*/
|
|
24
|
+
export class TransfersService {
|
|
25
|
+
http;
|
|
26
|
+
constructor(http) {
|
|
27
|
+
this.http = http;
|
|
28
|
+
}
|
|
29
|
+
/** GET /v1/transfers/banks */
|
|
30
|
+
listBanks() {
|
|
31
|
+
return this.http.request("GET", "/v1/transfers/banks");
|
|
32
|
+
}
|
|
33
|
+
/** POST /v1/transfers/bank/lookup */
|
|
34
|
+
lookupBankAccount(params) {
|
|
35
|
+
return this.http.request("POST", "/v1/transfers/bank/lookup", {
|
|
36
|
+
body: params,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** POST /v2/transfers/bank, from the parent account. */
|
|
40
|
+
async bankTransfer(params, options = {}) {
|
|
41
|
+
return settle(this.http, "POST", "/v2/transfers/bank", { body: params }, TRANSFER_OUTCOMES, {
|
|
42
|
+
...options,
|
|
43
|
+
idempotencyKey: options.idempotencyKey ?? idempotencyKeyFor(params),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/** POST /v2/transfers/bank/{subAccountId}. You must ask Nomba to profile you for sub account transfers. */
|
|
47
|
+
async bankTransferFromSubAccount(subAccountId, params, options = {}) {
|
|
48
|
+
return settle(this.http, "POST", `/v2/transfers/bank/${pathId(subAccountId)}`, { body: params }, TRANSFER_OUTCOMES, {
|
|
49
|
+
...options,
|
|
50
|
+
idempotencyKey: options.idempotencyKey ?? idempotencyKeyFor(params),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** POST /v2/transfers/wallet, from the parent account to another Nomba account. */
|
|
54
|
+
async walletTransfer(params, options = {}) {
|
|
55
|
+
return settle(this.http, "POST", "/v2/transfers/wallet", { body: params }, TRANSFER_OUTCOMES, {
|
|
56
|
+
...options,
|
|
57
|
+
idempotencyKey: options.idempotencyKey ?? idempotencyKeyFor(params),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/** POST /v2/transfers/wallet/{subAccountId} */
|
|
61
|
+
async walletTransferFromSubAccount(subAccountId, params, options = {}) {
|
|
62
|
+
return settle(this.http, "POST", `/v2/transfers/wallet/${pathId(subAccountId)}`, { body: params }, TRANSFER_OUTCOMES, {
|
|
63
|
+
...options,
|
|
64
|
+
idempotencyKey: options.idempotencyKey ?? idempotencyKeyFor(params),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
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 RequestOptions and 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 a single mutating call. */
|
|
50
|
+
export type RequestOptions = {
|
|
51
|
+
/**
|
|
52
|
+
* Tracked for error reporting and onOutcome events. For transfers and bill payments, defaults to merchantTxRef
|
|
53
|
+
* (the actual idempotency key in the request body). For Global Payout/Collections, sent in the request body
|
|
54
|
+
* where Nomba deduplicates on it. The SDK generates a UUID when you omit it.
|
|
55
|
+
*/
|
|
56
|
+
idempotencyKey?: string;
|
|
57
|
+
};
|
|
58
|
+
/** Options for one authenticated call made through IHttpClient.request. */
|
|
59
|
+
export type HttpRequestOptions = {
|
|
60
|
+
body?: unknown;
|
|
61
|
+
query?: Query;
|
|
62
|
+
/** Body codes that are not errors. Defaults to ["00"]. */
|
|
63
|
+
okCodes?: string[];
|
|
64
|
+
codeField?: string;
|
|
65
|
+
descriptionField?: string;
|
|
66
|
+
/** Resolve `{ code, data }` instead of `data`, so the caller can classify the body code. */
|
|
67
|
+
envelope?: boolean;
|
|
68
|
+
} & RequestOptions;
|
|
69
|
+
/** What request() resolves with `envelope: true`. */
|
|
70
|
+
export type ResponseEnvelope<T> = {
|
|
71
|
+
code: string;
|
|
72
|
+
data: T;
|
|
73
|
+
};
|
|
74
|
+
/** The API also accepts lowercase values (glo, mtn, ...). */
|
|
75
|
+
export type Upper = "GLO" | "MTN" | "9MOBILE" | "AIRTEL";
|
|
76
|
+
export type Network = Upper | Lowercase<Upper>;
|
|
77
|
+
/** Options for a money-moving call: an idempotency key plus closures for each outcome. */
|
|
78
|
+
export type CallOptions<T, R = T> = RequestOptions & OutcomeHandlers<T, R>;
|