@lukadriel/wave-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.
Files changed (185) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +2 -0
  4. package/README.md +523 -2
  5. package/dist/client/wave-client-options.d.ts +29 -0
  6. package/dist/client/wave-client-options.d.ts.map +1 -0
  7. package/dist/client/wave-client-options.js +58 -0
  8. package/dist/client/wave-client-options.js.map +1 -0
  9. package/dist/client/wave-client.d.ts +47 -0
  10. package/dist/client/wave-client.d.ts.map +1 -0
  11. package/dist/client/wave-client.js +66 -0
  12. package/dist/client/wave-client.js.map +1 -0
  13. package/dist/core/auth/authentication.d.ts +8 -0
  14. package/dist/core/auth/authentication.d.ts.map +1 -0
  15. package/dist/core/auth/authentication.js +10 -0
  16. package/dist/core/auth/authentication.js.map +1 -0
  17. package/dist/core/auth/request-signer.d.ts +26 -0
  18. package/dist/core/auth/request-signer.d.ts.map +1 -0
  19. package/dist/core/auth/request-signer.js +39 -0
  20. package/dist/core/auth/request-signer.js.map +1 -0
  21. package/dist/core/errors/error-parser.d.ts +25 -0
  22. package/dist/core/errors/error-parser.d.ts.map +1 -0
  23. package/dist/core/errors/error-parser.js +198 -0
  24. package/dist/core/errors/error-parser.js.map +1 -0
  25. package/dist/core/errors/redact.d.ts +11 -0
  26. package/dist/core/errors/redact.d.ts.map +1 -0
  27. package/dist/core/errors/redact.js +20 -0
  28. package/dist/core/errors/redact.js.map +1 -0
  29. package/dist/core/errors/wave-api-error.d.ts +116 -0
  30. package/dist/core/errors/wave-api-error.d.ts.map +1 -0
  31. package/dist/core/errors/wave-api-error.js +114 -0
  32. package/dist/core/errors/wave-api-error.js.map +1 -0
  33. package/dist/core/errors/wave-error.d.ts +27 -0
  34. package/dist/core/errors/wave-error.d.ts.map +1 -0
  35. package/dist/core/errors/wave-error.js +22 -0
  36. package/dist/core/errors/wave-error.js.map +1 -0
  37. package/dist/core/errors/wave-network-error.d.ts +24 -0
  38. package/dist/core/errors/wave-network-error.d.ts.map +1 -0
  39. package/dist/core/errors/wave-network-error.js +24 -0
  40. package/dist/core/errors/wave-network-error.js.map +1 -0
  41. package/dist/core/errors/wave-webhook-verification-error.d.ts +18 -0
  42. package/dist/core/errors/wave-webhook-verification-error.d.ts.map +1 -0
  43. package/dist/core/errors/wave-webhook-verification-error.js +17 -0
  44. package/dist/core/errors/wave-webhook-verification-error.js.map +1 -0
  45. package/dist/core/http/fetch-transport.d.ts +23 -0
  46. package/dist/core/http/fetch-transport.d.ts.map +1 -0
  47. package/dist/core/http/fetch-transport.js +34 -0
  48. package/dist/core/http/fetch-transport.js.map +1 -0
  49. package/dist/core/http/http-client.d.ts +57 -0
  50. package/dist/core/http/http-client.d.ts.map +1 -0
  51. package/dist/core/http/http-client.js +254 -0
  52. package/dist/core/http/http-client.js.map +1 -0
  53. package/dist/core/http/http-request.d.ts +35 -0
  54. package/dist/core/http/http-request.d.ts.map +1 -0
  55. package/dist/core/http/http-request.js +2 -0
  56. package/dist/core/http/http-request.js.map +1 -0
  57. package/dist/core/http/http-response.d.ts +26 -0
  58. package/dist/core/http/http-response.d.ts.map +1 -0
  59. package/dist/core/http/http-response.js +23 -0
  60. package/dist/core/http/http-response.js.map +1 -0
  61. package/dist/core/http/query.d.ts +14 -0
  62. package/dist/core/http/query.d.ts.map +1 -0
  63. package/dist/core/http/query.js +23 -0
  64. package/dist/core/http/query.js.map +1 -0
  65. package/dist/core/http/transport.d.ts +44 -0
  66. package/dist/core/http/transport.d.ts.map +1 -0
  67. package/dist/core/http/transport.js +2 -0
  68. package/dist/core/http/transport.js.map +1 -0
  69. package/dist/core/idempotency/idempotency.d.ts +16 -0
  70. package/dist/core/idempotency/idempotency.d.ts.map +1 -0
  71. package/dist/core/idempotency/idempotency.js +27 -0
  72. package/dist/core/idempotency/idempotency.js.map +1 -0
  73. package/dist/core/retry/backoff.d.ts +18 -0
  74. package/dist/core/retry/backoff.d.ts.map +1 -0
  75. package/dist/core/retry/backoff.js +46 -0
  76. package/dist/core/retry/backoff.js.map +1 -0
  77. package/dist/core/retry/retry-policy.d.ts +43 -0
  78. package/dist/core/retry/retry-policy.d.ts.map +1 -0
  79. package/dist/core/retry/retry-policy.js +90 -0
  80. package/dist/core/retry/retry-policy.js.map +1 -0
  81. package/dist/core/types/common.d.ts +59 -0
  82. package/dist/core/types/common.d.ts.map +1 -0
  83. package/dist/core/types/common.js +2 -0
  84. package/dist/core/types/common.js.map +1 -0
  85. package/dist/core/types/configuration.d.ts +82 -0
  86. package/dist/core/types/configuration.d.ts.map +1 -0
  87. package/dist/core/types/configuration.js +2 -0
  88. package/dist/core/types/configuration.js.map +1 -0
  89. package/dist/core/types/json.d.ts +15 -0
  90. package/dist/core/types/json.d.ts.map +1 -0
  91. package/dist/core/types/json.js +2 -0
  92. package/dist/core/types/json.js.map +1 -0
  93. package/dist/index.d.ts +39 -0
  94. package/dist/index.d.ts.map +1 -0
  95. package/dist/index.js +24 -0
  96. package/dist/index.js.map +1 -0
  97. package/dist/resources/aggregated-merchants/aggregated-merchant-types.d.ts +82 -0
  98. package/dist/resources/aggregated-merchants/aggregated-merchant-types.d.ts.map +1 -0
  99. package/dist/resources/aggregated-merchants/aggregated-merchant-types.js +2 -0
  100. package/dist/resources/aggregated-merchants/aggregated-merchant-types.js.map +1 -0
  101. package/dist/resources/aggregated-merchants/aggregated-merchants.d.ts +67 -0
  102. package/dist/resources/aggregated-merchants/aggregated-merchants.d.ts.map +1 -0
  103. package/dist/resources/aggregated-merchants/aggregated-merchants.js +111 -0
  104. package/dist/resources/aggregated-merchants/aggregated-merchants.js.map +1 -0
  105. package/dist/resources/balance/balance-types.d.ts +18 -0
  106. package/dist/resources/balance/balance-types.d.ts.map +1 -0
  107. package/dist/resources/balance/balance-types.js +2 -0
  108. package/dist/resources/balance/balance-types.js.map +1 -0
  109. package/dist/resources/balance/balance.d.ts +20 -0
  110. package/dist/resources/balance/balance.d.ts.map +1 -0
  111. package/dist/resources/balance/balance.js +28 -0
  112. package/dist/resources/balance/balance.js.map +1 -0
  113. package/dist/resources/checkout/checkout-types.d.ts +96 -0
  114. package/dist/resources/checkout/checkout-types.d.ts.map +1 -0
  115. package/dist/resources/checkout/checkout-types.js +2 -0
  116. package/dist/resources/checkout/checkout-types.js.map +1 -0
  117. package/dist/resources/checkout/checkout.d.ts +66 -0
  118. package/dist/resources/checkout/checkout.d.ts.map +1 -0
  119. package/dist/resources/checkout/checkout.js +95 -0
  120. package/dist/resources/checkout/checkout.js.map +1 -0
  121. package/dist/resources/payout-batches/payout-batches.d.ts +31 -0
  122. package/dist/resources/payout-batches/payout-batches.d.ts.map +1 -0
  123. package/dist/resources/payout-batches/payout-batches.js +36 -0
  124. package/dist/resources/payout-batches/payout-batches.js.map +1 -0
  125. package/dist/resources/payouts/payout-types.d.ts +158 -0
  126. package/dist/resources/payouts/payout-types.d.ts.map +1 -0
  127. package/dist/resources/payouts/payout-types.js +2 -0
  128. package/dist/resources/payouts/payout-types.js.map +1 -0
  129. package/dist/resources/payouts/payouts.d.ts +63 -0
  130. package/dist/resources/payouts/payouts.d.ts.map +1 -0
  131. package/dist/resources/payouts/payouts.js +80 -0
  132. package/dist/resources/payouts/payouts.js.map +1 -0
  133. package/dist/resources/reconciliation/reconciliation-types.d.ts +86 -0
  134. package/dist/resources/reconciliation/reconciliation-types.d.ts.map +1 -0
  135. package/dist/resources/reconciliation/reconciliation-types.js +2 -0
  136. package/dist/resources/reconciliation/reconciliation-types.js.map +1 -0
  137. package/dist/resources/reconciliation/reconciliation.d.ts +41 -0
  138. package/dist/resources/reconciliation/reconciliation.d.ts.map +1 -0
  139. package/dist/resources/reconciliation/reconciliation.js +81 -0
  140. package/dist/resources/reconciliation/reconciliation.js.map +1 -0
  141. package/dist/resources/webhooks/webhook-types.d.ts +159 -0
  142. package/dist/resources/webhooks/webhook-types.d.ts.map +1 -0
  143. package/dist/resources/webhooks/webhook-types.js +36 -0
  144. package/dist/resources/webhooks/webhook-types.js.map +1 -0
  145. package/dist/resources/webhooks/webhook-verifier.d.ts +104 -0
  146. package/dist/resources/webhooks/webhook-verifier.d.ts.map +1 -0
  147. package/dist/resources/webhooks/webhook-verifier.js +188 -0
  148. package/dist/resources/webhooks/webhook-verifier.js.map +1 -0
  149. package/package.json +70 -4
  150. package/src/client/wave-client-options.ts +91 -0
  151. package/src/client/wave-client.ts +70 -0
  152. package/src/core/auth/authentication.ts +9 -0
  153. package/src/core/auth/request-signer.ts +42 -0
  154. package/src/core/errors/error-parser.ts +258 -0
  155. package/src/core/errors/redact.ts +20 -0
  156. package/src/core/errors/wave-api-error.ts +148 -0
  157. package/src/core/errors/wave-error.ts +32 -0
  158. package/src/core/errors/wave-network-error.ts +24 -0
  159. package/src/core/errors/wave-webhook-verification-error.ts +28 -0
  160. package/src/core/http/fetch-transport.ts +48 -0
  161. package/src/core/http/http-client.ts +352 -0
  162. package/src/core/http/http-request.ts +37 -0
  163. package/src/core/http/http-response.ts +37 -0
  164. package/src/core/http/query.ts +31 -0
  165. package/src/core/http/transport.ts +45 -0
  166. package/src/core/idempotency/idempotency.ts +31 -0
  167. package/src/core/retry/backoff.ts +61 -0
  168. package/src/core/retry/retry-policy.ts +106 -0
  169. package/src/core/types/common.ts +65 -0
  170. package/src/core/types/configuration.ts +85 -0
  171. package/src/core/types/json.ts +16 -0
  172. package/src/index.ts +146 -0
  173. package/src/resources/aggregated-merchants/aggregated-merchant-types.ts +87 -0
  174. package/src/resources/aggregated-merchants/aggregated-merchants.ts +171 -0
  175. package/src/resources/balance/balance-types.ts +19 -0
  176. package/src/resources/balance/balance.ts +39 -0
  177. package/src/resources/checkout/checkout-types.ts +102 -0
  178. package/src/resources/checkout/checkout.ts +144 -0
  179. package/src/resources/payout-batches/payout-batches.ts +58 -0
  180. package/src/resources/payouts/payout-types.ts +171 -0
  181. package/src/resources/payouts/payouts.ts +120 -0
  182. package/src/resources/reconciliation/reconciliation-types.ts +102 -0
  183. package/src/resources/reconciliation/reconciliation.ts +116 -0
  184. package/src/resources/webhooks/webhook-types.ts +222 -0
  185. package/src/resources/webhooks/webhook-verifier.ts +297 -0
@@ -0,0 +1,39 @@
1
+ import type { HttpClient } from '../../core/http/http-client.js';
2
+ import type { RequestOptions } from '../../core/types/configuration.js';
3
+ import type { Balance, RetrieveBalanceQuery } from './balance-types.js';
4
+
5
+ const GET_BALANCE = { idempotent: true, requiresIdempotencyKey: false } as const;
6
+
7
+ /**
8
+ * Balance API operations.
9
+ */
10
+ export class BalanceResource {
11
+ readonly #http: HttpClient;
12
+
13
+ /** @param http - Shared HTTP pipeline. */
14
+ constructor(http: HttpClient) {
15
+ this.#http = http;
16
+ }
17
+
18
+ /**
19
+ * Retrieves the balance of the wallet associated with the API key.
20
+ *
21
+ * @param query - Optional subaccount inclusion.
22
+ * @param options - Per-request overrides.
23
+ * @returns The wallet balance.
24
+ */
25
+ retrieve(query: RetrieveBalanceQuery = {}, options: RequestOptions = {}): Promise<Balance> {
26
+ return this.#http.request<Balance>(
27
+ GET_BALANCE,
28
+ {
29
+ method: 'GET',
30
+ path: '/v1/balance',
31
+ query:
32
+ query.include_subaccounts === undefined
33
+ ? {}
34
+ : { include_subaccounts: query.include_subaccounts },
35
+ },
36
+ options,
37
+ );
38
+ }
39
+ }
@@ -0,0 +1,102 @@
1
+ import type { Amount, CurrencyCode, Timestamp } from '../../core/types/common.js';
2
+
3
+ /**
4
+ * Documented checkout session states.
5
+ */
6
+ export type CheckoutStatus = 'open' | 'complete' | 'expired';
7
+
8
+ /**
9
+ * Documented payment states for a checkout session.
10
+ */
11
+ export type PaymentStatus = 'processing' | 'cancelled' | 'succeeded';
12
+
13
+ /**
14
+ * Reason for the last failed payment attempt on a checkout session.
15
+ */
16
+ export interface CheckoutPaymentError {
17
+ /** Short machine-readable error code. */
18
+ readonly code: string;
19
+ /** Human-readable description. */
20
+ readonly message: string;
21
+ }
22
+
23
+ /**
24
+ * The Checkout Session object.
25
+ */
26
+ export interface CheckoutSession {
27
+ /** Unique session identifier, up to 20 characters. */
28
+ readonly id: string;
29
+ /** Total amount collected from the customer, gross of fees. */
30
+ readonly amount: Amount;
31
+ /** Checkout state. */
32
+ readonly checkout_status: CheckoutStatus;
33
+ /** Caller correlation string, or `null` when not provided. */
34
+ readonly client_reference: string | null;
35
+ /** Three-letter ISO 4217 currency code. */
36
+ readonly currency: CurrencyCode;
37
+ /** URL the customer is sent to when a payment attempt fails. */
38
+ readonly error_url: string;
39
+ /** Reason for the last failed payment attempt, or `null` when none. */
40
+ readonly last_payment_error: CheckoutPaymentError | null;
41
+ /** Business name shown to the customer. */
42
+ readonly business_name: string;
43
+ /** State of the associated payment. */
44
+ readonly payment_status: PaymentStatus;
45
+ /** Wave transaction identifier visible in the customer's app. */
46
+ readonly transaction_id: string;
47
+ /** Aggregated merchant identity used for this checkout, when applicable. */
48
+ readonly aggregated_merchant_id?: string;
49
+ /** Payer restriction currently stored on the session, when set. */
50
+ readonly restrict_payer_mobile?: string;
51
+ /** URL the customer is sent to when the payment succeeds. */
52
+ readonly success_url: string;
53
+ /** URL that opens the Wave app to complete the checkout. */
54
+ readonly wave_launch_url: string;
55
+ /** When the session succeeded or expired; absent while the session is open. */
56
+ readonly when_completed?: Timestamp;
57
+ /** When the session was created. */
58
+ readonly when_created: Timestamp;
59
+ /** When the session expires (30 minutes after creation by default). */
60
+ readonly when_expires: Timestamp;
61
+ }
62
+
63
+ /**
64
+ * Request body for `POST /v1/checkout/sessions`.
65
+ */
66
+ export interface CreateCheckoutSessionRequest {
67
+ /** Total amount to collect, gross of fees. */
68
+ readonly amount: Amount;
69
+ /** Three-letter ISO 4217 currency code. */
70
+ readonly currency: CurrencyCode;
71
+ /** Fully qualified HTTPS URL for failed payments. */
72
+ readonly error_url: string;
73
+ /** Fully qualified HTTPS URL for successful payments. */
74
+ readonly success_url: string;
75
+ /** Caller correlation string, up to 255 characters. */
76
+ readonly client_reference?: string;
77
+ /**
78
+ * Restrict payment to the Wave account with this E.164 number.
79
+ *
80
+ * Wave previously named this field `enforce_payer_mobile`; the old name is documented as still
81
+ * accepted but deprecated.
82
+ */
83
+ readonly restrict_payer_mobile?: string;
84
+ /** Aggregated merchant identity; only available to permitted aggregators. */
85
+ readonly aggregated_merchant_id?: string;
86
+ }
87
+
88
+ /**
89
+ * Query parameters for `GET /v1/checkout/sessions/search`.
90
+ */
91
+ export interface SearchCheckoutSessionsQuery {
92
+ /** Caller correlation string to search for. */
93
+ readonly client_reference: string;
94
+ }
95
+
96
+ /**
97
+ * Response body of `GET /v1/checkout/sessions/search`.
98
+ */
99
+ export interface SearchCheckoutSessionsResponse {
100
+ /** Matching checkout sessions. */
101
+ readonly result: readonly CheckoutSession[];
102
+ }
@@ -0,0 +1,144 @@
1
+ import type { HttpClient } from '../../core/http/http-client.js';
2
+ import type { RequestOptions } from '../../core/types/configuration.js';
3
+ import type {
4
+ CheckoutSession,
5
+ CreateCheckoutSessionRequest,
6
+ SearchCheckoutSessionsQuery,
7
+ SearchCheckoutSessionsResponse,
8
+ } from './checkout-types.js';
9
+
10
+ const CREATE_SESSION = { idempotent: false, requiresIdempotencyKey: false } as const;
11
+ const GET_SESSION = { idempotent: true, requiresIdempotencyKey: false } as const;
12
+ const REFUND_SESSION = { idempotent: true, requiresIdempotencyKey: true } as const;
13
+ const EXPIRE_SESSION = { idempotent: false, requiresIdempotencyKey: false } as const;
14
+
15
+ /**
16
+ * Checkout API operations.
17
+ */
18
+ export class CheckoutResource {
19
+ readonly #http: HttpClient;
20
+
21
+ /** @param http - Shared HTTP pipeline. */
22
+ constructor(http: HttpClient) {
23
+ this.#http = http;
24
+ }
25
+
26
+ /**
27
+ * Creates a checkout session.
28
+ *
29
+ * Wave does not document an idempotency mechanism for this endpoint, so the SDK never retries it
30
+ * automatically. Redirect the customer to `wave_launch_url` in a browser (not a webview).
31
+ *
32
+ * @param request - Session details.
33
+ * @param options - Per-request overrides.
34
+ * @returns The created checkout session.
35
+ */
36
+ createSession(
37
+ request: CreateCheckoutSessionRequest,
38
+ options: RequestOptions = {},
39
+ ): Promise<CheckoutSession> {
40
+ return this.#http.request<CheckoutSession>(
41
+ CREATE_SESSION,
42
+ { method: 'POST', path: '/v1/checkout/sessions', body: request },
43
+ options,
44
+ );
45
+ }
46
+
47
+ /**
48
+ * Retrieves a checkout session by identifier.
49
+ *
50
+ * @param sessionId - Session identifier starting with `cos-`.
51
+ * @param options - Per-request overrides.
52
+ * @returns The checkout session.
53
+ */
54
+ retrieve(sessionId: string, options: RequestOptions = {}): Promise<CheckoutSession> {
55
+ return this.#http.request<CheckoutSession>(
56
+ GET_SESSION,
57
+ { method: 'GET', path: `/v1/checkout/sessions/${encodeURIComponent(sessionId)}` },
58
+ options,
59
+ );
60
+ }
61
+
62
+ /**
63
+ * Retrieves a checkout session by its Wave transaction identifier.
64
+ *
65
+ * @param transactionId - Transaction identifier starting with `T_`.
66
+ * @param options - Per-request overrides.
67
+ * @returns The checkout session.
68
+ */
69
+ retrieveByTransactionId(
70
+ transactionId: string,
71
+ options: RequestOptions = {},
72
+ ): Promise<CheckoutSession> {
73
+ return this.#http.request<CheckoutSession>(
74
+ GET_SESSION,
75
+ {
76
+ method: 'GET',
77
+ path: '/v1/checkout/sessions',
78
+ query: { transaction_id: transactionId },
79
+ },
80
+ options,
81
+ );
82
+ }
83
+
84
+ /**
85
+ * Searches checkout sessions by client reference.
86
+ *
87
+ * @param query - Search criteria.
88
+ * @param options - Per-request overrides.
89
+ * @returns Matching checkout sessions.
90
+ */
91
+ search(
92
+ query: SearchCheckoutSessionsQuery,
93
+ options: RequestOptions = {},
94
+ ): Promise<SearchCheckoutSessionsResponse> {
95
+ return this.#http.request<SearchCheckoutSessionsResponse>(
96
+ GET_SESSION,
97
+ {
98
+ method: 'GET',
99
+ path: '/v1/checkout/sessions/search',
100
+ query: { client_reference: query.client_reference },
101
+ },
102
+ options,
103
+ );
104
+ }
105
+
106
+ /**
107
+ * Refunds the payment associated with a checkout session.
108
+ *
109
+ * Refunding twice returns HTTP 200 without creating another transaction.
110
+ *
111
+ * @param sessionId - Session identifier starting with `cos-`.
112
+ * @param options - Per-request overrides.
113
+ */
114
+ refund(sessionId: string, options: RequestOptions = {}): Promise<void> {
115
+ return this.#http.requestVoid(
116
+ REFUND_SESSION,
117
+ {
118
+ method: 'POST',
119
+ path: `/v1/checkout/sessions/${encodeURIComponent(sessionId)}/refund`,
120
+ },
121
+ options,
122
+ );
123
+ }
124
+
125
+ /**
126
+ * Expires an open checkout session.
127
+ *
128
+ * Wave documents HTTP 409 when the session is already complete or expired, so retries are not
129
+ * performed automatically.
130
+ *
131
+ * @param sessionId - Session identifier starting with `cos-`.
132
+ * @param options - Per-request overrides.
133
+ */
134
+ expire(sessionId: string, options: RequestOptions = {}): Promise<void> {
135
+ return this.#http.requestVoid(
136
+ EXPIRE_SESSION,
137
+ {
138
+ method: 'POST',
139
+ path: `/v1/checkout/sessions/${encodeURIComponent(sessionId)}/expire`,
140
+ },
141
+ options,
142
+ );
143
+ }
144
+ }
@@ -0,0 +1,58 @@
1
+ import type { HttpClient } from '../../core/http/http-client.js';
2
+ import type { RequestOptions } from '../../core/types/configuration.js';
3
+ import type {
4
+ CreatePayoutBatchRequest,
5
+ CreatePayoutBatchResponse,
6
+ PayoutBatch,
7
+ } from '../payouts/payout-types.js';
8
+
9
+ const CREATE_BATCH = { idempotent: true, requiresIdempotencyKey: true } as const;
10
+ const GET_BATCH = { idempotent: true, requiresIdempotencyKey: false } as const;
11
+
12
+ /**
13
+ * Payout batch operations.
14
+ */
15
+ export class PayoutBatchesResource {
16
+ readonly #http: HttpClient;
17
+
18
+ /** @param http - Shared HTTP pipeline. */
19
+ constructor(http: HttpClient) {
20
+ this.#http = http;
21
+ }
22
+
23
+ /**
24
+ * Submits a payout batch for asynchronous processing.
25
+ *
26
+ * @param request - Payouts to send.
27
+ * @param options - Per-request overrides.
28
+ * @returns The batch identifier; poll {@link retrieve} for results.
29
+ */
30
+ create(
31
+ request: CreatePayoutBatchRequest,
32
+ options: RequestOptions = {},
33
+ ): Promise<CreatePayoutBatchResponse> {
34
+ return this.#http.request<CreatePayoutBatchResponse>(
35
+ CREATE_BATCH,
36
+ { method: 'POST', path: '/v1/payout-batch', body: request },
37
+ options,
38
+ );
39
+ }
40
+
41
+ /**
42
+ * Retrieves a payout batch and its individual payouts.
43
+ *
44
+ * Wave's endpoint list writes this path as `/v1/payouts-batch/:id`, while the endpoint section and
45
+ * curl example use `/v1/payout-batch/:id`; this SDK follows the latter.
46
+ *
47
+ * @param batchId - Batch identifier starting with `pb-`.
48
+ * @param options - Per-request overrides.
49
+ * @returns The payout batch.
50
+ */
51
+ retrieve(batchId: string, options: RequestOptions = {}): Promise<PayoutBatch> {
52
+ return this.#http.request<PayoutBatch>(
53
+ GET_BATCH,
54
+ { method: 'GET', path: `/v1/payout-batch/${encodeURIComponent(batchId)}` },
55
+ options,
56
+ );
57
+ }
58
+ }
@@ -0,0 +1,171 @@
1
+ import type { Amount, CurrencyCode, PhoneNumber, Timestamp } from '../../core/types/common.js';
2
+
3
+ /**
4
+ * Documented payout states.
5
+ *
6
+ * - `processing`: submitted, execution in progress.
7
+ * - `succeeded`: money reached the recipient.
8
+ * - `failed`: execution failed; inspect `payout_error`.
9
+ * - `reversed`: the payout was reversed.
10
+ */
11
+ export type PayoutStatus = 'processing' | 'succeeded' | 'failed' | 'reversed';
12
+
13
+ /**
14
+ * Failure details attached to an individual payout.
15
+ *
16
+ * Wave uses this both for failed payouts and for payouts that fail inside a batch.
17
+ */
18
+ export interface PayoutError {
19
+ /** Machine-readable error code; see the Payout API error list. */
20
+ readonly error_code: string;
21
+ /** Human-readable description, when provided. */
22
+ readonly error_message?: string;
23
+ }
24
+
25
+ /**
26
+ * Request body for `POST /v1/payout`.
27
+ */
28
+ export interface CreatePayoutRequest {
29
+ /** Currency of the payout; the business wallet and recipient must be in the same country. */
30
+ readonly currency: CurrencyCode;
31
+ /** Amount paid to the recipient, net of fees. Payout amounts must be whole numbers. */
32
+ readonly receive_amount: Amount;
33
+ /** Recipient phone number in E.164 format. */
34
+ readonly mobile: PhoneNumber;
35
+ /** Recipient name, up to 255 characters; may be used for verification. */
36
+ readonly name?: string;
37
+ /** Recipient national ID, up to 255 characters. */
38
+ readonly national_id?: string;
39
+ /** Payment reason shown to the customer, up to 40 characters. */
40
+ readonly payment_reason?: string;
41
+ /** Caller correlation string, up to 255 characters. */
42
+ readonly client_reference?: string;
43
+ /** Aggregated merchant identity; only available to permitted aggregators. */
44
+ readonly aggregated_merchant_id?: string;
45
+ }
46
+
47
+ /**
48
+ * A payout object returned by the Payout API.
49
+ */
50
+ export interface Payout {
51
+ /** Unique payout identifier, up to 20 characters. */
52
+ readonly id: string;
53
+ /** Payout currency. */
54
+ readonly currency: CurrencyCode;
55
+ /** Amount paid to the recipient, net of fees. */
56
+ readonly receive_amount: Amount;
57
+ /** Fee charged for the payout. */
58
+ readonly fee: Amount;
59
+ /** Recipient phone number in E.164 format. */
60
+ readonly mobile: PhoneNumber;
61
+ /** Current payout state. */
62
+ readonly status: PayoutStatus;
63
+ /** When the payout request was recorded (not when the money moved). */
64
+ readonly timestamp: Timestamp;
65
+ /** Recipient name, when provided. */
66
+ readonly name?: string;
67
+ /** Recipient national ID, when provided. */
68
+ readonly national_id?: string;
69
+ /** Caller correlation string, when provided. */
70
+ readonly client_reference?: string;
71
+ /** Payment reason, when provided. */
72
+ readonly payment_reason?: string;
73
+ /** Aggregated merchant identity used for this payout, when applicable. */
74
+ readonly aggregated_merchant_id?: string;
75
+ /** Failure details; only populated when `status` is `failed`. */
76
+ readonly payout_error?: PayoutError;
77
+ }
78
+
79
+ /**
80
+ * Query parameters for `GET /v1/payouts/search`.
81
+ *
82
+ * The Payout API currently documents search by client reference only.
83
+ */
84
+ export interface SearchPayoutsQuery {
85
+ /** Caller correlation string to search for. */
86
+ readonly client_reference: string;
87
+ }
88
+
89
+ /**
90
+ * Response body of `GET /v1/payouts/search`.
91
+ */
92
+ export interface SearchPayoutsResponse {
93
+ /** Matching payouts; empty when nothing matches. */
94
+ readonly result: readonly Payout[];
95
+ }
96
+
97
+ /**
98
+ * Request body for `POST /v1/payout-batch`.
99
+ */
100
+ export interface CreatePayoutBatchRequest {
101
+ /** Payouts to send; each item uses the single-payout request shape. */
102
+ readonly payouts: readonly CreatePayoutRequest[];
103
+ }
104
+
105
+ /**
106
+ * Response body of `POST /v1/payout-batch`.
107
+ */
108
+ export interface CreatePayoutBatchResponse {
109
+ /** Batch identifier used to poll the retrieve endpoint. */
110
+ readonly id: string;
111
+ }
112
+
113
+ /**
114
+ * Documented payout batch states.
115
+ *
116
+ * Batches have no success/failure status of their own; inspect each payout's `payout_error`.
117
+ */
118
+ export type PayoutBatchStatus = 'processing' | 'complete';
119
+
120
+ /**
121
+ * A payout batch returned by `GET /v1/payout-batch/:id`.
122
+ */
123
+ export interface PayoutBatch {
124
+ /** Batch identifier. */
125
+ readonly id: string;
126
+ /** Batch state. */
127
+ readonly status: PayoutBatchStatus;
128
+ /** Payouts in the batch, each with the single-payout response shape. */
129
+ readonly payouts: readonly Payout[];
130
+ }
131
+
132
+ /**
133
+ * Outcome of comparing a provided name with Wave's records.
134
+ */
135
+ export type NameMatch = 'MATCH' | 'NO_MATCH' | 'NAME_NOT_KNOWN';
136
+
137
+ /**
138
+ * Outcome of comparing a provided national ID with Wave's records.
139
+ */
140
+ export type NationalIdMatch = 'MATCH' | 'NO_MATCH' | 'ID_NOT_KNOWN';
141
+
142
+ /**
143
+ * Request body for the restricted `POST /v1/verify_recipient/` endpoint.
144
+ *
145
+ * This endpoint is disabled by default and enabled case by case for businesses with a documented
146
+ * compliance justification; it returns HTTP 403 without access.
147
+ */
148
+ export interface VerifyRecipientRequest {
149
+ /** Recipient phone number in E.164 format. */
150
+ readonly mobile: PhoneNumber;
151
+ /** Name to compare with Wave's records. */
152
+ readonly name?: string;
153
+ /** National ID to compare with Wave's records. */
154
+ readonly national_id?: string;
155
+ /** Hypothetical amount, used to check balance and inflow limits. */
156
+ readonly amount?: Amount;
157
+ /** Currency of the hypothetical amount. */
158
+ readonly currency?: CurrencyCode;
159
+ }
160
+
161
+ /**
162
+ * Response body of `POST /v1/verify_recipient/`.
163
+ */
164
+ export interface RecipientVerification {
165
+ /** Whether the payout is likely to succeed; `null` when amount and currency were not provided. */
166
+ readonly within_limits: boolean | null;
167
+ /** Name comparison result; `null` when no name was provided. */
168
+ readonly name_match: NameMatch | null;
169
+ /** National ID comparison result; only included when ID verification is enabled. */
170
+ readonly national_id_match?: NationalIdMatch | null;
171
+ }
@@ -0,0 +1,120 @@
1
+ import type { HttpClient } from '../../core/http/http-client.js';
2
+ import type { RequestOptions } from '../../core/types/configuration.js';
3
+ import type {
4
+ CreatePayoutRequest,
5
+ Payout,
6
+ RecipientVerification,
7
+ SearchPayoutsQuery,
8
+ SearchPayoutsResponse,
9
+ VerifyRecipientRequest,
10
+ } from './payout-types.js';
11
+
12
+ const CREATE_PAYOUT = { idempotent: true, requiresIdempotencyKey: true } as const;
13
+ const GET_PAYOUT = { idempotent: true, requiresIdempotencyKey: false } as const;
14
+ const REVERSE_PAYOUT = { idempotent: true, requiresIdempotencyKey: true } as const;
15
+ const VERIFY_RECIPIENT = { idempotent: true, requiresIdempotencyKey: false } as const;
16
+
17
+ /**
18
+ * Payout API operations.
19
+ */
20
+ export class PayoutsResource {
21
+ readonly #http: HttpClient;
22
+
23
+ /** @param http - Shared HTTP pipeline. */
24
+ constructor(http: HttpClient) {
25
+ this.#http = http;
26
+ }
27
+
28
+ /**
29
+ * Sends a payout synchronously.
30
+ *
31
+ * A generated `Idempotency-Key` is reused for every retry of this call, so a transport failure
32
+ * cannot create a duplicate payout.
33
+ *
34
+ * A payout can fail in two documented ways: an HTTP error response, or a `Payout` whose
35
+ * `payout_error` field is populated.
36
+ *
37
+ * @param request - Payout details.
38
+ * @param options - Per-request overrides.
39
+ * @returns The created payout.
40
+ */
41
+ create(request: CreatePayoutRequest, options: RequestOptions = {}): Promise<Payout> {
42
+ return this.#http.request<Payout>(
43
+ CREATE_PAYOUT,
44
+ { method: 'POST', path: '/v1/payout', body: request },
45
+ options,
46
+ );
47
+ }
48
+
49
+ /**
50
+ * Retrieves a single payout by identifier.
51
+ *
52
+ * @param payoutId - Payout identifier starting with `pt-`.
53
+ * @param options - Per-request overrides.
54
+ * @returns The payout.
55
+ */
56
+ retrieve(payoutId: string, options: RequestOptions = {}): Promise<Payout> {
57
+ return this.#http.request<Payout>(
58
+ GET_PAYOUT,
59
+ { method: 'GET', path: `/v1/payout/${encodeURIComponent(payoutId)}` },
60
+ options,
61
+ );
62
+ }
63
+
64
+ /**
65
+ * Searches payouts by client reference.
66
+ *
67
+ * @param query - Search criteria; only `client_reference` is documented.
68
+ * @param options - Per-request overrides.
69
+ * @returns Matching payouts; the array is empty when nothing matches.
70
+ */
71
+ search(query: SearchPayoutsQuery, options: RequestOptions = {}): Promise<SearchPayoutsResponse> {
72
+ return this.#http.request<SearchPayoutsResponse>(
73
+ GET_PAYOUT,
74
+ {
75
+ method: 'GET',
76
+ path: '/v1/payouts/search',
77
+ query: { client_reference: query.client_reference },
78
+ },
79
+ options,
80
+ );
81
+ }
82
+
83
+ /**
84
+ * Reverses a previously executed payout, including fees.
85
+ *
86
+ * Wave allows reversal within three days of creation. The endpoint is idempotent: reversing an
87
+ * already reversed payout succeeds without creating another transaction.
88
+ *
89
+ * @param payoutId - Payout identifier starting with `pt-`.
90
+ * @param options - Per-request overrides.
91
+ */
92
+ reverse(payoutId: string, options: RequestOptions = {}): Promise<void> {
93
+ return this.#http.requestVoid(
94
+ REVERSE_PAYOUT,
95
+ { method: 'POST', path: `/v1/payout/${encodeURIComponent(payoutId)}/reverse` },
96
+ options,
97
+ );
98
+ }
99
+
100
+ /**
101
+ * Verifies payout recipient details before sending money.
102
+ *
103
+ * This endpoint is restricted: it is disabled by default and returns HTTP 403 unless Wave has
104
+ * enabled it for your business. Payouts to unregistered numbers still succeed without it.
105
+ *
106
+ * @param request - Recipient details to check.
107
+ * @param options - Per-request overrides.
108
+ * @returns The documented verification result.
109
+ */
110
+ verifyRecipient(
111
+ request: VerifyRecipientRequest,
112
+ options: RequestOptions = {},
113
+ ): Promise<RecipientVerification> {
114
+ return this.#http.request<RecipientVerification>(
115
+ VERIFY_RECIPIENT,
116
+ { method: 'POST', path: '/v1/verify_recipient/', body: request },
117
+ options,
118
+ );
119
+ }
120
+ }