@paymos/sdk 1.0.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.
@@ -0,0 +1,267 @@
1
+ interface RetryOptions {
2
+ maxRetries?: number;
3
+ baseDelayMs?: number;
4
+ }
5
+ interface ClientOptions {
6
+ apiKey: string;
7
+ apiSecret: string;
8
+ baseUrl?: string;
9
+ timeoutMs?: number;
10
+ retry?: RetryOptions | false;
11
+ fetch?: typeof globalThis.fetch;
12
+ clock?: () => number;
13
+ }
14
+ declare class HttpClient {
15
+ private readonly options;
16
+ constructor(options: ClientOptions);
17
+ request<T>(method: string, path: string, payload?: unknown, query?: string): Promise<T>;
18
+ }
19
+
20
+ type InvoiceStatus = "awaiting_client" | "awaiting_payment" | "confirming" | "underpaid_waiting" | "paid" | "paid_over" | "underpaid" | "expired" | "cancelled";
21
+ type WithdrawalStatus = "created" | "pending_review" | "signed" | "cancelling" | "completed" | "failed" | "cancelled";
22
+ interface CreateInvoiceParams {
23
+ project_id: string;
24
+ amount: string;
25
+ currency: string;
26
+ external_order_id: string;
27
+ network?: string | null;
28
+ allow_multiple_payments?: boolean;
29
+ customer_fee_percent?: number | null;
30
+ client_id?: string | null;
31
+ }
32
+ interface ConfirmPaymentParams {
33
+ currency: string;
34
+ network: string;
35
+ }
36
+ interface Order {
37
+ external_id: string;
38
+ client_id: string | null;
39
+ amount: string;
40
+ currency: string;
41
+ network: string | null;
42
+ }
43
+ interface Transfer {
44
+ tx_hash: string;
45
+ amount: string;
46
+ status: string;
47
+ created_at: string;
48
+ confirmed_at: string | null;
49
+ required_confirmations: number | null;
50
+ estimated_confirmation_at: string | null;
51
+ explorer_url: string | null;
52
+ }
53
+ interface Payment {
54
+ currency: string;
55
+ network: string;
56
+ chain_id: number;
57
+ contract_address: string | null;
58
+ expected: string;
59
+ address: string | null;
60
+ exchange_rate: string | null;
61
+ paid: string | null;
62
+ remaining: string | null;
63
+ fee: string | null;
64
+ net: string | null;
65
+ transfers: Transfer[] | null;
66
+ }
67
+ interface Invoice {
68
+ invoice_id: string;
69
+ project_id: string;
70
+ status: InvoiceStatus;
71
+ is_final: boolean;
72
+ is_test: boolean;
73
+ payment_url: string;
74
+ order: Order;
75
+ payment: Payment | null;
76
+ created_at: string;
77
+ updated_at: string;
78
+ expires_at: string | null;
79
+ completed_at: string | null;
80
+ }
81
+ interface InvoiceListItem {
82
+ invoice_id: string;
83
+ project_id: string;
84
+ external_order_id: string;
85
+ client_id: string | null;
86
+ status: InvoiceStatus;
87
+ is_final: boolean;
88
+ is_test: boolean;
89
+ amount: string;
90
+ currency: string;
91
+ network: string | null;
92
+ created_at: string;
93
+ expires_at: string | null;
94
+ completed_at: string | null;
95
+ }
96
+ interface ListInvoicesParams {
97
+ limit?: number;
98
+ cursor?: string;
99
+ status?: InvoiceStatus[];
100
+ external_order_id?: string;
101
+ project_id?: string;
102
+ created_from?: number;
103
+ created_to?: number;
104
+ }
105
+ interface CreateWithdrawalParams {
106
+ destination_address: string;
107
+ network: string;
108
+ currency: string;
109
+ amount: string;
110
+ external_order_id: string;
111
+ }
112
+ interface Withdrawal {
113
+ withdrawal_id: string;
114
+ external_order_id: string;
115
+ status: WithdrawalStatus;
116
+ is_final: boolean;
117
+ is_test: boolean;
118
+ amount: string;
119
+ fee: string | null;
120
+ currency: string;
121
+ network: string;
122
+ destination_address: string;
123
+ tx_hash: string | null;
124
+ explorer_url: string | null;
125
+ created_at: string;
126
+ completed_at: string | null;
127
+ failed_at: string | null;
128
+ cancelled_at: string | null;
129
+ }
130
+ type WithdrawalListItem = Omit<Withdrawal, "tx_hash" | "explorer_url">;
131
+ interface ListWithdrawalsParams {
132
+ limit?: number;
133
+ cursor?: string;
134
+ status?: WithdrawalStatus[];
135
+ external_order_id?: string;
136
+ created_from?: number;
137
+ created_to?: number;
138
+ }
139
+ interface CursorPage<T> {
140
+ items: T[];
141
+ next_cursor: string | null;
142
+ }
143
+ interface Balance {
144
+ currency: string;
145
+ available: string;
146
+ }
147
+ interface ProblemError {
148
+ code: string;
149
+ field: string | null;
150
+ message: string;
151
+ }
152
+ interface ProblemDetails {
153
+ type?: string;
154
+ title?: string;
155
+ status?: number;
156
+ detail?: string;
157
+ code?: string;
158
+ field?: string | null;
159
+ errors?: ProblemError[];
160
+ trace_id?: string;
161
+ }
162
+ interface WebhookEvent<T = unknown> {
163
+ event_id: string;
164
+ event_type: string;
165
+ created_at: string;
166
+ data: T;
167
+ }
168
+
169
+ declare class InvoicesResource {
170
+ private readonly http;
171
+ constructor(http: HttpClient);
172
+ create(params: CreateInvoiceParams): Promise<Invoice>;
173
+ get(invoiceId: string): Promise<Invoice>;
174
+ list(params?: ListInvoicesParams): Promise<CursorPage<InvoiceListItem>>;
175
+ iterate(params?: ListInvoicesParams, maxPages?: number): AsyncGenerator<InvoiceListItem>;
176
+ cancel(invoiceId: string, reason: string): Promise<Invoice>;
177
+ confirmPayment(invoiceId: string, params: ConfirmPaymentParams): Promise<Invoice>;
178
+ simulatePayment(invoiceId: string, stage: "paid" | "overpaid" | "underpay" | "cancel"): Promise<Invoice>;
179
+ }
180
+ declare class WithdrawalsResource {
181
+ private readonly http;
182
+ constructor(http: HttpClient);
183
+ create(params: CreateWithdrawalParams): Promise<Withdrawal>;
184
+ get(withdrawalId: string): Promise<Withdrawal>;
185
+ list(params?: ListWithdrawalsParams): Promise<CursorPage<WithdrawalListItem>>;
186
+ iterate(params?: ListWithdrawalsParams, maxPages?: number): AsyncGenerator<WithdrawalListItem>;
187
+ cancel(withdrawalId: string, reason: string): Promise<Withdrawal>;
188
+ simulateCompletion(withdrawalId: string): Promise<Withdrawal>;
189
+ }
190
+ declare class BalancesResource {
191
+ private readonly http;
192
+ constructor(http: HttpClient);
193
+ get(): Promise<Balance[]>;
194
+ }
195
+ declare class SystemResource {
196
+ private readonly http;
197
+ constructor(http: HttpClient);
198
+ time(): Promise<{
199
+ server_time: number;
200
+ }>;
201
+ }
202
+
203
+ declare class PaymosError extends Error {
204
+ constructor(message: string, options?: ErrorOptions);
205
+ }
206
+ declare class ConfigurationError extends PaymosError {
207
+ }
208
+ declare class SignatureMismatchError extends PaymosError {
209
+ }
210
+ declare class TimestampSkewError extends PaymosError {
211
+ }
212
+ declare class ApiError extends PaymosError {
213
+ readonly status: number;
214
+ readonly body: string;
215
+ readonly headers: Headers;
216
+ readonly problem: ProblemDetails | null;
217
+ constructor(status: number, body: string, headers: Headers);
218
+ get code(): string;
219
+ get field(): string | null;
220
+ get errors(): readonly ProblemError[];
221
+ get retryAfterSeconds(): number | null;
222
+ }
223
+ declare class ValidationError extends ApiError {
224
+ }
225
+ declare class AuthenticationError extends ApiError {
226
+ }
227
+ declare class NotFoundError extends ApiError {
228
+ }
229
+ declare class ConflictError extends ApiError {
230
+ }
231
+ declare class GoneError extends ApiError {
232
+ }
233
+ declare class RateLimitError extends ApiError {
234
+ }
235
+ declare class ServerError extends ApiError {
236
+ }
237
+ declare class UnavailableError extends ServerError {
238
+ }
239
+ declare function apiErrorFromResponse(status: number, body: string, headers: Headers): ApiError;
240
+
241
+ declare function stringToSign(timestamp: string | number, method: string, path: string, query?: string, body?: string): string;
242
+ declare function sign(secret: string, value: string): string;
243
+ declare function authorizationHeader(apiKey: string, apiSecret: string, timestamp: string | number, method: string, path: string, query?: string, body?: string): string;
244
+ declare function encodePathSegment(value: string): string;
245
+ declare function buildQuery<T extends object>(filters: T): string;
246
+
247
+ declare class WebhookVerifier {
248
+ private readonly secret;
249
+ private readonly toleranceSeconds;
250
+ constructor(secret: string, toleranceSeconds?: number);
251
+ verify(signatureHeader: string, rawBody: string | Buffer, now?: number): boolean;
252
+ assertValid(signatureHeader: string, rawBody: string | Buffer, now?: number): void;
253
+ constructEvent<T = unknown>(signatureHeader: string, rawBody: string | Buffer, now?: number): WebhookEvent<T>;
254
+ }
255
+
256
+ declare const SDK_VERSION = "1.0.0";
257
+
258
+ declare class Paymos {
259
+ readonly invoices: InvoicesResource;
260
+ readonly withdrawals: WithdrawalsResource;
261
+ readonly balances: BalancesResource;
262
+ readonly system: SystemResource;
263
+ constructor(options: ClientOptions);
264
+ }
265
+ declare function externalOrderId(prefix?: string): string;
266
+
267
+ export { ApiError, AuthenticationError, type Balance, type ClientOptions, ConfigurationError, type ConfirmPaymentParams, ConflictError, type CreateInvoiceParams, type CreateWithdrawalParams, type CursorPage, GoneError, type Invoice, type InvoiceListItem, type InvoiceStatus, type ListInvoicesParams, type ListWithdrawalsParams, NotFoundError, type Order, type Payment, Paymos, PaymosError, type ProblemDetails, type ProblemError, RateLimitError, type RetryOptions, SDK_VERSION, ServerError, SignatureMismatchError, TimestampSkewError, type Transfer, UnavailableError, ValidationError, type WebhookEvent, WebhookVerifier, type Withdrawal, type WithdrawalListItem, type WithdrawalStatus, apiErrorFromResponse, authorizationHeader, buildQuery, encodePathSegment, externalOrderId, sign, stringToSign };
@@ -0,0 +1,267 @@
1
+ interface RetryOptions {
2
+ maxRetries?: number;
3
+ baseDelayMs?: number;
4
+ }
5
+ interface ClientOptions {
6
+ apiKey: string;
7
+ apiSecret: string;
8
+ baseUrl?: string;
9
+ timeoutMs?: number;
10
+ retry?: RetryOptions | false;
11
+ fetch?: typeof globalThis.fetch;
12
+ clock?: () => number;
13
+ }
14
+ declare class HttpClient {
15
+ private readonly options;
16
+ constructor(options: ClientOptions);
17
+ request<T>(method: string, path: string, payload?: unknown, query?: string): Promise<T>;
18
+ }
19
+
20
+ type InvoiceStatus = "awaiting_client" | "awaiting_payment" | "confirming" | "underpaid_waiting" | "paid" | "paid_over" | "underpaid" | "expired" | "cancelled";
21
+ type WithdrawalStatus = "created" | "pending_review" | "signed" | "cancelling" | "completed" | "failed" | "cancelled";
22
+ interface CreateInvoiceParams {
23
+ project_id: string;
24
+ amount: string;
25
+ currency: string;
26
+ external_order_id: string;
27
+ network?: string | null;
28
+ allow_multiple_payments?: boolean;
29
+ customer_fee_percent?: number | null;
30
+ client_id?: string | null;
31
+ }
32
+ interface ConfirmPaymentParams {
33
+ currency: string;
34
+ network: string;
35
+ }
36
+ interface Order {
37
+ external_id: string;
38
+ client_id: string | null;
39
+ amount: string;
40
+ currency: string;
41
+ network: string | null;
42
+ }
43
+ interface Transfer {
44
+ tx_hash: string;
45
+ amount: string;
46
+ status: string;
47
+ created_at: string;
48
+ confirmed_at: string | null;
49
+ required_confirmations: number | null;
50
+ estimated_confirmation_at: string | null;
51
+ explorer_url: string | null;
52
+ }
53
+ interface Payment {
54
+ currency: string;
55
+ network: string;
56
+ chain_id: number;
57
+ contract_address: string | null;
58
+ expected: string;
59
+ address: string | null;
60
+ exchange_rate: string | null;
61
+ paid: string | null;
62
+ remaining: string | null;
63
+ fee: string | null;
64
+ net: string | null;
65
+ transfers: Transfer[] | null;
66
+ }
67
+ interface Invoice {
68
+ invoice_id: string;
69
+ project_id: string;
70
+ status: InvoiceStatus;
71
+ is_final: boolean;
72
+ is_test: boolean;
73
+ payment_url: string;
74
+ order: Order;
75
+ payment: Payment | null;
76
+ created_at: string;
77
+ updated_at: string;
78
+ expires_at: string | null;
79
+ completed_at: string | null;
80
+ }
81
+ interface InvoiceListItem {
82
+ invoice_id: string;
83
+ project_id: string;
84
+ external_order_id: string;
85
+ client_id: string | null;
86
+ status: InvoiceStatus;
87
+ is_final: boolean;
88
+ is_test: boolean;
89
+ amount: string;
90
+ currency: string;
91
+ network: string | null;
92
+ created_at: string;
93
+ expires_at: string | null;
94
+ completed_at: string | null;
95
+ }
96
+ interface ListInvoicesParams {
97
+ limit?: number;
98
+ cursor?: string;
99
+ status?: InvoiceStatus[];
100
+ external_order_id?: string;
101
+ project_id?: string;
102
+ created_from?: number;
103
+ created_to?: number;
104
+ }
105
+ interface CreateWithdrawalParams {
106
+ destination_address: string;
107
+ network: string;
108
+ currency: string;
109
+ amount: string;
110
+ external_order_id: string;
111
+ }
112
+ interface Withdrawal {
113
+ withdrawal_id: string;
114
+ external_order_id: string;
115
+ status: WithdrawalStatus;
116
+ is_final: boolean;
117
+ is_test: boolean;
118
+ amount: string;
119
+ fee: string | null;
120
+ currency: string;
121
+ network: string;
122
+ destination_address: string;
123
+ tx_hash: string | null;
124
+ explorer_url: string | null;
125
+ created_at: string;
126
+ completed_at: string | null;
127
+ failed_at: string | null;
128
+ cancelled_at: string | null;
129
+ }
130
+ type WithdrawalListItem = Omit<Withdrawal, "tx_hash" | "explorer_url">;
131
+ interface ListWithdrawalsParams {
132
+ limit?: number;
133
+ cursor?: string;
134
+ status?: WithdrawalStatus[];
135
+ external_order_id?: string;
136
+ created_from?: number;
137
+ created_to?: number;
138
+ }
139
+ interface CursorPage<T> {
140
+ items: T[];
141
+ next_cursor: string | null;
142
+ }
143
+ interface Balance {
144
+ currency: string;
145
+ available: string;
146
+ }
147
+ interface ProblemError {
148
+ code: string;
149
+ field: string | null;
150
+ message: string;
151
+ }
152
+ interface ProblemDetails {
153
+ type?: string;
154
+ title?: string;
155
+ status?: number;
156
+ detail?: string;
157
+ code?: string;
158
+ field?: string | null;
159
+ errors?: ProblemError[];
160
+ trace_id?: string;
161
+ }
162
+ interface WebhookEvent<T = unknown> {
163
+ event_id: string;
164
+ event_type: string;
165
+ created_at: string;
166
+ data: T;
167
+ }
168
+
169
+ declare class InvoicesResource {
170
+ private readonly http;
171
+ constructor(http: HttpClient);
172
+ create(params: CreateInvoiceParams): Promise<Invoice>;
173
+ get(invoiceId: string): Promise<Invoice>;
174
+ list(params?: ListInvoicesParams): Promise<CursorPage<InvoiceListItem>>;
175
+ iterate(params?: ListInvoicesParams, maxPages?: number): AsyncGenerator<InvoiceListItem>;
176
+ cancel(invoiceId: string, reason: string): Promise<Invoice>;
177
+ confirmPayment(invoiceId: string, params: ConfirmPaymentParams): Promise<Invoice>;
178
+ simulatePayment(invoiceId: string, stage: "paid" | "overpaid" | "underpay" | "cancel"): Promise<Invoice>;
179
+ }
180
+ declare class WithdrawalsResource {
181
+ private readonly http;
182
+ constructor(http: HttpClient);
183
+ create(params: CreateWithdrawalParams): Promise<Withdrawal>;
184
+ get(withdrawalId: string): Promise<Withdrawal>;
185
+ list(params?: ListWithdrawalsParams): Promise<CursorPage<WithdrawalListItem>>;
186
+ iterate(params?: ListWithdrawalsParams, maxPages?: number): AsyncGenerator<WithdrawalListItem>;
187
+ cancel(withdrawalId: string, reason: string): Promise<Withdrawal>;
188
+ simulateCompletion(withdrawalId: string): Promise<Withdrawal>;
189
+ }
190
+ declare class BalancesResource {
191
+ private readonly http;
192
+ constructor(http: HttpClient);
193
+ get(): Promise<Balance[]>;
194
+ }
195
+ declare class SystemResource {
196
+ private readonly http;
197
+ constructor(http: HttpClient);
198
+ time(): Promise<{
199
+ server_time: number;
200
+ }>;
201
+ }
202
+
203
+ declare class PaymosError extends Error {
204
+ constructor(message: string, options?: ErrorOptions);
205
+ }
206
+ declare class ConfigurationError extends PaymosError {
207
+ }
208
+ declare class SignatureMismatchError extends PaymosError {
209
+ }
210
+ declare class TimestampSkewError extends PaymosError {
211
+ }
212
+ declare class ApiError extends PaymosError {
213
+ readonly status: number;
214
+ readonly body: string;
215
+ readonly headers: Headers;
216
+ readonly problem: ProblemDetails | null;
217
+ constructor(status: number, body: string, headers: Headers);
218
+ get code(): string;
219
+ get field(): string | null;
220
+ get errors(): readonly ProblemError[];
221
+ get retryAfterSeconds(): number | null;
222
+ }
223
+ declare class ValidationError extends ApiError {
224
+ }
225
+ declare class AuthenticationError extends ApiError {
226
+ }
227
+ declare class NotFoundError extends ApiError {
228
+ }
229
+ declare class ConflictError extends ApiError {
230
+ }
231
+ declare class GoneError extends ApiError {
232
+ }
233
+ declare class RateLimitError extends ApiError {
234
+ }
235
+ declare class ServerError extends ApiError {
236
+ }
237
+ declare class UnavailableError extends ServerError {
238
+ }
239
+ declare function apiErrorFromResponse(status: number, body: string, headers: Headers): ApiError;
240
+
241
+ declare function stringToSign(timestamp: string | number, method: string, path: string, query?: string, body?: string): string;
242
+ declare function sign(secret: string, value: string): string;
243
+ declare function authorizationHeader(apiKey: string, apiSecret: string, timestamp: string | number, method: string, path: string, query?: string, body?: string): string;
244
+ declare function encodePathSegment(value: string): string;
245
+ declare function buildQuery<T extends object>(filters: T): string;
246
+
247
+ declare class WebhookVerifier {
248
+ private readonly secret;
249
+ private readonly toleranceSeconds;
250
+ constructor(secret: string, toleranceSeconds?: number);
251
+ verify(signatureHeader: string, rawBody: string | Buffer, now?: number): boolean;
252
+ assertValid(signatureHeader: string, rawBody: string | Buffer, now?: number): void;
253
+ constructEvent<T = unknown>(signatureHeader: string, rawBody: string | Buffer, now?: number): WebhookEvent<T>;
254
+ }
255
+
256
+ declare const SDK_VERSION = "1.0.0";
257
+
258
+ declare class Paymos {
259
+ readonly invoices: InvoicesResource;
260
+ readonly withdrawals: WithdrawalsResource;
261
+ readonly balances: BalancesResource;
262
+ readonly system: SystemResource;
263
+ constructor(options: ClientOptions);
264
+ }
265
+ declare function externalOrderId(prefix?: string): string;
266
+
267
+ export { ApiError, AuthenticationError, type Balance, type ClientOptions, ConfigurationError, type ConfirmPaymentParams, ConflictError, type CreateInvoiceParams, type CreateWithdrawalParams, type CursorPage, GoneError, type Invoice, type InvoiceListItem, type InvoiceStatus, type ListInvoicesParams, type ListWithdrawalsParams, NotFoundError, type Order, type Payment, Paymos, PaymosError, type ProblemDetails, type ProblemError, RateLimitError, type RetryOptions, SDK_VERSION, ServerError, SignatureMismatchError, TimestampSkewError, type Transfer, UnavailableError, ValidationError, type WebhookEvent, WebhookVerifier, type Withdrawal, type WithdrawalListItem, type WithdrawalStatus, apiErrorFromResponse, authorizationHeader, buildQuery, encodePathSegment, externalOrderId, sign, stringToSign };