@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.
- package/CHANGELOG.md +30 -0
- package/LICENSE +201 -0
- package/NOTICE +2 -0
- package/README.md +523 -2
- package/dist/client/wave-client-options.d.ts +29 -0
- package/dist/client/wave-client-options.d.ts.map +1 -0
- package/dist/client/wave-client-options.js +58 -0
- package/dist/client/wave-client-options.js.map +1 -0
- package/dist/client/wave-client.d.ts +47 -0
- package/dist/client/wave-client.d.ts.map +1 -0
- package/dist/client/wave-client.js +66 -0
- package/dist/client/wave-client.js.map +1 -0
- package/dist/core/auth/authentication.d.ts +8 -0
- package/dist/core/auth/authentication.d.ts.map +1 -0
- package/dist/core/auth/authentication.js +10 -0
- package/dist/core/auth/authentication.js.map +1 -0
- package/dist/core/auth/request-signer.d.ts +26 -0
- package/dist/core/auth/request-signer.d.ts.map +1 -0
- package/dist/core/auth/request-signer.js +39 -0
- package/dist/core/auth/request-signer.js.map +1 -0
- package/dist/core/errors/error-parser.d.ts +25 -0
- package/dist/core/errors/error-parser.d.ts.map +1 -0
- package/dist/core/errors/error-parser.js +198 -0
- package/dist/core/errors/error-parser.js.map +1 -0
- package/dist/core/errors/redact.d.ts +11 -0
- package/dist/core/errors/redact.d.ts.map +1 -0
- package/dist/core/errors/redact.js +20 -0
- package/dist/core/errors/redact.js.map +1 -0
- package/dist/core/errors/wave-api-error.d.ts +116 -0
- package/dist/core/errors/wave-api-error.d.ts.map +1 -0
- package/dist/core/errors/wave-api-error.js +114 -0
- package/dist/core/errors/wave-api-error.js.map +1 -0
- package/dist/core/errors/wave-error.d.ts +27 -0
- package/dist/core/errors/wave-error.d.ts.map +1 -0
- package/dist/core/errors/wave-error.js +22 -0
- package/dist/core/errors/wave-error.js.map +1 -0
- package/dist/core/errors/wave-network-error.d.ts +24 -0
- package/dist/core/errors/wave-network-error.d.ts.map +1 -0
- package/dist/core/errors/wave-network-error.js +24 -0
- package/dist/core/errors/wave-network-error.js.map +1 -0
- package/dist/core/errors/wave-webhook-verification-error.d.ts +18 -0
- package/dist/core/errors/wave-webhook-verification-error.d.ts.map +1 -0
- package/dist/core/errors/wave-webhook-verification-error.js +17 -0
- package/dist/core/errors/wave-webhook-verification-error.js.map +1 -0
- package/dist/core/http/fetch-transport.d.ts +23 -0
- package/dist/core/http/fetch-transport.d.ts.map +1 -0
- package/dist/core/http/fetch-transport.js +34 -0
- package/dist/core/http/fetch-transport.js.map +1 -0
- package/dist/core/http/http-client.d.ts +57 -0
- package/dist/core/http/http-client.d.ts.map +1 -0
- package/dist/core/http/http-client.js +254 -0
- package/dist/core/http/http-client.js.map +1 -0
- package/dist/core/http/http-request.d.ts +35 -0
- package/dist/core/http/http-request.d.ts.map +1 -0
- package/dist/core/http/http-request.js +2 -0
- package/dist/core/http/http-request.js.map +1 -0
- package/dist/core/http/http-response.d.ts +26 -0
- package/dist/core/http/http-response.d.ts.map +1 -0
- package/dist/core/http/http-response.js +23 -0
- package/dist/core/http/http-response.js.map +1 -0
- package/dist/core/http/query.d.ts +14 -0
- package/dist/core/http/query.d.ts.map +1 -0
- package/dist/core/http/query.js +23 -0
- package/dist/core/http/query.js.map +1 -0
- package/dist/core/http/transport.d.ts +44 -0
- package/dist/core/http/transport.d.ts.map +1 -0
- package/dist/core/http/transport.js +2 -0
- package/dist/core/http/transport.js.map +1 -0
- package/dist/core/idempotency/idempotency.d.ts +16 -0
- package/dist/core/idempotency/idempotency.d.ts.map +1 -0
- package/dist/core/idempotency/idempotency.js +27 -0
- package/dist/core/idempotency/idempotency.js.map +1 -0
- package/dist/core/retry/backoff.d.ts +18 -0
- package/dist/core/retry/backoff.d.ts.map +1 -0
- package/dist/core/retry/backoff.js +46 -0
- package/dist/core/retry/backoff.js.map +1 -0
- package/dist/core/retry/retry-policy.d.ts +43 -0
- package/dist/core/retry/retry-policy.d.ts.map +1 -0
- package/dist/core/retry/retry-policy.js +90 -0
- package/dist/core/retry/retry-policy.js.map +1 -0
- package/dist/core/types/common.d.ts +59 -0
- package/dist/core/types/common.d.ts.map +1 -0
- package/dist/core/types/common.js +2 -0
- package/dist/core/types/common.js.map +1 -0
- package/dist/core/types/configuration.d.ts +82 -0
- package/dist/core/types/configuration.d.ts.map +1 -0
- package/dist/core/types/configuration.js +2 -0
- package/dist/core/types/configuration.js.map +1 -0
- package/dist/core/types/json.d.ts +15 -0
- package/dist/core/types/json.d.ts.map +1 -0
- package/dist/core/types/json.js +2 -0
- package/dist/core/types/json.js.map +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/aggregated-merchants/aggregated-merchant-types.d.ts +82 -0
- package/dist/resources/aggregated-merchants/aggregated-merchant-types.d.ts.map +1 -0
- package/dist/resources/aggregated-merchants/aggregated-merchant-types.js +2 -0
- package/dist/resources/aggregated-merchants/aggregated-merchant-types.js.map +1 -0
- package/dist/resources/aggregated-merchants/aggregated-merchants.d.ts +67 -0
- package/dist/resources/aggregated-merchants/aggregated-merchants.d.ts.map +1 -0
- package/dist/resources/aggregated-merchants/aggregated-merchants.js +111 -0
- package/dist/resources/aggregated-merchants/aggregated-merchants.js.map +1 -0
- package/dist/resources/balance/balance-types.d.ts +18 -0
- package/dist/resources/balance/balance-types.d.ts.map +1 -0
- package/dist/resources/balance/balance-types.js +2 -0
- package/dist/resources/balance/balance-types.js.map +1 -0
- package/dist/resources/balance/balance.d.ts +20 -0
- package/dist/resources/balance/balance.d.ts.map +1 -0
- package/dist/resources/balance/balance.js +28 -0
- package/dist/resources/balance/balance.js.map +1 -0
- package/dist/resources/checkout/checkout-types.d.ts +96 -0
- package/dist/resources/checkout/checkout-types.d.ts.map +1 -0
- package/dist/resources/checkout/checkout-types.js +2 -0
- package/dist/resources/checkout/checkout-types.js.map +1 -0
- package/dist/resources/checkout/checkout.d.ts +66 -0
- package/dist/resources/checkout/checkout.d.ts.map +1 -0
- package/dist/resources/checkout/checkout.js +95 -0
- package/dist/resources/checkout/checkout.js.map +1 -0
- package/dist/resources/payout-batches/payout-batches.d.ts +31 -0
- package/dist/resources/payout-batches/payout-batches.d.ts.map +1 -0
- package/dist/resources/payout-batches/payout-batches.js +36 -0
- package/dist/resources/payout-batches/payout-batches.js.map +1 -0
- package/dist/resources/payouts/payout-types.d.ts +158 -0
- package/dist/resources/payouts/payout-types.d.ts.map +1 -0
- package/dist/resources/payouts/payout-types.js +2 -0
- package/dist/resources/payouts/payout-types.js.map +1 -0
- package/dist/resources/payouts/payouts.d.ts +63 -0
- package/dist/resources/payouts/payouts.d.ts.map +1 -0
- package/dist/resources/payouts/payouts.js +80 -0
- package/dist/resources/payouts/payouts.js.map +1 -0
- package/dist/resources/reconciliation/reconciliation-types.d.ts +86 -0
- package/dist/resources/reconciliation/reconciliation-types.d.ts.map +1 -0
- package/dist/resources/reconciliation/reconciliation-types.js +2 -0
- package/dist/resources/reconciliation/reconciliation-types.js.map +1 -0
- package/dist/resources/reconciliation/reconciliation.d.ts +41 -0
- package/dist/resources/reconciliation/reconciliation.d.ts.map +1 -0
- package/dist/resources/reconciliation/reconciliation.js +81 -0
- package/dist/resources/reconciliation/reconciliation.js.map +1 -0
- package/dist/resources/webhooks/webhook-types.d.ts +159 -0
- package/dist/resources/webhooks/webhook-types.d.ts.map +1 -0
- package/dist/resources/webhooks/webhook-types.js +36 -0
- package/dist/resources/webhooks/webhook-types.js.map +1 -0
- package/dist/resources/webhooks/webhook-verifier.d.ts +104 -0
- package/dist/resources/webhooks/webhook-verifier.d.ts.map +1 -0
- package/dist/resources/webhooks/webhook-verifier.js +188 -0
- package/dist/resources/webhooks/webhook-verifier.js.map +1 -0
- package/package.json +70 -4
- package/src/client/wave-client-options.ts +91 -0
- package/src/client/wave-client.ts +70 -0
- package/src/core/auth/authentication.ts +9 -0
- package/src/core/auth/request-signer.ts +42 -0
- package/src/core/errors/error-parser.ts +258 -0
- package/src/core/errors/redact.ts +20 -0
- package/src/core/errors/wave-api-error.ts +148 -0
- package/src/core/errors/wave-error.ts +32 -0
- package/src/core/errors/wave-network-error.ts +24 -0
- package/src/core/errors/wave-webhook-verification-error.ts +28 -0
- package/src/core/http/fetch-transport.ts +48 -0
- package/src/core/http/http-client.ts +352 -0
- package/src/core/http/http-request.ts +37 -0
- package/src/core/http/http-response.ts +37 -0
- package/src/core/http/query.ts +31 -0
- package/src/core/http/transport.ts +45 -0
- package/src/core/idempotency/idempotency.ts +31 -0
- package/src/core/retry/backoff.ts +61 -0
- package/src/core/retry/retry-policy.ts +106 -0
- package/src/core/types/common.ts +65 -0
- package/src/core/types/configuration.ts +85 -0
- package/src/core/types/json.ts +16 -0
- package/src/index.ts +146 -0
- package/src/resources/aggregated-merchants/aggregated-merchant-types.ts +87 -0
- package/src/resources/aggregated-merchants/aggregated-merchants.ts +171 -0
- package/src/resources/balance/balance-types.ts +19 -0
- package/src/resources/balance/balance.ts +39 -0
- package/src/resources/checkout/checkout-types.ts +102 -0
- package/src/resources/checkout/checkout.ts +144 -0
- package/src/resources/payout-batches/payout-batches.ts +58 -0
- package/src/resources/payouts/payout-types.ts +171 -0
- package/src/resources/payouts/payouts.ts +120 -0
- package/src/resources/reconciliation/reconciliation-types.ts +102 -0
- package/src/resources/reconciliation/reconciliation.ts +116 -0
- package/src/resources/webhooks/webhook-types.ts +222 -0
- package/src/resources/webhooks/webhook-verifier.ts +297 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { Amount, CurrencyCode, PageInfo, Timestamp } from '../../core/types/common.js';
|
|
2
|
+
import type { JsonObject } from '../../core/types/json.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Documented transaction types.
|
|
6
|
+
*/
|
|
7
|
+
export type TransactionType =
|
|
8
|
+
| 'merchant_payment'
|
|
9
|
+
| 'merchant_payment_refund'
|
|
10
|
+
| 'api_checkout'
|
|
11
|
+
| 'api_checkout_refund'
|
|
12
|
+
| 'api_payout'
|
|
13
|
+
| 'api_payout_reversal'
|
|
14
|
+
| 'bulk_payment'
|
|
15
|
+
| 'bulk_payment_reversal'
|
|
16
|
+
| 'b2b_payment'
|
|
17
|
+
| 'b2b_payment_reversal'
|
|
18
|
+
| 'merchant_sweep'
|
|
19
|
+
| 'remittance'
|
|
20
|
+
| 'remittance_reversal';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A wallet transaction returned by `GET /v1/transactions`.
|
|
24
|
+
*/
|
|
25
|
+
export interface Transaction {
|
|
26
|
+
/** Execution time of the transaction. */
|
|
27
|
+
readonly timestamp: Timestamp;
|
|
28
|
+
/** Unique transaction identifier, up to 20 characters. */
|
|
29
|
+
readonly transaction_id: string;
|
|
30
|
+
/** Transaction type; may be empty. */
|
|
31
|
+
readonly transaction_type?: TransactionType | '';
|
|
32
|
+
/** Amount difference applied to the wallet. */
|
|
33
|
+
readonly amount: Amount;
|
|
34
|
+
/** Fee charged for the transaction. */
|
|
35
|
+
readonly fee: Amount;
|
|
36
|
+
/** Wallet balance after the transaction, when provided. */
|
|
37
|
+
readonly balance?: Amount;
|
|
38
|
+
/** Currency of the transaction amount. */
|
|
39
|
+
readonly currency: CurrencyCode;
|
|
40
|
+
/** Whether this is a reversal or refund of a previous transaction. */
|
|
41
|
+
readonly is_reversal?: boolean;
|
|
42
|
+
/** Name of the counterparty, when provided. */
|
|
43
|
+
readonly counterparty_name?: string;
|
|
44
|
+
/** Mobile number of the counterparty, when provided. */
|
|
45
|
+
readonly counterparty_mobile?: string;
|
|
46
|
+
/** Counterparty identifier for B2B payments, when provided. */
|
|
47
|
+
readonly counterparty_id?: string;
|
|
48
|
+
/** Business user involved in the transaction, when provided. */
|
|
49
|
+
readonly business_user_name?: string;
|
|
50
|
+
/** Mobile number of the business user, when provided. */
|
|
51
|
+
readonly business_user_mobile?: string;
|
|
52
|
+
/** Employee identifier of the business user, when provided. */
|
|
53
|
+
readonly employee_id?: string;
|
|
54
|
+
/** Caller correlation string, when provided. */
|
|
55
|
+
readonly client_reference?: string;
|
|
56
|
+
/** Payment reason, when provided. */
|
|
57
|
+
readonly payment_reason?: string;
|
|
58
|
+
/** Linked Checkout API session identifier, when applicable. */
|
|
59
|
+
readonly checkout_api_session_id?: string;
|
|
60
|
+
/** Bulk payment batch identifier, when applicable. */
|
|
61
|
+
readonly batch_id?: string;
|
|
62
|
+
/** Aggregated merchant identifier, when applicable. */
|
|
63
|
+
readonly aggregated_merchant_id?: string;
|
|
64
|
+
/** Aggregated merchant name, when applicable. */
|
|
65
|
+
readonly aggregated_merchant_name?: string;
|
|
66
|
+
/** Custom key-value fields related to the payment, when provided. */
|
|
67
|
+
readonly custom_fields?: JsonObject;
|
|
68
|
+
/** Subaccount identifier that owns the transaction, when applicable. */
|
|
69
|
+
readonly submerchant_id?: string;
|
|
70
|
+
/** Subaccount name that owns the transaction, when applicable. */
|
|
71
|
+
readonly submerchant_name?: string;
|
|
72
|
+
/** Government tax applied to the transaction (Senegal only). */
|
|
73
|
+
readonly government_tax_amount?: string;
|
|
74
|
+
/** Government tax covered by Wave (Senegal only). */
|
|
75
|
+
readonly government_tax_paid_by_wave?: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Response body of `GET /v1/transactions`.
|
|
80
|
+
*/
|
|
81
|
+
export interface TransactionPage {
|
|
82
|
+
/** Cursor pagination state. */
|
|
83
|
+
readonly page_info: PageInfo;
|
|
84
|
+
/** Day the transactions belong to, in `YYYY-MM-DD` form. */
|
|
85
|
+
readonly date: string;
|
|
86
|
+
/** Transactions for the day, oldest first. */
|
|
87
|
+
readonly items: readonly Transaction[];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Query parameters for `GET /v1/transactions`.
|
|
92
|
+
*/
|
|
93
|
+
export interface ListTransactionsQuery {
|
|
94
|
+
/** Day to fetch, in `YYYY-MM-DD` form; defaults to the current day. */
|
|
95
|
+
readonly date?: string;
|
|
96
|
+
/** Opaque cursor, normally the previous page's `page_info.end_cursor`. */
|
|
97
|
+
readonly after?: string;
|
|
98
|
+
/** Include transactions from readable subaccounts. */
|
|
99
|
+
readonly include_subaccounts?: boolean;
|
|
100
|
+
/** Maximum number of items to retrieve, when the server honours it. */
|
|
101
|
+
readonly first?: number;
|
|
102
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { HttpClient } from '../../core/http/http-client.js';
|
|
2
|
+
import type { QueryParameterValue } from '../../core/http/query.js';
|
|
3
|
+
import type { RequestOptions } from '../../core/types/configuration.js';
|
|
4
|
+
import type {
|
|
5
|
+
ListTransactionsQuery,
|
|
6
|
+
Transaction,
|
|
7
|
+
TransactionPage,
|
|
8
|
+
} from './reconciliation-types.js';
|
|
9
|
+
|
|
10
|
+
const LIST_TRANSACTIONS = { idempotent: true, requiresIdempotencyKey: false } as const;
|
|
11
|
+
const REFUND_TRANSACTION = { idempotent: true, requiresIdempotencyKey: true } as const;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Balance & Reconciliation API operations.
|
|
15
|
+
*/
|
|
16
|
+
export class ReconciliationResource {
|
|
17
|
+
readonly #http: HttpClient;
|
|
18
|
+
|
|
19
|
+
/** @param http - Shared HTTP pipeline. */
|
|
20
|
+
constructor(http: HttpClient) {
|
|
21
|
+
this.#http = http;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves one day of wallet transactions, oldest first.
|
|
26
|
+
*
|
|
27
|
+
* Responses paginate when a day has more than 1000 entries; pass
|
|
28
|
+
* `page_info.end_cursor` as `after` to continue. Use {@link iterateTransactions} to walk all
|
|
29
|
+
* pages.
|
|
30
|
+
*
|
|
31
|
+
* @param query - Day, cursor and subaccount options.
|
|
32
|
+
* @param options - Per-request overrides.
|
|
33
|
+
* @returns One page of transactions.
|
|
34
|
+
*/
|
|
35
|
+
listTransactions(
|
|
36
|
+
query: ListTransactionsQuery = {},
|
|
37
|
+
options: RequestOptions = {},
|
|
38
|
+
): Promise<TransactionPage> {
|
|
39
|
+
return this.#http.request<TransactionPage>(
|
|
40
|
+
LIST_TRANSACTIONS,
|
|
41
|
+
{ method: 'GET', path: '/v1/transactions', query: toQuery(query) },
|
|
42
|
+
options,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Iterates every transaction for the requested day, following pagination cursors.
|
|
48
|
+
*
|
|
49
|
+
* @param query - Day and subaccount options; `after` is managed automatically.
|
|
50
|
+
* @param options - Per-request overrides applied to every page request.
|
|
51
|
+
* @yields Each transaction in order.
|
|
52
|
+
*/
|
|
53
|
+
async *iterateTransactions(
|
|
54
|
+
query: ListTransactionsQuery = {},
|
|
55
|
+
options: RequestOptions = {},
|
|
56
|
+
): AsyncGenerator<Transaction, void, undefined> {
|
|
57
|
+
let after = query.after;
|
|
58
|
+
|
|
59
|
+
for (;;) {
|
|
60
|
+
const page = await this.listTransactions(
|
|
61
|
+
{ ...query, ...(after === undefined ? {} : { after }) },
|
|
62
|
+
options,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
for (const transaction of page.items) {
|
|
66
|
+
yield transaction;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!page.page_info.has_next_page) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const nextCursor = page.page_info.end_cursor;
|
|
74
|
+
if (nextCursor === null || nextCursor === after) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
after = nextCursor;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Refunds a payment received, including fees.
|
|
83
|
+
*
|
|
84
|
+
* Wave documents the endpoint as idempotent and returns an empty body on success.
|
|
85
|
+
*
|
|
86
|
+
* @param transactionId - Transaction identifier to refund.
|
|
87
|
+
* @param options - Per-request overrides.
|
|
88
|
+
*/
|
|
89
|
+
refund(transactionId: string, options: RequestOptions = {}): Promise<void> {
|
|
90
|
+
return this.#http.requestVoid(
|
|
91
|
+
REFUND_TRANSACTION,
|
|
92
|
+
{
|
|
93
|
+
method: 'POST',
|
|
94
|
+
path: `/v1/transactions/${encodeURIComponent(transactionId)}/refund`,
|
|
95
|
+
},
|
|
96
|
+
options,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function toQuery(query: ListTransactionsQuery): Readonly<Record<string, QueryParameterValue>> {
|
|
102
|
+
const result: Record<string, QueryParameterValue> = {};
|
|
103
|
+
if (query.date !== undefined) {
|
|
104
|
+
result['date'] = query.date;
|
|
105
|
+
}
|
|
106
|
+
if (query.after !== undefined) {
|
|
107
|
+
result['after'] = query.after;
|
|
108
|
+
}
|
|
109
|
+
if (query.include_subaccounts !== undefined) {
|
|
110
|
+
result['include_subaccounts'] = query.include_subaccounts;
|
|
111
|
+
}
|
|
112
|
+
if (query.first !== undefined) {
|
|
113
|
+
result['first'] = query.first;
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import type { Amount, CurrencyCode, PhoneNumber, Timestamp } from '../../core/types/common.js';
|
|
2
|
+
import type { JsonObject } from '../../core/types/json.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The event envelope Wave sends to a webhook endpoint.
|
|
6
|
+
*
|
|
7
|
+
* @typeParam TData - Event-specific data payload.
|
|
8
|
+
* @typeParam TType - Event type string.
|
|
9
|
+
*/
|
|
10
|
+
export interface WebhookEvent<TData = unknown, TType extends string = string> {
|
|
11
|
+
/** Unique event identifier; use it to detect duplicate deliveries. */
|
|
12
|
+
readonly id: string;
|
|
13
|
+
/** Event type, for example `checkout.session.completed`. */
|
|
14
|
+
readonly type: TType;
|
|
15
|
+
/** Event-specific data containing the changed state. */
|
|
16
|
+
readonly data: TData;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Event types documented by Wave.
|
|
21
|
+
*/
|
|
22
|
+
export type KnownWebhookEventType =
|
|
23
|
+
| 'checkout.session.completed'
|
|
24
|
+
| 'checkout.session.payment_failed'
|
|
25
|
+
| 'b2b.payment_received'
|
|
26
|
+
| 'b2b.payment_failed'
|
|
27
|
+
| 'merchant.payment_received'
|
|
28
|
+
| 'remittance.delivered'
|
|
29
|
+
| 'remittance.reversed'
|
|
30
|
+
| 'test.test_event';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Data payload of `checkout.session.completed`.
|
|
34
|
+
*/
|
|
35
|
+
export interface CheckoutSessionCompletedEventData {
|
|
36
|
+
/** Checkout session identifier. */
|
|
37
|
+
readonly id: string;
|
|
38
|
+
/** Amount collected. */
|
|
39
|
+
readonly amount: Amount;
|
|
40
|
+
/** Currency of the amount. */
|
|
41
|
+
readonly currency: CurrencyCode;
|
|
42
|
+
/** Payment state. */
|
|
43
|
+
readonly payment_status: 'succeeded';
|
|
44
|
+
/** Checkout state. */
|
|
45
|
+
readonly checkout_status: 'complete';
|
|
46
|
+
/** Caller correlation string, when provided. */
|
|
47
|
+
readonly client_reference?: string | null;
|
|
48
|
+
/** Wave transaction identifier. */
|
|
49
|
+
readonly transaction_id: string;
|
|
50
|
+
/** When the payment completed. */
|
|
51
|
+
readonly when_completed: Timestamp;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Data payload of `checkout.session.payment_failed`.
|
|
56
|
+
*
|
|
57
|
+
* Wave's example returns `payment_status: "failed"` and `checkout_status: "failed"`, which are not
|
|
58
|
+
* part of the documented Checkout Session enums; those literal values are preserved here.
|
|
59
|
+
*/
|
|
60
|
+
export interface CheckoutSessionPaymentFailedEventData {
|
|
61
|
+
/** Checkout session identifier. */
|
|
62
|
+
readonly id: string;
|
|
63
|
+
/** Payment state as delivered by the event. */
|
|
64
|
+
readonly payment_status: 'failed';
|
|
65
|
+
/** Checkout state as delivered by the event. */
|
|
66
|
+
readonly checkout_status: 'failed';
|
|
67
|
+
/** Reason for the failed attempt. */
|
|
68
|
+
readonly last_payment_error: {
|
|
69
|
+
/** Short machine-readable error code. */
|
|
70
|
+
readonly code: string;
|
|
71
|
+
/** Human-readable description. */
|
|
72
|
+
readonly message: string;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Data payload of `b2b.payment_received`.
|
|
78
|
+
*/
|
|
79
|
+
export interface B2BPaymentReceivedEventData {
|
|
80
|
+
/** B2B payment identifier. */
|
|
81
|
+
readonly id: string;
|
|
82
|
+
/** Amount received. */
|
|
83
|
+
readonly amount: Amount;
|
|
84
|
+
/** Currency of the amount. */
|
|
85
|
+
readonly currency: CurrencyCode;
|
|
86
|
+
/** Identifier of the sending business. */
|
|
87
|
+
readonly sender_id: string;
|
|
88
|
+
/** Caller correlation string, when provided. */
|
|
89
|
+
readonly client_reference?: string | null;
|
|
90
|
+
/** When the payment was created. */
|
|
91
|
+
readonly when_created: Timestamp;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Data payload of `merchant.payment_received`.
|
|
96
|
+
*/
|
|
97
|
+
export interface MerchantPaymentReceivedEventData {
|
|
98
|
+
/** Transaction identifier. */
|
|
99
|
+
readonly id: string;
|
|
100
|
+
/** Amount received. */
|
|
101
|
+
readonly amount: Amount;
|
|
102
|
+
/** Fee charged for the payment. */
|
|
103
|
+
readonly fee: Amount;
|
|
104
|
+
/** Currency of the amount. */
|
|
105
|
+
readonly currency: CurrencyCode;
|
|
106
|
+
/** Mobile number of the payer. */
|
|
107
|
+
readonly sender_mobile: PhoneNumber;
|
|
108
|
+
/** Name of the receiving business. */
|
|
109
|
+
readonly merchant_name: string;
|
|
110
|
+
/** Custom key-value fields, when provided. */
|
|
111
|
+
readonly custom_fields?: JsonObject;
|
|
112
|
+
/** When the payment was created. */
|
|
113
|
+
readonly when_created: Timestamp;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Event payload for `checkout.session.completed`.
|
|
118
|
+
*/
|
|
119
|
+
export type CheckoutSessionCompletedEvent = WebhookEvent<
|
|
120
|
+
CheckoutSessionCompletedEventData,
|
|
121
|
+
'checkout.session.completed'
|
|
122
|
+
>;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Event payload for `checkout.session.payment_failed`.
|
|
126
|
+
*/
|
|
127
|
+
export type CheckoutSessionPaymentFailedEvent = WebhookEvent<
|
|
128
|
+
CheckoutSessionPaymentFailedEventData,
|
|
129
|
+
'checkout.session.payment_failed'
|
|
130
|
+
>;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Event payload for `b2b.payment_received`.
|
|
134
|
+
*/
|
|
135
|
+
export type B2BPaymentReceivedEvent = WebhookEvent<
|
|
136
|
+
B2BPaymentReceivedEventData,
|
|
137
|
+
'b2b.payment_received'
|
|
138
|
+
>;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Event payload for `b2b.payment_failed`.
|
|
142
|
+
*
|
|
143
|
+
* Wave does not document the data schema for this event.
|
|
144
|
+
*/
|
|
145
|
+
export type B2BPaymentFailedEvent = WebhookEvent<unknown, 'b2b.payment_failed'>;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Event payload for `merchant.payment_received`.
|
|
149
|
+
*/
|
|
150
|
+
export type MerchantPaymentReceivedEvent = WebhookEvent<
|
|
151
|
+
MerchantPaymentReceivedEventData,
|
|
152
|
+
'merchant.payment_received'
|
|
153
|
+
>;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Event payload for `remittance.delivered`.
|
|
157
|
+
*
|
|
158
|
+
* Wave does not document the data schema for this event.
|
|
159
|
+
*/
|
|
160
|
+
export type RemittanceDeliveredEvent = WebhookEvent<unknown, 'remittance.delivered'>;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Event payload for `remittance.reversed`.
|
|
164
|
+
*
|
|
165
|
+
* Wave does not document the data schema for this event.
|
|
166
|
+
*/
|
|
167
|
+
export type RemittanceReversedEvent = WebhookEvent<unknown, 'remittance.reversed'>;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Event payload for the portal-triggered test event.
|
|
171
|
+
*/
|
|
172
|
+
export type TestWebhookEvent = WebhookEvent<unknown, 'test.test_event'>;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Any documented Wave webhook event.
|
|
176
|
+
*/
|
|
177
|
+
export type KnownWebhookEvent =
|
|
178
|
+
| CheckoutSessionCompletedEvent
|
|
179
|
+
| CheckoutSessionPaymentFailedEvent
|
|
180
|
+
| B2BPaymentReceivedEvent
|
|
181
|
+
| B2BPaymentFailedEvent
|
|
182
|
+
| MerchantPaymentReceivedEvent
|
|
183
|
+
| RemittanceDeliveredEvent
|
|
184
|
+
| RemittanceReversedEvent
|
|
185
|
+
| TestWebhookEvent;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Narrows an arbitrary type string to a documented event type.
|
|
189
|
+
*
|
|
190
|
+
* @param type - Event type string from a webhook payload.
|
|
191
|
+
*/
|
|
192
|
+
export function isKnownWebhookEventType(type: string): type is KnownWebhookEventType {
|
|
193
|
+
switch (type) {
|
|
194
|
+
case 'checkout.session.completed':
|
|
195
|
+
case 'checkout.session.payment_failed':
|
|
196
|
+
case 'b2b.payment_received':
|
|
197
|
+
case 'b2b.payment_failed':
|
|
198
|
+
case 'merchant.payment_received':
|
|
199
|
+
case 'remittance.delivered':
|
|
200
|
+
case 'remittance.reversed':
|
|
201
|
+
case 'test.test_event':
|
|
202
|
+
return true;
|
|
203
|
+
default:
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Narrows a parsed event to the documented discriminated union.
|
|
210
|
+
*
|
|
211
|
+
* Event payloads are not validated at runtime because Wave does not publish JSON schemas for them;
|
|
212
|
+
* the returned object keeps the parsed `data` value.
|
|
213
|
+
*
|
|
214
|
+
* @param event - Event returned by `constructEvent` or `constructWaveWebhookEvent`.
|
|
215
|
+
* @returns The typed event, or `undefined` for an undocumented event type.
|
|
216
|
+
*/
|
|
217
|
+
export function toKnownWebhookEvent(event: WebhookEvent): KnownWebhookEvent | undefined {
|
|
218
|
+
if (!isKnownWebhookEventType(event.type)) {
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
return { id: event.id, type: event.type, data: event.data } as KnownWebhookEvent;
|
|
222
|
+
}
|