@nomba/node-sdk 0.1.0 → 0.4.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.
Files changed (82) hide show
  1. package/README.md +77 -16
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/interfaces/v1/accounts/IAccountsService.d.ts +46 -8
  5. package/dist/interfaces/v1/betting/IBettingService.d.ts +11 -2
  6. package/dist/interfaces/v1/cable/ICableService.d.ts +12 -2
  7. package/dist/interfaces/v1/charge/IChargeService.d.ts +80 -19
  8. package/dist/interfaces/v1/checkout/ICheckoutService.d.ts +64 -15
  9. package/dist/interfaces/v1/data/IDataService.d.ts +6 -1
  10. package/dist/interfaces/v1/direct-debits/IDirectDebitsService.d.ts +37 -14
  11. package/dist/interfaces/v1/electricity/IElectricityService.d.ts +11 -2
  12. package/dist/interfaces/v1/globals/collections/IGlobalCollectionsService.d.ts +22 -5
  13. package/dist/interfaces/v1/globals/payouts/IGlobalPayoutService.d.ts +76 -13
  14. package/dist/interfaces/v1/requery/IRequeryService.d.ts +19 -5
  15. package/dist/interfaces/v1/terminals/ITerminalsService.d.ts +43 -10
  16. package/dist/interfaces/v1/transactions/ITransactionsService.d.ts +71 -12
  17. package/dist/interfaces/v1/virtual-accounts/IVirtualAccountsService.d.ts +50 -12
  18. package/dist/interfaces/v1/webhooks/IWebhooksService.d.ts +29 -10
  19. package/dist/interfaces/v2/airtime/IAirtimeV2Service.d.ts +21 -2
  20. package/dist/interfaces/v2/betting/IBettingV2Service.d.ts +21 -2
  21. package/dist/interfaces/v2/cable/ICableV2Service.d.ts +21 -2
  22. package/dist/interfaces/v2/data/IDataV2Service.d.ts +21 -2
  23. package/dist/interfaces/v2/electricity/IElectricityV2Service.d.ts +22 -2
  24. package/dist/interfaces/v2/transfers/ITransfersService.d.ts +57 -6
  25. package/dist/lib/errors.d.ts +19 -0
  26. package/dist/lib/errors.js +23 -0
  27. package/dist/lib/outcome.d.ts +30 -5
  28. package/dist/lib/outcome.js +31 -6
  29. package/dist/lib/sdk-version.generated.d.ts +1 -1
  30. package/dist/lib/sdk-version.generated.js +1 -1
  31. package/dist/lib/util.d.ts +0 -1
  32. package/dist/lib/util.js +0 -6
  33. package/dist/nomba.d.ts +38 -5
  34. package/dist/nomba.js +38 -5
  35. package/dist/services/http/http-client.service.d.ts +40 -6
  36. package/dist/services/http/http-client.service.js +44 -9
  37. package/dist/services/v1/accounts/accounts.service.d.ts +46 -8
  38. package/dist/services/v1/accounts/accounts.service.js +46 -8
  39. package/dist/services/v1/betting/betting.service.d.ts +12 -2
  40. package/dist/services/v1/betting/betting.service.js +12 -2
  41. package/dist/services/v1/cable/cable.service.d.ts +13 -2
  42. package/dist/services/v1/cable/cable.service.js +13 -2
  43. package/dist/services/v1/charge/charge.service.d.ts +80 -19
  44. package/dist/services/v1/charge/charge.service.js +88 -26
  45. package/dist/services/v1/checkout/checkout.service.d.ts +63 -15
  46. package/dist/services/v1/checkout/checkout.service.js +70 -24
  47. package/dist/services/v1/data/data.service.d.ts +7 -1
  48. package/dist/services/v1/data/data.service.js +7 -1
  49. package/dist/services/v1/direct-debits/direct-debits.service.d.ts +38 -14
  50. package/dist/services/v1/direct-debits/direct-debits.service.js +39 -17
  51. package/dist/services/v1/electricity/electricity.service.d.ts +12 -2
  52. package/dist/services/v1/electricity/electricity.service.js +12 -2
  53. package/dist/services/v1/globals/collections.service.d.ts +23 -5
  54. package/dist/services/v1/globals/collections.service.js +29 -7
  55. package/dist/services/v1/globals/payout.service.d.ts +77 -13
  56. package/dist/services/v1/globals/payout.service.js +83 -17
  57. package/dist/services/v1/requery/requery.service.d.ts +23 -5
  58. package/dist/services/v1/requery/requery.service.js +23 -5
  59. package/dist/services/v1/terminals/terminals.service.d.ts +42 -14
  60. package/dist/services/v1/terminals/terminals.service.js +44 -27
  61. package/dist/services/v1/transactions/transactions.service.d.ts +70 -12
  62. package/dist/services/v1/transactions/transactions.service.js +70 -12
  63. package/dist/services/v1/virtual-accounts/virtual-accounts.service.d.ts +52 -12
  64. package/dist/services/v1/virtual-accounts/virtual-accounts.service.js +55 -15
  65. package/dist/services/v1/webhooks/webhooks.service.d.ts +31 -10
  66. package/dist/services/v1/webhooks/webhooks.service.js +35 -14
  67. package/dist/services/v2/airtime/airtime.service.d.ts +26 -2
  68. package/dist/services/v2/airtime/airtime.service.js +27 -7
  69. package/dist/services/v2/betting/betting.service.d.ts +27 -3
  70. package/dist/services/v2/betting/betting.service.js +28 -8
  71. package/dist/services/v2/cable/cable.service.d.ts +27 -3
  72. package/dist/services/v2/cable/cable.service.js +28 -8
  73. package/dist/services/v2/data/data.service.d.ts +26 -2
  74. package/dist/services/v2/data/data.service.js +27 -7
  75. package/dist/services/v2/electricity/electricity.service.d.ts +28 -3
  76. package/dist/services/v2/electricity/electricity.service.js +29 -8
  77. package/dist/services/v2/transfers/transfers.service.d.ts +51 -6
  78. package/dist/services/v2/transfers/transfers.service.js +55 -25
  79. package/dist/types/common/common.types.d.ts +10 -13
  80. package/dist/types/v1/globals/collections.types.d.ts +3 -3
  81. package/dist/types/v1/globals/payout.types.d.ts +3 -3
  82. package/package.json +1 -1
@@ -19,20 +19,58 @@ import type { Terminal, TerminalList, TerminalListParams } from "../../../types/
19
19
  export declare class AccountsService implements IAccountsService {
20
20
  private readonly http;
21
21
  constructor(http: IHttpClient);
22
- /** GET /v1/accounts/parent */
22
+ /**
23
+ * `GET /v1/accounts/parent`.
24
+ * @returns The parent account's details.
25
+ * @throws {NombaError} The call failed.
26
+ */
23
27
  getParentAccount(): Promise<AccountDetails>;
24
- /** GET /v1/accounts/balance */
28
+ /**
29
+ * `GET /v1/accounts/balance`.
30
+ * @returns The parent account's balance.
31
+ * @throws {NombaError} The call failed.
32
+ */
25
33
  getParentBalance(): Promise<AccountBalance>;
26
- /** GET /v1/accounts/sub-account-details */
34
+ /**
35
+ * `GET /v1/accounts/sub-account-details`.
36
+ * @param lookup Which sub account to fetch, by account ID or account number.
37
+ * @returns The sub account's details.
38
+ * @throws {NombaError} The call failed, e.g. no sub account matches `lookup`.
39
+ */
27
40
  getSubAccount(lookup?: SubAccountLookup): Promise<AccountDetails>;
28
- /** GET /v1/accounts/{subAccountId}/balance */
41
+ /**
42
+ * `GET /v1/accounts/{subAccountId}/balance`.
43
+ * @param subAccountId The sub account's ID.
44
+ * @returns The sub account's balance.
45
+ * @throws {NombaError} The call failed, e.g. `subAccountId` does not exist.
46
+ */
29
47
  getSubAccountBalance(subAccountId: string): Promise<AccountBalance>;
30
- /** GET /v1/accounts/terminals */
48
+ /**
49
+ * `GET /v1/accounts/terminals`.
50
+ * @param params Pagination (`cursor`, `size`) and other list filters.
51
+ * @returns One page of the parent account's terminals.
52
+ * @throws {NombaError} The call failed.
53
+ */
31
54
  listParentTerminals(params?: TerminalListParams): Promise<TerminalList>;
32
- /** GET /v1/accounts/{accountId}/terminals */
55
+ /**
56
+ * `GET /v1/accounts/{accountId}/terminals`.
57
+ * @param accountId The sub account's ID.
58
+ * @param params Pagination (`cursor`, `size`) and other list filters.
59
+ * @returns One page of the sub account's terminals.
60
+ * @throws {NombaError} The call failed, e.g. `accountId` does not exist.
61
+ */
33
62
  listSubAccountTerminals(accountId: string, params?: TerminalListParams): Promise<TerminalList>;
34
- /** Every terminal of the parent account, across all pages. Starts at `params.cursor` if given. */
63
+ /**
64
+ * Every terminal of the parent account, across all pages. Starts at `params.cursor` if given.
65
+ * @param params Starting cursor and other list filters.
66
+ * @throws {NombaError} A page request failed.
67
+ */
35
68
  iterateParentTerminals(params?: TerminalListParams): AsyncGenerator<Terminal>;
36
- /** Every terminal of a sub account, across all pages. Starts at `params.cursor` if given. */
69
+ /**
70
+ * Every terminal of a sub account, across all pages. Starts at `params.cursor` if given.
71
+ * @param accountId The sub account's ID.
72
+ * @param params Starting cursor and other list filters.
73
+ * @throws {NombaError} A page request failed, e.g. `accountId` does not exist.
74
+ */
37
75
  iterateSubAccountTerminals(accountId: string, params?: TerminalListParams): AsyncGenerator<Terminal>;
38
76
  }
@@ -19,39 +19,77 @@ export class AccountsService {
19
19
  constructor(http) {
20
20
  this.http = http;
21
21
  }
22
- /** GET /v1/accounts/parent */
22
+ /**
23
+ * `GET /v1/accounts/parent`.
24
+ * @returns The parent account's details.
25
+ * @throws {NombaError} The call failed.
26
+ */
23
27
  getParentAccount() {
24
28
  return this.http.request("GET", "/v1/accounts/parent");
25
29
  }
26
- /** GET /v1/accounts/balance */
30
+ /**
31
+ * `GET /v1/accounts/balance`.
32
+ * @returns The parent account's balance.
33
+ * @throws {NombaError} The call failed.
34
+ */
27
35
  getParentBalance() {
28
36
  return this.http.request("GET", "/v1/accounts/balance");
29
37
  }
30
- /** GET /v1/accounts/sub-account-details */
38
+ /**
39
+ * `GET /v1/accounts/sub-account-details`.
40
+ * @param lookup Which sub account to fetch, by account ID or account number.
41
+ * @returns The sub account's details.
42
+ * @throws {NombaError} The call failed, e.g. no sub account matches `lookup`.
43
+ */
31
44
  getSubAccount(lookup = {}) {
32
45
  return this.http.request("GET", "/v1/accounts/sub-account-details", {
33
46
  query: lookup,
34
47
  });
35
48
  }
36
- /** GET /v1/accounts/{subAccountId}/balance */
49
+ /**
50
+ * `GET /v1/accounts/{subAccountId}/balance`.
51
+ * @param subAccountId The sub account's ID.
52
+ * @returns The sub account's balance.
53
+ * @throws {NombaError} The call failed, e.g. `subAccountId` does not exist.
54
+ */
37
55
  async getSubAccountBalance(subAccountId) {
38
56
  return this.http.request("GET", `/v1/accounts/${pathId(subAccountId)}/balance`);
39
57
  }
40
- /** GET /v1/accounts/terminals */
58
+ /**
59
+ * `GET /v1/accounts/terminals`.
60
+ * @param params Pagination (`cursor`, `size`) and other list filters.
61
+ * @returns One page of the parent account's terminals.
62
+ * @throws {NombaError} The call failed.
63
+ */
41
64
  listParentTerminals(params = {}) {
42
65
  return this.http.request("GET", "/v1/accounts/terminals", {
43
66
  query: pageQuery(params),
44
67
  });
45
68
  }
46
- /** GET /v1/accounts/{accountId}/terminals */
69
+ /**
70
+ * `GET /v1/accounts/{accountId}/terminals`.
71
+ * @param accountId The sub account's ID.
72
+ * @param params Pagination (`cursor`, `size`) and other list filters.
73
+ * @returns One page of the sub account's terminals.
74
+ * @throws {NombaError} The call failed, e.g. `accountId` does not exist.
75
+ */
47
76
  async listSubAccountTerminals(accountId, params = {}) {
48
77
  return this.http.request("GET", `/v1/accounts/${pathId(accountId)}/terminals`, { query: pageQuery(params) });
49
78
  }
50
- /** Every terminal of the parent account, across all pages. Starts at `params.cursor` if given. */
79
+ /**
80
+ * Every terminal of the parent account, across all pages. Starts at `params.cursor` if given.
81
+ * @param params Starting cursor and other list filters.
82
+ * @throws {NombaError} A page request failed.
83
+ */
51
84
  iterateParentTerminals(params = {}) {
52
85
  return paginate((cursor) => this.listParentTerminals(cursor ? { ...params, cursor } : params));
53
86
  }
54
- /** Every terminal of a sub account, across all pages. Starts at `params.cursor` if given. */
87
+ /**
88
+ * Every terminal of a sub account, across all pages. Starts at `params.cursor` if given.
89
+ * @param accountId The sub account's ID.
90
+ * @param params Starting cursor and other list filters.
91
+ * @throws {NombaError} A page request failed, e.g. `accountId` does not exist.
92
+ */
55
93
  iterateSubAccountTerminals(accountId, params = {}) {
56
94
  return paginate((cursor) => this.listSubAccountTerminals(accountId, cursor ? { ...params, cursor } : params));
57
95
  }
@@ -6,11 +6,21 @@
6
6
  import type { IHttpClient } from "../../../interfaces/http/IHttpClient.js";
7
7
  import type { IBettingService } from "../../../interfaces/v1/betting/index.js";
8
8
  import type { BettingCustomerLookupParams, BettingCustomerLookupResult, BettingProvidersResult } from "../../../types/v1/betting/betting.types.js";
9
+ /** Betting lookups (v1): provider listing and customer lookup. Use BettingV2Service for payments. */
9
10
  export declare class BettingService implements IBettingService {
10
11
  private readonly http;
11
12
  constructor(http: IHttpClient);
12
- /** GET /v1/bill/betting/providers */
13
+ /**
14
+ * `GET /v1/bill/betting/providers`.
15
+ * @returns The supported betting providers.
16
+ * @throws {NombaError} The call failed.
17
+ */
13
18
  getBettingProviders(): Promise<BettingProvidersResult>;
14
- /** GET /v1/bill/betting/lookup */
19
+ /**
20
+ * `GET /v1/bill/betting/lookup`. Validates a customer ID and returns the account name.
21
+ * @param params The provider and customer ID to look up.
22
+ * @returns The customer's account name.
23
+ * @throws {NombaError} The call failed, e.g. the customer ID is invalid.
24
+ */
15
25
  lookupCustomer(params: BettingCustomerLookupParams): Promise<BettingCustomerLookupResult>;
16
26
  }
@@ -3,16 +3,26 @@
3
3
  * @description Betting (v1): GET /v1/bill/betting/providers, GET /v1/bill/betting/lookup
4
4
  * @see https://developer.nomba.com/docs/api-reference/bills
5
5
  */
6
+ /** Betting lookups (v1): provider listing and customer lookup. Use BettingV2Service for payments. */
6
7
  export class BettingService {
7
8
  http;
8
9
  constructor(http) {
9
10
  this.http = http;
10
11
  }
11
- /** GET /v1/bill/betting/providers */
12
+ /**
13
+ * `GET /v1/bill/betting/providers`.
14
+ * @returns The supported betting providers.
15
+ * @throws {NombaError} The call failed.
16
+ */
12
17
  getBettingProviders() {
13
18
  return this.http.request("GET", "/v1/bill/betting/providers");
14
19
  }
15
- /** GET /v1/bill/betting/lookup */
20
+ /**
21
+ * `GET /v1/bill/betting/lookup`. Validates a customer ID and returns the account name.
22
+ * @param params The provider and customer ID to look up.
23
+ * @returns The customer's account name.
24
+ * @throws {NombaError} The call failed, e.g. the customer ID is invalid.
25
+ */
16
26
  lookupCustomer(params) {
17
27
  return this.http.request("GET", "/v1/bill/betting/lookup", {
18
28
  query: params,
@@ -6,11 +6,22 @@
6
6
  import type { IHttpClient } from "../../../interfaces/http/IHttpClient.js";
7
7
  import type { ICableService } from "../../../interfaces/v1/cable/index.js";
8
8
  import type { CableCustomerLookupParams, CableCustomerLookupResult, CablePlansParams, CablePlansResult } from "../../../types/v1/cable/cable.types.js";
9
+ /** Cable TV lookups (v1): plan listing and customer lookup. Use CableV2Service for payments. */
9
10
  export declare class CableService implements ICableService {
10
11
  private readonly http;
11
12
  constructor(http: IHttpClient);
12
- /** GET /v1/bill/cableTvProduct */
13
+ /**
14
+ * `GET /v1/bill/cableTvProduct`.
15
+ * @param params The provider whose plans to fetch.
16
+ * @returns The provider's cable TV plans.
17
+ * @throws {NombaError} The call failed.
18
+ */
13
19
  getCablePlans(params: CablePlansParams): Promise<CablePlansResult>;
14
- /** GET /v1/bill/cable/lookup */
20
+ /**
21
+ * `GET /v1/bill/cable/lookup`. Validates a smartcard number and returns the account name.
22
+ * @param params The provider and smartcard number to look up.
23
+ * @returns The customer's account name.
24
+ * @throws {NombaError} The call failed, e.g. the smartcard number is invalid.
25
+ */
15
26
  lookupCustomer(params: CableCustomerLookupParams): Promise<CableCustomerLookupResult>;
16
27
  }
@@ -3,18 +3,29 @@
3
3
  * @description Cable TV (v1): GET /v1/bill/cableTvProduct, GET /v1/bill/cable/lookup
4
4
  * @see https://developer.nomba.com/docs/api-reference/bills
5
5
  */
6
+ /** Cable TV lookups (v1): plan listing and customer lookup. Use CableV2Service for payments. */
6
7
  export class CableService {
7
8
  http;
8
9
  constructor(http) {
9
10
  this.http = http;
10
11
  }
11
- /** GET /v1/bill/cableTvProduct */
12
+ /**
13
+ * `GET /v1/bill/cableTvProduct`.
14
+ * @param params The provider whose plans to fetch.
15
+ * @returns The provider's cable TV plans.
16
+ * @throws {NombaError} The call failed.
17
+ */
12
18
  getCablePlans(params) {
13
19
  return this.http.request("GET", "/v1/bill/cableTvProduct", {
14
20
  query: params,
15
21
  });
16
22
  }
17
- /** GET /v1/bill/cable/lookup */
23
+ /**
24
+ * `GET /v1/bill/cable/lookup`. Validates a smartcard number and returns the account name.
25
+ * @param params The provider and smartcard number to look up.
26
+ * @returns The customer's account name.
27
+ * @throws {NombaError} The call failed, e.g. the smartcard number is invalid.
28
+ */
18
29
  lookupCustomer(params) {
19
30
  return this.http.request("GET", "/v1/bill/cable/lookup", {
20
31
  query: params,
@@ -14,7 +14,6 @@
14
14
  */
15
15
  import type { IHttpClient } from "../../../interfaces/http/IHttpClient.js";
16
16
  import type { IChargeService } from "../../../interfaces/v1/charge/IChargeService.js";
17
- import type { RequestOptions } from "../../../types/common/common.types.js";
18
17
  import type { CancelChargeTransactionParams, ChargeOrder, ChargeTransactionDetails, FlashAccount, SaveCardOtpRequest, SubmitCardDetailsParams, SubmitCardDetailsResult, SubmitCardOtpParams, SubmitCardOtpResult, SubmitSaveCardOtpParams } from "../../../types/v1/charge/charge.types.js";
19
18
  import type { CheckoutResult, TokenizedCardData } from "../../../types/v1/checkout/checkout.types.js";
20
19
  /**
@@ -25,28 +24,90 @@ import type { CheckoutResult, TokenizedCardData } from "../../../types/v1/checko
25
24
  export declare class ChargeService implements IChargeService {
26
25
  private readonly http;
27
26
  constructor(http: IHttpClient);
28
- /** GET /v1/checkout/order/{orderReference} */
27
+ /**
28
+ * `GET /v1/checkout/order/{orderReference}`.
29
+ * @param orderReference The order's reference, from `nomba.checkout.createOrder`.
30
+ * @returns The order's details.
31
+ * @throws {NombaError} The call failed, e.g. `orderReference` does not exist.
32
+ */
29
33
  getOrder(orderReference: string): Promise<ChargeOrder>;
30
- /** POST /v1/checkout/checkout-card-detail */
31
- submitCardDetails(params: SubmitCardDetailsParams, options?: RequestOptions): Promise<SubmitCardDetailsResult>;
32
- /** POST /v1/checkout/checkout-card-otp */
33
- submitCardOtp(params: SubmitCardOtpParams, options?: RequestOptions): Promise<SubmitCardOtpResult>;
34
- /** POST /v1/checkout/resend-otp. Resends the payment OTP to the customer's phone. */
35
- resendOtp(orderReference: string, options?: RequestOptions): Promise<CheckoutResult>;
36
- /** POST /v1/checkout/confirm-transaction-receipt. The status after the OTP is submitted or a transfer is made. */
34
+ /**
35
+ * `POST /v1/checkout/checkout-card-detail`.
36
+ * @param params The order reference and card details to charge.
37
+ * @returns The result of submitting the card; an OTP is typically sent next.
38
+ * @throws {NombaError} The call failed, e.g. the card was declined.
39
+ * @throws {OutcomeUnknownError} The call failed in a way that does not say whether it was processed.
40
+ */
41
+ submitCardDetails(params: SubmitCardDetailsParams): Promise<SubmitCardDetailsResult>;
42
+ /**
43
+ * `POST /v1/checkout/checkout-card-otp`.
44
+ * @param params The order reference and OTP the customer received.
45
+ * @returns The result of submitting the OTP.
46
+ * @throws {NombaError} The call failed, e.g. the OTP was wrong or expired.
47
+ * @throws {OutcomeUnknownError} The call failed in a way that does not say whether it was processed.
48
+ */
49
+ submitCardOtp(params: SubmitCardOtpParams): Promise<SubmitCardOtpResult>;
50
+ /**
51
+ * `POST /v1/checkout/resend-otp`. Resends the payment OTP to the customer's phone.
52
+ * @param orderReference The order's reference.
53
+ * @throws {NombaError} The call failed, e.g. `orderReference` does not exist.
54
+ * @throws {OutcomeUnknownError} The call failed in a way that does not say whether it was processed.
55
+ */
56
+ resendOtp(orderReference: string): Promise<CheckoutResult>;
57
+ /**
58
+ * `POST /v1/checkout/confirm-transaction-receipt`. The status after the OTP is submitted or a transfer
59
+ * is made.
60
+ * @param orderReference The order's reference.
61
+ * @returns The transaction's current status.
62
+ * @throws {NombaError} The call failed, e.g. `orderReference` does not exist.
63
+ */
37
64
  fetchTransactionDetails(orderReference: string): Promise<ChargeTransactionDetails>;
38
- /** GET /v1/checkout/get-checkout-kta/{orderReference}. A Flash account number the customer can pay by transfer. */
65
+ /**
66
+ * `GET /v1/checkout/get-checkout-kta/{orderReference}`. A Flash account number the customer can pay by
67
+ * transfer.
68
+ * @param orderReference The order's reference.
69
+ * @returns The Flash account to transfer payment to.
70
+ * @throws {NombaError} The call failed, e.g. `orderReference` does not exist.
71
+ */
39
72
  fetchFlashAccount(orderReference: string): Promise<FlashAccount>;
40
- /** POST /v1/checkout/transaction/cancel. Cancels an incomplete checkout transaction. */
41
- cancelTransaction(params: CancelChargeTransactionParams, options?: RequestOptions): Promise<CheckoutResult>;
42
- /** POST /v1/checkout/user-card/saved-card/auth. Sends an OTP; use when getOrder says the user has saved cards. */
43
- requestSavedCardsOtp(orderReference: string, options?: RequestOptions): Promise<CheckoutResult>;
44
- /** GET /v1/checkout/user-card/{orderReference}. Needs the OTP from requestSavedCardsOtp. */
73
+ /**
74
+ * `POST /v1/checkout/transaction/cancel`. Cancels an incomplete checkout transaction.
75
+ * @param params The order reference to cancel.
76
+ * @throws {NombaError} The call failed, e.g. the transaction already completed.
77
+ * @throws {OutcomeUnknownError} The call failed in a way that does not say whether it was processed.
78
+ */
79
+ cancelTransaction(params: CancelChargeTransactionParams): Promise<CheckoutResult>;
80
+ /**
81
+ * `POST /v1/checkout/user-card/saved-card/auth`. Sends an OTP; use when `getOrder` says the user has
82
+ * saved cards.
83
+ * @param orderReference The order's reference.
84
+ * @throws {NombaError} The call failed, e.g. `orderReference` does not exist.
85
+ * @throws {OutcomeUnknownError} The call failed in a way that does not say whether it was processed.
86
+ */
87
+ requestSavedCardsOtp(orderReference: string): Promise<CheckoutResult>;
88
+ /**
89
+ * `GET /v1/checkout/user-card/{orderReference}`. Needs the OTP from `requestSavedCardsOtp`.
90
+ * @param orderReference The order's reference.
91
+ * @param otp The OTP sent by `requestSavedCardsOtp`.
92
+ * @returns The customer's saved, tokenized cards.
93
+ * @throws {NombaError} The call failed, e.g. the OTP was wrong or expired.
94
+ */
45
95
  getSavedCards(orderReference: string, otp: string): Promise<{
46
96
  tokenizedCardData?: TokenizedCardData[];
47
97
  }>;
48
- /** POST /v1/checkout/user-card/auth. Sends an OTP before saving a card; call after a successful payment. */
49
- requestSaveCardOtp(params: SaveCardOtpRequest, options?: RequestOptions): Promise<CheckoutResult>;
50
- /** POST /v1/checkout/user-card. Submits the OTP, which saves the card for later use. */
51
- submitSaveCardOtp(params: SubmitSaveCardOtpParams, options?: RequestOptions): Promise<CheckoutResult>;
98
+ /**
99
+ * `POST /v1/checkout/user-card/auth`. Sends an OTP before saving a card; call after a successful
100
+ * payment.
101
+ * @param params The order reference and card to save.
102
+ * @throws {NombaError} The call failed, e.g. `orderReference` does not exist.
103
+ * @throws {OutcomeUnknownError} The call failed in a way that does not say whether it was processed.
104
+ */
105
+ requestSaveCardOtp(params: SaveCardOtpRequest): Promise<CheckoutResult>;
106
+ /**
107
+ * `POST /v1/checkout/user-card`. Submits the OTP, which saves the card for later use.
108
+ * @param params The order reference and OTP from `requestSaveCardOtp`.
109
+ * @throws {NombaError} The call failed, e.g. the OTP was wrong or expired.
110
+ * @throws {OutcomeUnknownError} The call failed in a way that does not say whether it was processed.
111
+ */
112
+ submitSaveCardOtp(params: SubmitSaveCardOtpParams): Promise<CheckoutResult>;
52
113
  }
@@ -23,13 +23,24 @@ export class ChargeService {
23
23
  constructor(http) {
24
24
  this.http = http;
25
25
  }
26
- /** GET /v1/checkout/order/{orderReference} */
26
+ /**
27
+ * `GET /v1/checkout/order/{orderReference}`.
28
+ * @param orderReference The order's reference, from `nomba.checkout.createOrder`.
29
+ * @returns The order's details.
30
+ * @throws {NombaError} The call failed, e.g. `orderReference` does not exist.
31
+ */
27
32
  async getOrder(orderReference) {
28
33
  return this.http.request("GET", `/v1/checkout/order/${pathId(orderReference)}`);
29
34
  }
30
- /** POST /v1/checkout/checkout-card-detail */
31
- async submitCardDetails(params, options = {}) {
32
- const { cardDetails } = params;
35
+ /**
36
+ * `POST /v1/checkout/checkout-card-detail`.
37
+ * @param params The order reference and card details to charge.
38
+ * @returns The result of submitting the card; an OTP is typically sent next.
39
+ * @throws {NombaError} The call failed, e.g. the card was declined.
40
+ * @throws {OutcomeUnknownError} The call failed in a way that does not say whether it was processed.
41
+ */
42
+ async submitCardDetails(params) {
43
+ const { cardDetails, orderReference } = params;
33
44
  return this.http.request("POST", "/v1/checkout/checkout-card-detail", {
34
45
  body: {
35
46
  ...params,
@@ -37,63 +48,114 @@ export class ChargeService {
37
48
  cardDetails: JSON.stringify(cardDetails),
38
49
  }),
39
50
  },
40
- ...options,
51
+ ...(orderReference && { idempotencyKey: orderReference }),
41
52
  });
42
53
  }
43
- /** POST /v1/checkout/checkout-card-otp */
44
- submitCardOtp(params, options = {}) {
54
+ /**
55
+ * `POST /v1/checkout/checkout-card-otp`.
56
+ * @param params The order reference and OTP the customer received.
57
+ * @returns The result of submitting the OTP.
58
+ * @throws {NombaError} The call failed, e.g. the OTP was wrong or expired.
59
+ * @throws {OutcomeUnknownError} The call failed in a way that does not say whether it was processed.
60
+ */
61
+ submitCardOtp(params) {
45
62
  return this.http.request("POST", "/v1/checkout/checkout-card-otp", {
46
63
  body: params,
47
- ...options,
64
+ idempotencyKey: params.transactionId,
48
65
  });
49
66
  }
50
- /** POST /v1/checkout/resend-otp. Resends the payment OTP to the customer's phone. */
51
- resendOtp(orderReference, options = {}) {
67
+ /**
68
+ * `POST /v1/checkout/resend-otp`. Resends the payment OTP to the customer's phone.
69
+ * @param orderReference The order's reference.
70
+ * @throws {NombaError} The call failed, e.g. `orderReference` does not exist.
71
+ * @throws {OutcomeUnknownError} The call failed in a way that does not say whether it was processed.
72
+ */
73
+ resendOtp(orderReference) {
52
74
  return this.http.request("POST", "/v1/checkout/resend-otp", {
53
75
  body: { orderReference },
54
- ...options,
76
+ idempotencyKey: orderReference,
55
77
  });
56
78
  }
57
- /** POST /v1/checkout/confirm-transaction-receipt. The status after the OTP is submitted or a transfer is made. */
79
+ /**
80
+ * `POST /v1/checkout/confirm-transaction-receipt`. The status after the OTP is submitted or a transfer
81
+ * is made.
82
+ * @param orderReference The order's reference.
83
+ * @returns The transaction's current status.
84
+ * @throws {NombaError} The call failed, e.g. `orderReference` does not exist.
85
+ */
58
86
  fetchTransactionDetails(orderReference) {
59
87
  return this.http.request("POST", "/v1/checkout/confirm-transaction-receipt", {
60
88
  body: { orderReference },
61
89
  });
62
90
  }
63
- /** GET /v1/checkout/get-checkout-kta/{orderReference}. A Flash account number the customer can pay by transfer. */
91
+ /**
92
+ * `GET /v1/checkout/get-checkout-kta/{orderReference}`. A Flash account number the customer can pay by
93
+ * transfer.
94
+ * @param orderReference The order's reference.
95
+ * @returns The Flash account to transfer payment to.
96
+ * @throws {NombaError} The call failed, e.g. `orderReference` does not exist.
97
+ */
64
98
  async fetchFlashAccount(orderReference) {
65
99
  return this.http.request("GET", `/v1/checkout/get-checkout-kta/${pathId(orderReference)}`);
66
100
  }
67
- /** POST /v1/checkout/transaction/cancel. Cancels an incomplete checkout transaction. */
68
- cancelTransaction(params, options = {}) {
101
+ /**
102
+ * `POST /v1/checkout/transaction/cancel`. Cancels an incomplete checkout transaction.
103
+ * @param params The order reference to cancel.
104
+ * @throws {NombaError} The call failed, e.g. the transaction already completed.
105
+ * @throws {OutcomeUnknownError} The call failed in a way that does not say whether it was processed.
106
+ */
107
+ cancelTransaction(params) {
69
108
  return this.http.request("POST", "/v1/checkout/transaction/cancel", {
70
109
  body: params,
71
- ...options,
110
+ idempotencyKey: params.transactionId,
72
111
  });
73
112
  }
74
- /** POST /v1/checkout/user-card/saved-card/auth. Sends an OTP; use when getOrder says the user has saved cards. */
75
- requestSavedCardsOtp(orderReference, options = {}) {
113
+ /**
114
+ * `POST /v1/checkout/user-card/saved-card/auth`. Sends an OTP; use when `getOrder` says the user has
115
+ * saved cards.
116
+ * @param orderReference The order's reference.
117
+ * @throws {NombaError} The call failed, e.g. `orderReference` does not exist.
118
+ * @throws {OutcomeUnknownError} The call failed in a way that does not say whether it was processed.
119
+ */
120
+ requestSavedCardsOtp(orderReference) {
76
121
  return this.http.request("POST", "/v1/checkout/user-card/saved-card/auth", {
77
122
  body: { orderReference },
78
- ...options,
123
+ idempotencyKey: orderReference,
79
124
  });
80
125
  }
81
- /** GET /v1/checkout/user-card/{orderReference}. Needs the OTP from requestSavedCardsOtp. */
126
+ /**
127
+ * `GET /v1/checkout/user-card/{orderReference}`. Needs the OTP from `requestSavedCardsOtp`.
128
+ * @param orderReference The order's reference.
129
+ * @param otp The OTP sent by `requestSavedCardsOtp`.
130
+ * @returns The customer's saved, tokenized cards.
131
+ * @throws {NombaError} The call failed, e.g. the OTP was wrong or expired.
132
+ */
82
133
  async getSavedCards(orderReference, otp) {
83
134
  return this.http.request("GET", `/v1/checkout/user-card/${pathId(orderReference)}`, { query: { otp } });
84
135
  }
85
- /** POST /v1/checkout/user-card/auth. Sends an OTP before saving a card; call after a successful payment. */
86
- requestSaveCardOtp(params, options = {}) {
136
+ /**
137
+ * `POST /v1/checkout/user-card/auth`. Sends an OTP before saving a card; call after a successful
138
+ * payment.
139
+ * @param params The order reference and card to save.
140
+ * @throws {NombaError} The call failed, e.g. `orderReference` does not exist.
141
+ * @throws {OutcomeUnknownError} The call failed in a way that does not say whether it was processed.
142
+ */
143
+ requestSaveCardOtp(params) {
87
144
  return this.http.request("POST", "/v1/checkout/user-card/auth", {
88
145
  body: params,
89
- ...options,
146
+ idempotencyKey: params.orderReference,
90
147
  });
91
148
  }
92
- /** POST /v1/checkout/user-card. Submits the OTP, which saves the card for later use. */
93
- submitSaveCardOtp(params, options = {}) {
149
+ /**
150
+ * `POST /v1/checkout/user-card`. Submits the OTP, which saves the card for later use.
151
+ * @param params The order reference and OTP from `requestSaveCardOtp`.
152
+ * @throws {NombaError} The call failed, e.g. the OTP was wrong or expired.
153
+ * @throws {OutcomeUnknownError} The call failed in a way that does not say whether it was processed.
154
+ */
155
+ submitSaveCardOtp(params) {
94
156
  return this.http.request("POST", "/v1/checkout/user-card", {
95
157
  body: params,
96
- ...options,
158
+ idempotencyKey: params.orderReference,
97
159
  });
98
160
  }
99
161
  }