@nomba/node-sdk 0.3.0 → 0.5.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/README.md +49 -15
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/interfaces/v1/electricity/IElectricityService.d.ts +1 -8
- package/dist/interfaces/v1/globals/collections/IGlobalCollectionsService.d.ts +3 -1
- package/dist/interfaces/v1/globals/payouts/IGlobalPayoutService.d.ts +8 -6
- package/dist/interfaces/v2/electricity/IElectricityV2Service.d.ts +9 -2
- package/dist/interfaces/v2/electricity/IElectricityV2Service.js +1 -1
- package/dist/lib/errors.d.ts +19 -0
- package/dist/lib/errors.js +23 -0
- package/dist/lib/outcome.d.ts +9 -3
- package/dist/lib/outcome.js +10 -4
- package/dist/lib/sdk-version.generated.d.ts +1 -1
- package/dist/lib/sdk-version.generated.js +1 -1
- package/dist/lib/util.d.ts +0 -1
- package/dist/lib/util.js +0 -6
- package/dist/services/http/http-client.service.js +5 -3
- package/dist/services/v1/betting/betting.service.d.ts +1 -0
- package/dist/services/v1/betting/betting.service.js +1 -0
- package/dist/services/v1/cable/cable.service.d.ts +1 -0
- package/dist/services/v1/cable/cable.service.js +1 -0
- package/dist/services/v1/checkout/checkout.service.js +1 -1
- package/dist/services/v1/electricity/electricity.service.d.ts +3 -10
- package/dist/services/v1/electricity/electricity.service.js +2 -13
- package/dist/services/v1/globals/collections.service.d.ts +3 -1
- package/dist/services/v1/globals/collections.service.js +10 -5
- package/dist/services/v1/globals/payout.service.d.ts +12 -8
- package/dist/services/v1/globals/payout.service.js +19 -12
- package/dist/services/v1/requery/requery.service.d.ts +23 -5
- package/dist/services/v1/requery/requery.service.js +23 -5
- package/dist/services/v1/terminals/terminals.service.d.ts +37 -9
- package/dist/services/v1/terminals/terminals.service.js +38 -10
- package/dist/services/v1/transactions/transactions.service.d.ts +70 -12
- package/dist/services/v1/transactions/transactions.service.js +70 -12
- package/dist/services/v1/virtual-accounts/virtual-accounts.service.d.ts +48 -7
- package/dist/services/v1/virtual-accounts/virtual-accounts.service.js +48 -7
- package/dist/services/v1/webhooks/webhooks.service.d.ts +28 -6
- package/dist/services/v1/webhooks/webhooks.service.js +28 -6
- package/dist/services/v2/airtime/airtime.service.js +1 -1
- package/dist/services/v2/betting/betting.service.js +1 -1
- package/dist/services/v2/cable/cable.service.js +1 -1
- package/dist/services/v2/data/data.service.js +1 -1
- package/dist/services/v2/electricity/electricity.service.d.ts +10 -3
- package/dist/services/v2/electricity/electricity.service.js +14 -3
- package/dist/services/v2/transfers/transfers.service.js +4 -4
- package/dist/types/common/common.types.d.ts +2 -1
- package/dist/types/v1/electricity/electricity.types.d.ts +0 -9
- package/dist/types/v1/globals/collections.types.d.ts +3 -3
- package/dist/types/v1/globals/payout.types.d.ts +3 -3
- package/dist/types/v2/electricity/electricity.types.d.ts +9 -0
- package/package.json +1 -1
|
@@ -16,25 +16,66 @@ import type { IHttpClient } from "../../../interfaces/http/IHttpClient.js";
|
|
|
16
16
|
import type { IVirtualAccountsService } from "../../../interfaces/v1/virtual-accounts/IVirtualAccountsService.js";
|
|
17
17
|
import type { PageParams } from "../../../lib/util.js";
|
|
18
18
|
import type { CreatedVirtualAccount, CreateVirtualAccountParams, FilterVirtualAccountsParams, UpdateVirtualAccountParams, VirtualAccount, VirtualAccountList } from "../../../types/v1/virtual-accounts/virtual-accounts.types.js";
|
|
19
|
+
/** Virtual Accounts (v1): create, update, expire, and list virtual bank accounts that collect payments. */
|
|
19
20
|
export declare class VirtualAccountsService implements IVirtualAccountsService {
|
|
20
21
|
private readonly http;
|
|
21
22
|
constructor(http: IHttpClient);
|
|
22
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* `POST /v1/accounts/virtual`. Creates a virtual account for the parent account.
|
|
25
|
+
* @param params The account details to create; `accountRef` is your unique identifier for lookups.
|
|
26
|
+
* @returns The created virtual account, including its bank account number.
|
|
27
|
+
* @throws {NombaError} The call failed, e.g. `accountRef` already exists.
|
|
28
|
+
*/
|
|
23
29
|
create(params: CreateVirtualAccountParams): Promise<CreatedVirtualAccount>;
|
|
24
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* `POST /v1/accounts/virtual/{subAccountId}`. Creates a virtual account that collects funds
|
|
32
|
+
* into a specific sub account.
|
|
33
|
+
* @param subAccountId The sub account to receive collected funds.
|
|
34
|
+
* @param params The account details to create; `accountRef` is your unique identifier for lookups.
|
|
35
|
+
* @returns The created virtual account, including its bank account number.
|
|
36
|
+
* @throws {NombaError} The call failed, e.g. `subAccountId` does not exist or `accountRef` already exists.
|
|
37
|
+
*/
|
|
25
38
|
createForSubAccount(subAccountId: string, params: CreateVirtualAccountParams): Promise<CreatedVirtualAccount>;
|
|
26
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* `GET /v1/accounts/virtual/{identifier}`. Looks up a virtual account by reference or account number.
|
|
41
|
+
* @param identifier The `accountRef` or the 10-digit virtual account number.
|
|
42
|
+
* @returns The virtual account's details.
|
|
43
|
+
* @throws {NombaError} The call failed, e.g. `identifier` does not match any account.
|
|
44
|
+
*/
|
|
27
45
|
get(identifier: string): Promise<VirtualAccount>;
|
|
28
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* `PUT /v1/accounts/virtual/{identifier}`. Updates a virtual account's mutable fields.
|
|
48
|
+
* @param identifier The `accountRef` or the 10-digit virtual account number.
|
|
49
|
+
* @param params The fields to update (e.g., `accountName`, `expiryDate`).
|
|
50
|
+
* @returns Whether the update succeeded.
|
|
51
|
+
* @throws {NombaError} The call failed, e.g. `identifier` does not match any account.
|
|
52
|
+
*/
|
|
29
53
|
update(identifier: string, params: UpdateVirtualAccountParams): Promise<{
|
|
30
54
|
updated: boolean;
|
|
31
55
|
}>;
|
|
32
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* `DELETE /v1/accounts/virtual/{identifier}`. Expires a virtual account so it no longer accepts
|
|
58
|
+
* payments. This action cannot be undone.
|
|
59
|
+
* @param identifier The `accountRef` or the 10-digit virtual account number.
|
|
60
|
+
* @returns Whether the expiration succeeded.
|
|
61
|
+
* @throws {NombaError} The call failed, e.g. `identifier` does not match any account.
|
|
62
|
+
*/
|
|
33
63
|
expire(identifier: string): Promise<{
|
|
34
64
|
expired: boolean;
|
|
35
65
|
}>;
|
|
36
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* `POST /v1/accounts/virtual/list`. Lists virtual accounts matching the given filters.
|
|
68
|
+
* @param filter Filters to apply (e.g., `accountName`, `resourceAcquired`).
|
|
69
|
+
* @param page Pagination options (`cursor`, `limit`).
|
|
70
|
+
* @returns One page of matching virtual accounts.
|
|
71
|
+
* @throws {NombaError} The call failed.
|
|
72
|
+
*/
|
|
37
73
|
list(filter?: FilterVirtualAccountsParams, page?: PageParams): Promise<VirtualAccountList>;
|
|
38
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* Iterates over every matching virtual account, across all pages. Starts at `page.cursor` if given.
|
|
76
|
+
* @param filter Filters to apply (e.g., `accountName`, `resourceAcquired`).
|
|
77
|
+
* @param page Starting pagination options.
|
|
78
|
+
* @throws {NombaError} A page request failed.
|
|
79
|
+
*/
|
|
39
80
|
iterate(filter?: FilterVirtualAccountsParams, page?: PageParams): AsyncGenerator<VirtualAccount>;
|
|
40
81
|
}
|
|
@@ -14,41 +14,82 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { paginate } from "../../../lib/paginate.js";
|
|
16
16
|
import { pageQuery, pathId } from "../../../lib/util.js";
|
|
17
|
+
/** Virtual Accounts (v1): create, update, expire, and list virtual bank accounts that collect payments. */
|
|
17
18
|
export class VirtualAccountsService {
|
|
18
19
|
http;
|
|
19
20
|
constructor(http) {
|
|
20
21
|
this.http = http;
|
|
21
22
|
}
|
|
22
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* `POST /v1/accounts/virtual`. Creates a virtual account for the parent account.
|
|
25
|
+
* @param params The account details to create; `accountRef` is your unique identifier for lookups.
|
|
26
|
+
* @returns The created virtual account, including its bank account number.
|
|
27
|
+
* @throws {NombaError} The call failed, e.g. `accountRef` already exists.
|
|
28
|
+
*/
|
|
23
29
|
create(params) {
|
|
24
30
|
return this.http.request("POST", "/v1/accounts/virtual", {
|
|
25
31
|
body: params,
|
|
26
32
|
});
|
|
27
33
|
}
|
|
28
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* `POST /v1/accounts/virtual/{subAccountId}`. Creates a virtual account that collects funds
|
|
36
|
+
* into a specific sub account.
|
|
37
|
+
* @param subAccountId The sub account to receive collected funds.
|
|
38
|
+
* @param params The account details to create; `accountRef` is your unique identifier for lookups.
|
|
39
|
+
* @returns The created virtual account, including its bank account number.
|
|
40
|
+
* @throws {NombaError} The call failed, e.g. `subAccountId` does not exist or `accountRef` already exists.
|
|
41
|
+
*/
|
|
29
42
|
async createForSubAccount(subAccountId, params) {
|
|
30
43
|
return this.http.request("POST", `/v1/accounts/virtual/${pathId(subAccountId)}`, { body: params });
|
|
31
44
|
}
|
|
32
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* `GET /v1/accounts/virtual/{identifier}`. Looks up a virtual account by reference or account number.
|
|
47
|
+
* @param identifier The `accountRef` or the 10-digit virtual account number.
|
|
48
|
+
* @returns The virtual account's details.
|
|
49
|
+
* @throws {NombaError} The call failed, e.g. `identifier` does not match any account.
|
|
50
|
+
*/
|
|
33
51
|
async get(identifier) {
|
|
34
52
|
return this.http.request("GET", `/v1/accounts/virtual/${pathId(identifier)}`);
|
|
35
53
|
}
|
|
36
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* `PUT /v1/accounts/virtual/{identifier}`. Updates a virtual account's mutable fields.
|
|
56
|
+
* @param identifier The `accountRef` or the 10-digit virtual account number.
|
|
57
|
+
* @param params The fields to update (e.g., `accountName`, `expiryDate`).
|
|
58
|
+
* @returns Whether the update succeeded.
|
|
59
|
+
* @throws {NombaError} The call failed, e.g. `identifier` does not match any account.
|
|
60
|
+
*/
|
|
37
61
|
async update(identifier, params) {
|
|
38
62
|
return this.http.request("PUT", `/v1/accounts/virtual/${pathId(identifier)}`, { body: params });
|
|
39
63
|
}
|
|
40
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* `DELETE /v1/accounts/virtual/{identifier}`. Expires a virtual account so it no longer accepts
|
|
66
|
+
* payments. This action cannot be undone.
|
|
67
|
+
* @param identifier The `accountRef` or the 10-digit virtual account number.
|
|
68
|
+
* @returns Whether the expiration succeeded.
|
|
69
|
+
* @throws {NombaError} The call failed, e.g. `identifier` does not match any account.
|
|
70
|
+
*/
|
|
41
71
|
async expire(identifier) {
|
|
42
72
|
return this.http.request("DELETE", `/v1/accounts/virtual/${pathId(identifier)}`);
|
|
43
73
|
}
|
|
44
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* `POST /v1/accounts/virtual/list`. Lists virtual accounts matching the given filters.
|
|
76
|
+
* @param filter Filters to apply (e.g., `accountName`, `resourceAcquired`).
|
|
77
|
+
* @param page Pagination options (`cursor`, `limit`).
|
|
78
|
+
* @returns One page of matching virtual accounts.
|
|
79
|
+
* @throws {NombaError} The call failed.
|
|
80
|
+
*/
|
|
45
81
|
list(filter = {}, page = {}) {
|
|
46
82
|
return this.http.request("POST", "/v1/accounts/virtual/list", {
|
|
47
83
|
body: filter,
|
|
48
84
|
query: pageQuery(page),
|
|
49
85
|
});
|
|
50
86
|
}
|
|
51
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* Iterates over every matching virtual account, across all pages. Starts at `page.cursor` if given.
|
|
89
|
+
* @param filter Filters to apply (e.g., `accountName`, `resourceAcquired`).
|
|
90
|
+
* @param page Starting pagination options.
|
|
91
|
+
* @throws {NombaError} A page request failed.
|
|
92
|
+
*/
|
|
52
93
|
iterate(filter = {}, page = {}) {
|
|
53
94
|
return paginate((cursor) => this.list(filter, cursor ? { ...page, cursor } : page));
|
|
54
95
|
}
|
|
@@ -15,21 +15,43 @@
|
|
|
15
15
|
import type { IHttpClient } from "../../../interfaces/http/IHttpClient.js";
|
|
16
16
|
import type { IWebhooksService } from "../../../interfaces/v1/webhooks/IWebhooksService.js";
|
|
17
17
|
import type { EventLog, EventLogsParams, EventsParams, ReplayParams, WebhookList, WebhookSubscription } from "../../../types/v1/webhooks/webhooks.types.js";
|
|
18
|
+
/** Webhooks (v1): delivery logs, re-push, and replay for troubleshooting webhook delivery. */
|
|
18
19
|
export declare class WebhooksService implements IWebhooksService {
|
|
19
20
|
#private;
|
|
20
21
|
private readonly http;
|
|
21
22
|
constructor(http: IHttpClient);
|
|
22
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* `POST /v1/webhooks/event-logs`. Returns webhooks sent to your system and how your server answered.
|
|
25
|
+
* Useful for debugging missed or failed deliveries.
|
|
26
|
+
* @param params Filters (e.g., `startDate`, `endDate`, `eventType`).
|
|
27
|
+
* @returns A list of webhook event logs.
|
|
28
|
+
* @throws {NombaError} The call failed.
|
|
29
|
+
*/
|
|
23
30
|
eventLogs(params?: EventLogsParams): Promise<WebhookList<EventLog>>;
|
|
24
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* `POST /v1/webhooks/events`. Returns your webhook subscriptions.
|
|
33
|
+
* @param params Filters (e.g., `eventType`).
|
|
34
|
+
* @returns A list of webhook subscriptions.
|
|
35
|
+
* @throws {NombaError} The call failed.
|
|
36
|
+
*/
|
|
25
37
|
events(params?: EventsParams): Promise<WebhookList<WebhookSubscription>>;
|
|
26
38
|
/**
|
|
27
|
-
* POST /v1/webhooks/re-push
|
|
28
|
-
*
|
|
39
|
+
* `POST /v1/webhooks/re-push`. Resends a single webhook event. Use the `hookRequestId` from `eventLogs`.
|
|
40
|
+
* @param hookRequestId The event log's ID to resend.
|
|
41
|
+
* @throws {NombaError} The call failed, e.g. `hookRequestId` does not exist.
|
|
29
42
|
*/
|
|
30
43
|
repush(hookRequestId: string): Promise<void>;
|
|
31
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* `POST /v1/webhooks/bulk-re-push`. Resends multiple webhook events at once.
|
|
46
|
+
* @param hookRequestIds The event log IDs to resend.
|
|
47
|
+
* @throws {NombaError} The call failed.
|
|
48
|
+
*/
|
|
32
49
|
bulkRepush(hookRequestIds: string[]): Promise<void>;
|
|
33
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* `POST /v1/webhooks/replay`. Resends every matching webhook event in a time window.
|
|
52
|
+
* Useful for recovering from webhook handler outages.
|
|
53
|
+
* @param params The time window (`startDate`, `endDate`) and optional filters.
|
|
54
|
+
* @throws {NombaError} The call failed.
|
|
55
|
+
*/
|
|
34
56
|
replay(params: ReplayParams): Promise<void>;
|
|
35
57
|
}
|
|
@@ -15,19 +15,31 @@
|
|
|
15
15
|
// Documented in the guide only (no API reference page). Its examples answer code "200", not "00", and never
|
|
16
16
|
// mark request fields as required, so every field is optional here.
|
|
17
17
|
const OK_CODES = ["00", "200"];
|
|
18
|
+
/** Webhooks (v1): delivery logs, re-push, and replay for troubleshooting webhook delivery. */
|
|
18
19
|
export class WebhooksService {
|
|
19
20
|
http;
|
|
20
21
|
constructor(http) {
|
|
21
22
|
this.http = http;
|
|
22
23
|
}
|
|
23
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* `POST /v1/webhooks/event-logs`. Returns webhooks sent to your system and how your server answered.
|
|
26
|
+
* Useful for debugging missed or failed deliveries.
|
|
27
|
+
* @param params Filters (e.g., `startDate`, `endDate`, `eventType`).
|
|
28
|
+
* @returns A list of webhook event logs.
|
|
29
|
+
* @throws {NombaError} The call failed.
|
|
30
|
+
*/
|
|
24
31
|
eventLogs(params = {}) {
|
|
25
32
|
return this.http.request("POST", "/v1/webhooks/event-logs", {
|
|
26
33
|
body: params,
|
|
27
34
|
okCodes: OK_CODES,
|
|
28
35
|
});
|
|
29
36
|
}
|
|
30
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* `POST /v1/webhooks/events`. Returns your webhook subscriptions.
|
|
39
|
+
* @param params Filters (e.g., `eventType`).
|
|
40
|
+
* @returns A list of webhook subscriptions.
|
|
41
|
+
* @throws {NombaError} The call failed.
|
|
42
|
+
*/
|
|
31
43
|
events(params = {}) {
|
|
32
44
|
return this.http.request("POST", "/v1/webhooks/events", {
|
|
33
45
|
body: params,
|
|
@@ -35,17 +47,27 @@ export class WebhooksService {
|
|
|
35
47
|
});
|
|
36
48
|
}
|
|
37
49
|
/**
|
|
38
|
-
* POST /v1/webhooks/re-push
|
|
39
|
-
*
|
|
50
|
+
* `POST /v1/webhooks/re-push`. Resends a single webhook event. Use the `hookRequestId` from `eventLogs`.
|
|
51
|
+
* @param hookRequestId The event log's ID to resend.
|
|
52
|
+
* @throws {NombaError} The call failed, e.g. `hookRequestId` does not exist.
|
|
40
53
|
*/
|
|
41
54
|
repush(hookRequestId) {
|
|
42
55
|
return this.#post("re-push", { hooksRequestId: hookRequestId });
|
|
43
56
|
}
|
|
44
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* `POST /v1/webhooks/bulk-re-push`. Resends multiple webhook events at once.
|
|
59
|
+
* @param hookRequestIds The event log IDs to resend.
|
|
60
|
+
* @throws {NombaError} The call failed.
|
|
61
|
+
*/
|
|
45
62
|
bulkRepush(hookRequestIds) {
|
|
46
63
|
return this.#post("bulk-re-push", { hooksRequestIds: hookRequestIds });
|
|
47
64
|
}
|
|
48
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* `POST /v1/webhooks/replay`. Resends every matching webhook event in a time window.
|
|
67
|
+
* Useful for recovering from webhook handler outages.
|
|
68
|
+
* @param params The time window (`startDate`, `endDate`) and optional filters.
|
|
69
|
+
* @throws {NombaError} The call failed.
|
|
70
|
+
*/
|
|
49
71
|
replay(params) {
|
|
50
72
|
return this.#post("replay", params);
|
|
51
73
|
}
|
|
@@ -50,6 +50,6 @@ export class AirtimeV2Service {
|
|
|
50
50
|
return this.#buy(`/v2/bill/topup/${pathId(subAccountId)}`, params, options);
|
|
51
51
|
}
|
|
52
52
|
#buy(path, params, options) {
|
|
53
|
-
return settle(this.http, "POST", path, { body: params }, OUTCOMES, params.merchantTxRef, options);
|
|
53
|
+
return settle(this.http, "POST", path, { body: params }, OUTCOMES, { field: "merchantTxRef", value: params.merchantTxRef }, options);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
@@ -51,6 +51,6 @@ export class BettingV2Service {
|
|
|
51
51
|
return this.#pay(`/v2/bill/betting/${pathId(subAccountId)}`, params, options);
|
|
52
52
|
}
|
|
53
53
|
#pay(path, params, options) {
|
|
54
|
-
return settle(this.http, "POST", path, { body: params }, OUTCOMES, params.merchantTxRef, options);
|
|
54
|
+
return settle(this.http, "POST", path, { body: params }, OUTCOMES, { field: "merchantTxRef", value: params.merchantTxRef }, options);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -51,6 +51,6 @@ export class CableV2Service {
|
|
|
51
51
|
return this.#pay(`/v2/bill/cabletv/${pathId(subAccountId)}`, params, options);
|
|
52
52
|
}
|
|
53
53
|
#pay(path, params, options) {
|
|
54
|
-
return settle(this.http, "POST", path, { body: params }, OUTCOMES, params.merchantTxRef, options);
|
|
54
|
+
return settle(this.http, "POST", path, { body: params }, OUTCOMES, { field: "merchantTxRef", value: params.merchantTxRef }, options);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -50,6 +50,6 @@ export class DataV2Service {
|
|
|
50
50
|
return this.#buy(`/v2/bill/data/${pathId(subAccountId)}`, params, options);
|
|
51
51
|
}
|
|
52
52
|
#buy(path, params, options) {
|
|
53
|
-
return settle(this.http, "POST", path, { body: params }, OUTCOMES, params.merchantTxRef, options);
|
|
53
|
+
return settle(this.http, "POST", path, { body: params }, OUTCOMES, { field: "merchantTxRef", value: params.merchantTxRef }, options);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module nomba/services/v2/electricity
|
|
3
|
-
* @description ElectricityV2 (v2): POST /v2/bill/electricity[/{subAccountId}]
|
|
3
|
+
* @description ElectricityV2 (v2): GET /v2/bill/electricity/lookup, POST /v2/bill/electricity[/{subAccountId}]
|
|
4
4
|
* @see https://developer.nomba.com/docs/api-reference/bills
|
|
5
5
|
*/
|
|
6
6
|
import type { IHttpClient } from "../../../interfaces/http/IHttpClient.js";
|
|
7
7
|
import type { IElectricityV2Service } from "../../../interfaces/v2/electricity/index.js";
|
|
8
8
|
import type { CallOptions } from "../../../types/common/common.types.js";
|
|
9
|
-
import type { ElectricityPaymentParams, ElectricityPaymentV2Result } from "../../../types/v2/electricity/electricity.types.js";
|
|
9
|
+
import type { ElectricityPaymentParams, ElectricityPaymentV2Result, MeterLookupV2Params, MeterLookupV2Result } from "../../../types/v2/electricity/electricity.types.js";
|
|
10
10
|
/**
|
|
11
|
-
* Electricity
|
|
11
|
+
* Electricity meter lookup and bill payments. A call that throws a NombaError with a 4xx
|
|
12
12
|
* status was rejected and did nothing. Any other failure (5xx, network error, timeout) leaves the outcome
|
|
13
13
|
* unknown: keep the same `merchantTxRef`, wait for the webhook or requery, and never retry under a new
|
|
14
14
|
* reference.
|
|
@@ -17,6 +17,13 @@ export declare class ElectricityV2Service implements IElectricityV2Service {
|
|
|
17
17
|
#private;
|
|
18
18
|
private readonly http;
|
|
19
19
|
constructor(http: IHttpClient);
|
|
20
|
+
/**
|
|
21
|
+
* `GET /v2/bill/electricity/lookup`.
|
|
22
|
+
* @param params The disco and meter/customer id to look up.
|
|
23
|
+
* @returns The customer's name and address.
|
|
24
|
+
* @throws {NombaError} The meter number is invalid or not found, or the request failed.
|
|
25
|
+
*/
|
|
26
|
+
lookupMeter(params: MeterLookupV2Params): Promise<MeterLookupV2Result>;
|
|
20
27
|
/**
|
|
21
28
|
* `POST /v2/bill/electricity`. Pays an electricity bill from the parent account. Prepaid meters get the
|
|
22
29
|
* token in `meta.phcnToken`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module nomba/services/v2/electricity
|
|
3
|
-
* @description ElectricityV2 (v2): POST /v2/bill/electricity[/{subAccountId}]
|
|
3
|
+
* @description ElectricityV2 (v2): GET /v2/bill/electricity/lookup, POST /v2/bill/electricity[/{subAccountId}]
|
|
4
4
|
* @see https://developer.nomba.com/docs/api-reference/bills
|
|
5
5
|
*/
|
|
6
6
|
import { REJECTED, settle } from "../../../lib/outcome.js";
|
|
@@ -13,7 +13,7 @@ const OUTCOMES = {
|
|
|
13
13
|
statuses: { SUCCESS: "success", PENDING_BILLING: "pending" },
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
|
-
* Electricity
|
|
16
|
+
* Electricity meter lookup and bill payments. A call that throws a NombaError with a 4xx
|
|
17
17
|
* status was rejected and did nothing. Any other failure (5xx, network error, timeout) leaves the outcome
|
|
18
18
|
* unknown: keep the same `merchantTxRef`, wait for the webhook or requery, and never retry under a new
|
|
19
19
|
* reference.
|
|
@@ -23,6 +23,17 @@ export class ElectricityV2Service {
|
|
|
23
23
|
constructor(http) {
|
|
24
24
|
this.http = http;
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* `GET /v2/bill/electricity/lookup`.
|
|
28
|
+
* @param params The disco and meter/customer id to look up.
|
|
29
|
+
* @returns The customer's name and address.
|
|
30
|
+
* @throws {NombaError} The meter number is invalid or not found, or the request failed.
|
|
31
|
+
*/
|
|
32
|
+
lookupMeter(params) {
|
|
33
|
+
return this.http.request("GET", "/v2/bill/electricity/lookup", {
|
|
34
|
+
query: params,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
26
37
|
/**
|
|
27
38
|
* `POST /v2/bill/electricity`. Pays an electricity bill from the parent account. Prepaid meters get the
|
|
28
39
|
* token in `meta.phcnToken`.
|
|
@@ -52,6 +63,6 @@ export class ElectricityV2Service {
|
|
|
52
63
|
return this.#pay(`/v2/bill/electricity/${pathId(subAccountId)}`, params, options);
|
|
53
64
|
}
|
|
54
65
|
#pay(path, params, options) {
|
|
55
|
-
return settle(this.http, "POST", path, { body: params }, OUTCOMES, params.merchantTxRef, options);
|
|
66
|
+
return settle(this.http, "POST", path, { body: params }, OUTCOMES, { field: "merchantTxRef", value: params.merchantTxRef }, options);
|
|
56
67
|
}
|
|
57
68
|
}
|
|
@@ -52,7 +52,7 @@ export class TransfersService {
|
|
|
52
52
|
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
53
53
|
*/
|
|
54
54
|
async bankTransfer(params, options = {}) {
|
|
55
|
-
return settle(this.http, "POST", "/v2/transfers/bank", { body: params }, TRANSFER_OUTCOMES, params.merchantTxRef, options);
|
|
55
|
+
return settle(this.http, "POST", "/v2/transfers/bank", { body: params }, TRANSFER_OUTCOMES, { field: "merchantTxRef", value: params.merchantTxRef }, options);
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* `POST /v2/transfers/bank/{subAccountId}`. Sends a bank transfer from a sub account. You must ask
|
|
@@ -66,7 +66,7 @@ export class TransfersService {
|
|
|
66
66
|
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
67
67
|
*/
|
|
68
68
|
async bankTransferFromSubAccount(subAccountId, params, options = {}) {
|
|
69
|
-
return settle(this.http, "POST", `/v2/transfers/bank/${pathId(subAccountId)}`, { body: params }, TRANSFER_OUTCOMES, params.merchantTxRef, options);
|
|
69
|
+
return settle(this.http, "POST", `/v2/transfers/bank/${pathId(subAccountId)}`, { body: params }, TRANSFER_OUTCOMES, { field: "merchantTxRef", value: params.merchantTxRef }, options);
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* `POST /v2/transfers/wallet`. Sends a wallet-to-wallet transfer from the parent account to another
|
|
@@ -79,7 +79,7 @@ export class TransfersService {
|
|
|
79
79
|
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
80
80
|
*/
|
|
81
81
|
async walletTransfer(params, options = {}) {
|
|
82
|
-
return settle(this.http, "POST", "/v2/transfers/wallet", { body: params }, TRANSFER_OUTCOMES, params.merchantTxRef, options);
|
|
82
|
+
return settle(this.http, "POST", "/v2/transfers/wallet", { body: params }, TRANSFER_OUTCOMES, { field: "merchantTxRef", value: params.merchantTxRef }, options);
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* `POST /v2/transfers/wallet/{subAccountId}`. Sends a wallet-to-wallet transfer from a sub account.
|
|
@@ -92,6 +92,6 @@ export class TransfersService {
|
|
|
92
92
|
* @throws {UnconfirmedOutcomeError} The result is pending and no `onPending` handler was given.
|
|
93
93
|
*/
|
|
94
94
|
async walletTransferFromSubAccount(subAccountId, params, options = {}) {
|
|
95
|
-
return settle(this.http, "POST", `/v2/transfers/wallet/${pathId(subAccountId)}`, { body: params }, TRANSFER_OUTCOMES, params.merchantTxRef, options);
|
|
95
|
+
return settle(this.http, "POST", `/v2/transfers/wallet/${pathId(subAccountId)}`, { body: params }, TRANSFER_OUTCOMES, { field: "merchantTxRef", value: params.merchantTxRef }, options);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
@@ -58,7 +58,8 @@ export type HttpRequestOptions = {
|
|
|
58
58
|
envelope?: boolean;
|
|
59
59
|
/**
|
|
60
60
|
* Tracked in `OutcomeUnknownError` so callers know which transaction to requery. Services derive
|
|
61
|
-
* this from params (e.g., `merchantTxRef`).
|
|
61
|
+
* this from params (e.g., `merchantTxRef`). For non-money-moving operations, a random UUID is
|
|
62
|
+
* generated if omitted. Money-moving operations (settle) require a caller-provided key.
|
|
62
63
|
*/
|
|
63
64
|
idempotencyKey?: string;
|
|
64
65
|
};
|
|
@@ -10,12 +10,3 @@ export type ElectricityProvidersResult = {
|
|
|
10
10
|
code: string;
|
|
11
11
|
data: ElectricityProvider[];
|
|
12
12
|
};
|
|
13
|
-
export type MeterLookupParams = {
|
|
14
|
-
disco: string;
|
|
15
|
-
customerId: string;
|
|
16
|
-
};
|
|
17
|
-
export type MeterLookupResult = {
|
|
18
|
-
code: string;
|
|
19
|
-
/** Customer name associated with the meter */
|
|
20
|
-
data: string;
|
|
21
|
-
};
|
|
@@ -13,10 +13,10 @@ export type InitiateInflowParams = {
|
|
|
13
13
|
/** A `code` from `inflowProviders`. */
|
|
14
14
|
topupVendor: string;
|
|
15
15
|
/**
|
|
16
|
-
* Sent in the body; the API dedupes on it.
|
|
17
|
-
* OutcomeUnknownError, retry with the
|
|
16
|
+
* Sent in the body; the API dedupes on it. Required to prevent double disbursement. After an
|
|
17
|
+
* OutcomeUnknownError, retry with the same key. After a definite rejection, use a new key.
|
|
18
18
|
*/
|
|
19
|
-
idempotencyKey
|
|
19
|
+
idempotencyKey: string;
|
|
20
20
|
};
|
|
21
21
|
export type InflowProvider = {
|
|
22
22
|
/** Pass as `topupVendor`, e.g. MPESA, AIRTEL, ORANGE. */
|
|
@@ -19,11 +19,11 @@ export type ConvertMoneyParams = {
|
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
21
21
|
* Sent in the body; the API dedupes on it (same key and body replays the original, with `idempotentReplay`).
|
|
22
|
-
*
|
|
23
|
-
*
|
|
22
|
+
* Required to prevent double disbursement. After an OutcomeUnknownError, retry with the same key;
|
|
23
|
+
* change anything about the payment and you must use a new key. At most 128 characters.
|
|
24
24
|
*/
|
|
25
25
|
export type BodyIdempotencyKey = {
|
|
26
|
-
idempotencyKey
|
|
26
|
+
idempotencyKey: string;
|
|
27
27
|
};
|
|
28
28
|
export type AuthorizeExchangeParams = BodyIdempotencyKey & {
|
|
29
29
|
amount: number;
|
|
@@ -13,6 +13,15 @@ export type ElectricityPaymentParams = {
|
|
|
13
13
|
/** Usually PREPAID or POSTPAID. */
|
|
14
14
|
meterType: string;
|
|
15
15
|
};
|
|
16
|
+
export type MeterLookupV2Params = {
|
|
17
|
+
disco: string;
|
|
18
|
+
customerId: string;
|
|
19
|
+
};
|
|
20
|
+
export type MeterLookupV2Result = {
|
|
21
|
+
name: string;
|
|
22
|
+
/** `"unknown"` if the provider supplies no address. */
|
|
23
|
+
address: string;
|
|
24
|
+
};
|
|
16
25
|
export type ElectricityPaymentV2Result = {
|
|
17
26
|
/** Pass to requery to confirm the final status. */
|
|
18
27
|
id: string;
|