@imerchantsolutions/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.
- package/README.md +204 -0
- package/dist/index.d.mts +749 -0
- package/dist/index.d.ts +749 -0
- package/dist/index.js +745 -0
- package/dist/index.mjs +706 -0
- package/package.json +49 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,749 @@
|
|
|
1
|
+
interface iMerchantConfig {
|
|
2
|
+
/** Your iMerchant API key (starts with sk_test_ or sk_live_) */
|
|
3
|
+
apiKey: string;
|
|
4
|
+
/** API base URL (defaults to https://api.imerchant.com) */
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
7
|
+
timeout?: number;
|
|
8
|
+
/** API version (default: 'v1') */
|
|
9
|
+
apiVersion?: string;
|
|
10
|
+
}
|
|
11
|
+
interface RequestOptions {
|
|
12
|
+
/** Override timeout for this specific request */
|
|
13
|
+
timeout?: number;
|
|
14
|
+
/** Idempotency key for safe retries */
|
|
15
|
+
idempotencyKey?: string;
|
|
16
|
+
}
|
|
17
|
+
interface Amount {
|
|
18
|
+
/** Amount in minor units (e.g., cents for USD) */
|
|
19
|
+
value: number;
|
|
20
|
+
/** Three-letter ISO currency code */
|
|
21
|
+
currency: string;
|
|
22
|
+
}
|
|
23
|
+
interface Address {
|
|
24
|
+
line1: string;
|
|
25
|
+
line2?: string;
|
|
26
|
+
city: string;
|
|
27
|
+
state?: string;
|
|
28
|
+
postalCode: string;
|
|
29
|
+
country: string;
|
|
30
|
+
}
|
|
31
|
+
interface PaginationParams {
|
|
32
|
+
/** Number of records to return (max 100) */
|
|
33
|
+
limit?: number;
|
|
34
|
+
/** Pagination cursor for next page */
|
|
35
|
+
cursor?: string;
|
|
36
|
+
}
|
|
37
|
+
interface PaginatedResponse<T> {
|
|
38
|
+
data: T[];
|
|
39
|
+
hasMore: boolean;
|
|
40
|
+
cursor?: string;
|
|
41
|
+
total?: number;
|
|
42
|
+
}
|
|
43
|
+
interface APIError$1 {
|
|
44
|
+
code: string;
|
|
45
|
+
message: string;
|
|
46
|
+
details?: Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
type PaymentStatus = 'pending' | 'processing' | 'authorized' | 'captured' | 'failed' | 'cancelled' | 'refunded' | 'partially_refunded';
|
|
49
|
+
type PaymentMethodType = 'card' | 'bank_transfer' | 'apple_pay' | 'google_pay' | 'klarna' | 'afterpay';
|
|
50
|
+
interface CardDetails {
|
|
51
|
+
/** Last 4 digits of the card */
|
|
52
|
+
last4: string;
|
|
53
|
+
/** Card brand (visa, mastercard, amex, etc.) */
|
|
54
|
+
brand: string;
|
|
55
|
+
/** Expiry month (1-12) */
|
|
56
|
+
expMonth: number;
|
|
57
|
+
/** Expiry year (4 digits) */
|
|
58
|
+
expYear: number;
|
|
59
|
+
/** Cardholder name */
|
|
60
|
+
holderName?: string;
|
|
61
|
+
}
|
|
62
|
+
interface PaymentMethod {
|
|
63
|
+
type: PaymentMethodType;
|
|
64
|
+
card?: CardDetails;
|
|
65
|
+
}
|
|
66
|
+
interface Payment {
|
|
67
|
+
/** Unique payment identifier */
|
|
68
|
+
id: string;
|
|
69
|
+
/** Payment amount */
|
|
70
|
+
amount: Amount;
|
|
71
|
+
/** Current payment status */
|
|
72
|
+
status: PaymentStatus;
|
|
73
|
+
/** Your reference for this payment */
|
|
74
|
+
reference: string;
|
|
75
|
+
/** Payment description */
|
|
76
|
+
description?: string;
|
|
77
|
+
/** Payment method used */
|
|
78
|
+
paymentMethod?: PaymentMethod;
|
|
79
|
+
/** Customer ID if associated */
|
|
80
|
+
customerId?: string;
|
|
81
|
+
/** Additional metadata */
|
|
82
|
+
metadata?: Record<string, string>;
|
|
83
|
+
/** ISO timestamp of creation */
|
|
84
|
+
createdAt: string;
|
|
85
|
+
/** ISO timestamp of last update */
|
|
86
|
+
updatedAt: string;
|
|
87
|
+
}
|
|
88
|
+
interface CreatePaymentParams {
|
|
89
|
+
/** Amount in minor units (e.g., cents) */
|
|
90
|
+
amount: number;
|
|
91
|
+
/** Three-letter ISO currency code */
|
|
92
|
+
currency: string;
|
|
93
|
+
/** Your unique reference for this payment */
|
|
94
|
+
reference: string;
|
|
95
|
+
/** Payment description */
|
|
96
|
+
description?: string;
|
|
97
|
+
/** Customer ID to associate with payment */
|
|
98
|
+
customerId?: string;
|
|
99
|
+
/** Return URL after payment completion */
|
|
100
|
+
returnUrl?: string;
|
|
101
|
+
/** Additional metadata (key-value pairs) */
|
|
102
|
+
metadata?: Record<string, string>;
|
|
103
|
+
/** Payment method details for server-side payments */
|
|
104
|
+
paymentMethod?: {
|
|
105
|
+
type: PaymentMethodType;
|
|
106
|
+
encryptedCardNumber?: string;
|
|
107
|
+
encryptedExpiryMonth?: string;
|
|
108
|
+
encryptedExpiryYear?: string;
|
|
109
|
+
encryptedSecurityCode?: string;
|
|
110
|
+
holderName?: string;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
interface ListPaymentsParams extends PaginationParams {
|
|
114
|
+
/** Filter by status */
|
|
115
|
+
status?: PaymentStatus;
|
|
116
|
+
/** Filter by customer ID */
|
|
117
|
+
customerId?: string;
|
|
118
|
+
/** Filter payments after this date (ISO string) */
|
|
119
|
+
createdAfter?: string;
|
|
120
|
+
/** Filter payments before this date (ISO string) */
|
|
121
|
+
createdBefore?: string;
|
|
122
|
+
}
|
|
123
|
+
interface CapturePaymentParams {
|
|
124
|
+
/** Amount to capture (defaults to full authorized amount) */
|
|
125
|
+
amount?: number;
|
|
126
|
+
}
|
|
127
|
+
type RefundStatus = 'pending' | 'processing' | 'completed' | 'failed';
|
|
128
|
+
interface Refund {
|
|
129
|
+
/** Unique refund identifier */
|
|
130
|
+
id: string;
|
|
131
|
+
/** Associated payment ID */
|
|
132
|
+
paymentId: string;
|
|
133
|
+
/** Refund amount */
|
|
134
|
+
amount: Amount;
|
|
135
|
+
/** Current refund status */
|
|
136
|
+
status: RefundStatus;
|
|
137
|
+
/** Reason for refund */
|
|
138
|
+
reason?: string;
|
|
139
|
+
/** Additional metadata */
|
|
140
|
+
metadata?: Record<string, string>;
|
|
141
|
+
/** ISO timestamp of creation */
|
|
142
|
+
createdAt: string;
|
|
143
|
+
}
|
|
144
|
+
interface CreateRefundParams {
|
|
145
|
+
/** Payment ID to refund */
|
|
146
|
+
paymentId: string;
|
|
147
|
+
/** Amount to refund in minor units (defaults to full payment amount) */
|
|
148
|
+
amount?: number;
|
|
149
|
+
/** Reason for the refund */
|
|
150
|
+
reason?: string;
|
|
151
|
+
/** Additional metadata */
|
|
152
|
+
metadata?: Record<string, string>;
|
|
153
|
+
}
|
|
154
|
+
interface ListRefundsParams extends PaginationParams {
|
|
155
|
+
/** Filter by payment ID */
|
|
156
|
+
paymentId?: string;
|
|
157
|
+
/** Filter by status */
|
|
158
|
+
status?: RefundStatus;
|
|
159
|
+
}
|
|
160
|
+
interface Customer {
|
|
161
|
+
/** Unique customer identifier */
|
|
162
|
+
id: string;
|
|
163
|
+
/** Customer email address */
|
|
164
|
+
email: string;
|
|
165
|
+
/** Customer's first name */
|
|
166
|
+
firstName?: string;
|
|
167
|
+
/** Customer's last name */
|
|
168
|
+
lastName?: string;
|
|
169
|
+
/** Customer's phone number */
|
|
170
|
+
phone?: string;
|
|
171
|
+
/** Billing address */
|
|
172
|
+
billingAddress?: Address;
|
|
173
|
+
/** Additional metadata */
|
|
174
|
+
metadata?: Record<string, string>;
|
|
175
|
+
/** ISO timestamp of creation */
|
|
176
|
+
createdAt: string;
|
|
177
|
+
/** ISO timestamp of last update */
|
|
178
|
+
updatedAt: string;
|
|
179
|
+
}
|
|
180
|
+
interface CreateCustomerParams {
|
|
181
|
+
/** Customer email address */
|
|
182
|
+
email: string;
|
|
183
|
+
/** Customer's first name */
|
|
184
|
+
firstName?: string;
|
|
185
|
+
/** Customer's last name */
|
|
186
|
+
lastName?: string;
|
|
187
|
+
/** Customer's phone number */
|
|
188
|
+
phone?: string;
|
|
189
|
+
/** Billing address */
|
|
190
|
+
billingAddress?: Address;
|
|
191
|
+
/** Additional metadata */
|
|
192
|
+
metadata?: Record<string, string>;
|
|
193
|
+
}
|
|
194
|
+
interface UpdateCustomerParams {
|
|
195
|
+
/** Customer email address */
|
|
196
|
+
email?: string;
|
|
197
|
+
/** Customer's first name */
|
|
198
|
+
firstName?: string;
|
|
199
|
+
/** Customer's last name */
|
|
200
|
+
lastName?: string;
|
|
201
|
+
/** Customer's phone number */
|
|
202
|
+
phone?: string;
|
|
203
|
+
/** Billing address */
|
|
204
|
+
billingAddress?: Address;
|
|
205
|
+
/** Additional metadata */
|
|
206
|
+
metadata?: Record<string, string>;
|
|
207
|
+
}
|
|
208
|
+
interface ListCustomersParams extends PaginationParams {
|
|
209
|
+
/** Filter by email */
|
|
210
|
+
email?: string;
|
|
211
|
+
/** Filter customers created after this date */
|
|
212
|
+
createdAfter?: string;
|
|
213
|
+
/** Filter customers created before this date */
|
|
214
|
+
createdBefore?: string;
|
|
215
|
+
}
|
|
216
|
+
type SubscriptionStatus = 'active' | 'paused' | 'cancelled' | 'past_due' | 'trialing';
|
|
217
|
+
type BillingInterval = 'day' | 'week' | 'month' | 'year';
|
|
218
|
+
interface Subscription {
|
|
219
|
+
/** Unique subscription identifier */
|
|
220
|
+
id: string;
|
|
221
|
+
/** Associated customer ID */
|
|
222
|
+
customerId: string;
|
|
223
|
+
/** Current subscription status */
|
|
224
|
+
status: SubscriptionStatus;
|
|
225
|
+
/** Billing amount */
|
|
226
|
+
amount: Amount;
|
|
227
|
+
/** Billing interval */
|
|
228
|
+
interval: BillingInterval;
|
|
229
|
+
/** Number of intervals between billings */
|
|
230
|
+
intervalCount: number;
|
|
231
|
+
/** Current billing period start */
|
|
232
|
+
currentPeriodStart: string;
|
|
233
|
+
/** Current billing period end */
|
|
234
|
+
currentPeriodEnd: string;
|
|
235
|
+
/** Whether subscription cancels at period end */
|
|
236
|
+
cancelAtPeriodEnd: boolean;
|
|
237
|
+
/** Additional metadata */
|
|
238
|
+
metadata?: Record<string, string>;
|
|
239
|
+
/** ISO timestamp of creation */
|
|
240
|
+
createdAt: string;
|
|
241
|
+
}
|
|
242
|
+
interface CreateSubscriptionParams {
|
|
243
|
+
/** Customer ID */
|
|
244
|
+
customerId: string;
|
|
245
|
+
/** Amount in minor units */
|
|
246
|
+
amount: number;
|
|
247
|
+
/** Currency code */
|
|
248
|
+
currency: string;
|
|
249
|
+
/** Billing interval */
|
|
250
|
+
interval: BillingInterval;
|
|
251
|
+
/** Number of intervals between billings (default: 1) */
|
|
252
|
+
intervalCount?: number;
|
|
253
|
+
/** Number of trial days (default: 0) */
|
|
254
|
+
trialDays?: number;
|
|
255
|
+
/** Additional metadata */
|
|
256
|
+
metadata?: Record<string, string>;
|
|
257
|
+
}
|
|
258
|
+
type WebhookEventType = 'payment.created' | 'payment.authorized' | 'payment.captured' | 'payment.failed' | 'payment.cancelled' | 'refund.created' | 'refund.completed' | 'refund.failed' | 'customer.created' | 'customer.updated' | 'subscription.created' | 'subscription.updated' | 'subscription.cancelled' | 'chargeback.created';
|
|
259
|
+
interface WebhookEvent<T = unknown> {
|
|
260
|
+
/** Unique event identifier */
|
|
261
|
+
id: string;
|
|
262
|
+
/** Event type */
|
|
263
|
+
type: WebhookEventType;
|
|
264
|
+
/** Event data */
|
|
265
|
+
data: T;
|
|
266
|
+
/** ISO timestamp of event creation */
|
|
267
|
+
createdAt: string;
|
|
268
|
+
}
|
|
269
|
+
interface WebhookPayload {
|
|
270
|
+
/** Raw request body as string */
|
|
271
|
+
body: string;
|
|
272
|
+
/** Signature from imerchant-signature header */
|
|
273
|
+
signature: string;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
declare class HttpClient {
|
|
277
|
+
private config;
|
|
278
|
+
constructor(config: iMerchantConfig);
|
|
279
|
+
private getUrl;
|
|
280
|
+
private handleResponse;
|
|
281
|
+
request<T>(method: string, path: string, data?: unknown, options?: RequestOptions): Promise<T>;
|
|
282
|
+
get<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
283
|
+
post<T>(path: string, data?: unknown, options?: RequestOptions): Promise<T>;
|
|
284
|
+
put<T>(path: string, data?: unknown, options?: RequestOptions): Promise<T>;
|
|
285
|
+
patch<T>(path: string, data?: unknown, options?: RequestOptions): Promise<T>;
|
|
286
|
+
delete<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Payments API - Create, retrieve, and manage payments
|
|
291
|
+
*/
|
|
292
|
+
declare class Payments {
|
|
293
|
+
private http;
|
|
294
|
+
constructor(http: HttpClient);
|
|
295
|
+
/**
|
|
296
|
+
* Create a new payment
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```typescript
|
|
300
|
+
* const payment = await client.payments.create({
|
|
301
|
+
* amount: 1000, // $10.00 in cents
|
|
302
|
+
* currency: 'usd',
|
|
303
|
+
* reference: 'order_123',
|
|
304
|
+
* description: 'Test payment',
|
|
305
|
+
* });
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
create(params: CreatePaymentParams, options?: RequestOptions): Promise<Payment>;
|
|
309
|
+
/**
|
|
310
|
+
* Retrieve a payment by ID
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* ```typescript
|
|
314
|
+
* const payment = await client.payments.retrieve('pay_abc123');
|
|
315
|
+
* console.log(payment.status);
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
retrieve(id: string, options?: RequestOptions): Promise<Payment>;
|
|
319
|
+
/**
|
|
320
|
+
* List all payments with optional filters
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* ```typescript
|
|
324
|
+
* const { data, hasMore } = await client.payments.list({
|
|
325
|
+
* status: 'captured',
|
|
326
|
+
* limit: 10,
|
|
327
|
+
* });
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
list(params?: ListPaymentsParams, options?: RequestOptions): Promise<PaginatedResponse<Payment>>;
|
|
331
|
+
/**
|
|
332
|
+
* Capture an authorized payment
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* ```typescript
|
|
336
|
+
* // Capture full amount
|
|
337
|
+
* const payment = await client.payments.capture('pay_abc123');
|
|
338
|
+
*
|
|
339
|
+
* // Capture partial amount
|
|
340
|
+
* const payment = await client.payments.capture('pay_abc123', { amount: 500 });
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
capture(id: string, params?: CapturePaymentParams, options?: RequestOptions): Promise<Payment>;
|
|
344
|
+
/**
|
|
345
|
+
* Cancel an authorized payment
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* ```typescript
|
|
349
|
+
* const payment = await client.payments.cancel('pay_abc123');
|
|
350
|
+
* ```
|
|
351
|
+
*/
|
|
352
|
+
cancel(id: string, options?: RequestOptions): Promise<Payment>;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Refunds API - Create and manage refunds
|
|
357
|
+
*/
|
|
358
|
+
declare class Refunds {
|
|
359
|
+
private http;
|
|
360
|
+
constructor(http: HttpClient);
|
|
361
|
+
/**
|
|
362
|
+
* Create a refund for a payment
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* ```typescript
|
|
366
|
+
* // Full refund
|
|
367
|
+
* const refund = await client.refunds.create({
|
|
368
|
+
* paymentId: 'pay_abc123',
|
|
369
|
+
* reason: 'Customer request',
|
|
370
|
+
* });
|
|
371
|
+
*
|
|
372
|
+
* // Partial refund
|
|
373
|
+
* const refund = await client.refunds.create({
|
|
374
|
+
* paymentId: 'pay_abc123',
|
|
375
|
+
* amount: 500, // $5.00 in cents
|
|
376
|
+
* reason: 'Partial return',
|
|
377
|
+
* });
|
|
378
|
+
* ```
|
|
379
|
+
*/
|
|
380
|
+
create(params: CreateRefundParams, options?: RequestOptions): Promise<Refund>;
|
|
381
|
+
/**
|
|
382
|
+
* Retrieve a refund by ID
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* ```typescript
|
|
386
|
+
* const refund = await client.refunds.retrieve('ref_abc123');
|
|
387
|
+
* console.log(refund.status);
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
390
|
+
retrieve(id: string, options?: RequestOptions): Promise<Refund>;
|
|
391
|
+
/**
|
|
392
|
+
* List all refunds with optional filters
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* ```typescript
|
|
396
|
+
* // List all refunds for a payment
|
|
397
|
+
* const { data } = await client.refunds.list({
|
|
398
|
+
* paymentId: 'pay_abc123',
|
|
399
|
+
* });
|
|
400
|
+
*
|
|
401
|
+
* // List refunds by status
|
|
402
|
+
* const { data } = await client.refunds.list({
|
|
403
|
+
* status: 'completed',
|
|
404
|
+
* limit: 20,
|
|
405
|
+
* });
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
list(params?: ListRefundsParams, options?: RequestOptions): Promise<PaginatedResponse<Refund>>;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Customers API - Create and manage customers
|
|
413
|
+
*/
|
|
414
|
+
declare class Customers {
|
|
415
|
+
private http;
|
|
416
|
+
constructor(http: HttpClient);
|
|
417
|
+
/**
|
|
418
|
+
* Create a new customer
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* ```typescript
|
|
422
|
+
* const customer = await client.customers.create({
|
|
423
|
+
* email: 'john@example.com',
|
|
424
|
+
* firstName: 'John',
|
|
425
|
+
* lastName: 'Doe',
|
|
426
|
+
* metadata: { userId: '12345' },
|
|
427
|
+
* });
|
|
428
|
+
* ```
|
|
429
|
+
*/
|
|
430
|
+
create(params: CreateCustomerParams, options?: RequestOptions): Promise<Customer>;
|
|
431
|
+
/**
|
|
432
|
+
* Retrieve a customer by ID
|
|
433
|
+
*
|
|
434
|
+
* @example
|
|
435
|
+
* ```typescript
|
|
436
|
+
* const customer = await client.customers.retrieve('cus_abc123');
|
|
437
|
+
* console.log(customer.email);
|
|
438
|
+
* ```
|
|
439
|
+
*/
|
|
440
|
+
retrieve(id: string, options?: RequestOptions): Promise<Customer>;
|
|
441
|
+
/**
|
|
442
|
+
* Update a customer
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
* ```typescript
|
|
446
|
+
* const customer = await client.customers.update('cus_abc123', {
|
|
447
|
+
* firstName: 'Jane',
|
|
448
|
+
* phone: '+1234567890',
|
|
449
|
+
* });
|
|
450
|
+
* ```
|
|
451
|
+
*/
|
|
452
|
+
update(id: string, params: UpdateCustomerParams, options?: RequestOptions): Promise<Customer>;
|
|
453
|
+
/**
|
|
454
|
+
* Delete a customer
|
|
455
|
+
*
|
|
456
|
+
* @example
|
|
457
|
+
* ```typescript
|
|
458
|
+
* await client.customers.delete('cus_abc123');
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
461
|
+
delete(id: string, options?: RequestOptions): Promise<void>;
|
|
462
|
+
/**
|
|
463
|
+
* List all customers with optional filters
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* ```typescript
|
|
467
|
+
* const { data, hasMore } = await client.customers.list({
|
|
468
|
+
* limit: 20,
|
|
469
|
+
* });
|
|
470
|
+
*
|
|
471
|
+
* // Search by email
|
|
472
|
+
* const { data } = await client.customers.list({
|
|
473
|
+
* email: 'john@example.com',
|
|
474
|
+
* });
|
|
475
|
+
* ```
|
|
476
|
+
*/
|
|
477
|
+
list(params?: ListCustomersParams, options?: RequestOptions): Promise<PaginatedResponse<Customer>>;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
interface ListSubscriptionsParams extends PaginationParams {
|
|
481
|
+
/** Filter by customer ID */
|
|
482
|
+
customerId?: string;
|
|
483
|
+
/** Filter by status */
|
|
484
|
+
status?: SubscriptionStatus;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Subscriptions API - Create and manage recurring billing
|
|
488
|
+
*/
|
|
489
|
+
declare class Subscriptions {
|
|
490
|
+
private http;
|
|
491
|
+
constructor(http: HttpClient);
|
|
492
|
+
/**
|
|
493
|
+
* Create a new subscription
|
|
494
|
+
*
|
|
495
|
+
* @example
|
|
496
|
+
* ```typescript
|
|
497
|
+
* const subscription = await client.subscriptions.create({
|
|
498
|
+
* customerId: 'cus_abc123',
|
|
499
|
+
* amount: 2999, // $29.99 in cents
|
|
500
|
+
* currency: 'usd',
|
|
501
|
+
* interval: 'month',
|
|
502
|
+
* });
|
|
503
|
+
* ```
|
|
504
|
+
*/
|
|
505
|
+
create(params: CreateSubscriptionParams, options?: RequestOptions): Promise<Subscription>;
|
|
506
|
+
/**
|
|
507
|
+
* Retrieve a subscription by ID
|
|
508
|
+
*
|
|
509
|
+
* @example
|
|
510
|
+
* ```typescript
|
|
511
|
+
* const subscription = await client.subscriptions.retrieve('sub_abc123');
|
|
512
|
+
* console.log(subscription.status);
|
|
513
|
+
* ```
|
|
514
|
+
*/
|
|
515
|
+
retrieve(id: string, options?: RequestOptions): Promise<Subscription>;
|
|
516
|
+
/**
|
|
517
|
+
* Cancel a subscription
|
|
518
|
+
*
|
|
519
|
+
* @example
|
|
520
|
+
* ```typescript
|
|
521
|
+
* // Cancel immediately
|
|
522
|
+
* const subscription = await client.subscriptions.cancel('sub_abc123');
|
|
523
|
+
*
|
|
524
|
+
* // Cancel at end of billing period
|
|
525
|
+
* const subscription = await client.subscriptions.cancel('sub_abc123', {
|
|
526
|
+
* atPeriodEnd: true,
|
|
527
|
+
* });
|
|
528
|
+
* ```
|
|
529
|
+
*/
|
|
530
|
+
cancel(id: string, params?: {
|
|
531
|
+
atPeriodEnd?: boolean;
|
|
532
|
+
}, options?: RequestOptions): Promise<Subscription>;
|
|
533
|
+
/**
|
|
534
|
+
* Pause a subscription
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* ```typescript
|
|
538
|
+
* const subscription = await client.subscriptions.pause('sub_abc123');
|
|
539
|
+
* ```
|
|
540
|
+
*/
|
|
541
|
+
pause(id: string, options?: RequestOptions): Promise<Subscription>;
|
|
542
|
+
/**
|
|
543
|
+
* Resume a paused subscription
|
|
544
|
+
*
|
|
545
|
+
* @example
|
|
546
|
+
* ```typescript
|
|
547
|
+
* const subscription = await client.subscriptions.resume('sub_abc123');
|
|
548
|
+
* ```
|
|
549
|
+
*/
|
|
550
|
+
resume(id: string, options?: RequestOptions): Promise<Subscription>;
|
|
551
|
+
/**
|
|
552
|
+
* List all subscriptions with optional filters
|
|
553
|
+
*
|
|
554
|
+
* @example
|
|
555
|
+
* ```typescript
|
|
556
|
+
* // List all active subscriptions
|
|
557
|
+
* const { data } = await client.subscriptions.list({
|
|
558
|
+
* status: 'active',
|
|
559
|
+
* });
|
|
560
|
+
*
|
|
561
|
+
* // List subscriptions for a customer
|
|
562
|
+
* const { data } = await client.subscriptions.list({
|
|
563
|
+
* customerId: 'cus_abc123',
|
|
564
|
+
* });
|
|
565
|
+
* ```
|
|
566
|
+
*/
|
|
567
|
+
list(params?: ListSubscriptionsParams, options?: RequestOptions): Promise<PaginatedResponse<Subscription>>;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Webhooks utility class for verifying webhook signatures
|
|
572
|
+
*/
|
|
573
|
+
declare class Webhooks {
|
|
574
|
+
/**
|
|
575
|
+
* Verify webhook signature and parse the event
|
|
576
|
+
*
|
|
577
|
+
* @example
|
|
578
|
+
* ```typescript
|
|
579
|
+
* // Express.js example
|
|
580
|
+
* app.post('/webhooks', express.raw({ type: 'application/json' }), (req, res) => {
|
|
581
|
+
* const signature = req.headers['imerchant-signature'] as string;
|
|
582
|
+
*
|
|
583
|
+
* try {
|
|
584
|
+
* const event = iMerchant.webhooks.verify({
|
|
585
|
+
* body: req.body.toString(),
|
|
586
|
+
* signature,
|
|
587
|
+
* }, process.env.WEBHOOK_SECRET);
|
|
588
|
+
*
|
|
589
|
+
* switch (event.type) {
|
|
590
|
+
* case 'payment.captured':
|
|
591
|
+
* // Handle successful payment
|
|
592
|
+
* break;
|
|
593
|
+
* case 'payment.failed':
|
|
594
|
+
* // Handle failed payment
|
|
595
|
+
* break;
|
|
596
|
+
* }
|
|
597
|
+
*
|
|
598
|
+
* res.json({ received: true });
|
|
599
|
+
* } catch (err) {
|
|
600
|
+
* res.status(400).send('Invalid signature');
|
|
601
|
+
* }
|
|
602
|
+
* });
|
|
603
|
+
* ```
|
|
604
|
+
*
|
|
605
|
+
* @param payload - The webhook payload containing body and signature
|
|
606
|
+
* @param secret - Your webhook signing secret
|
|
607
|
+
* @returns The verified and parsed webhook event
|
|
608
|
+
* @throws {WebhookSignatureError} If signature verification fails
|
|
609
|
+
*/
|
|
610
|
+
static verify<T = unknown>(payload: WebhookPayload, secret: string): WebhookEvent<T>;
|
|
611
|
+
/**
|
|
612
|
+
* Compute HMAC-SHA256 signature
|
|
613
|
+
* Uses Node.js crypto module (available in Node.js environments)
|
|
614
|
+
*/
|
|
615
|
+
private static computeSignature;
|
|
616
|
+
/**
|
|
617
|
+
* Timing-safe string comparison to prevent timing attacks
|
|
618
|
+
*/
|
|
619
|
+
private static secureCompare;
|
|
620
|
+
/**
|
|
621
|
+
* Async signature verification using Web Crypto API
|
|
622
|
+
* Use this in environments that support Web Crypto
|
|
623
|
+
*
|
|
624
|
+
* @example
|
|
625
|
+
* ```typescript
|
|
626
|
+
* const event = await iMerchant.webhooks.verifyAsync(payload, secret);
|
|
627
|
+
* ```
|
|
628
|
+
*/
|
|
629
|
+
static verifyAsync<T = unknown>(payload: WebhookPayload, secret: string): Promise<WebhookEvent<T>>;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* iMerchant SDK Client
|
|
634
|
+
*
|
|
635
|
+
* The main entry point for interacting with the iMerchant API.
|
|
636
|
+
*
|
|
637
|
+
* @example
|
|
638
|
+
* ```typescript
|
|
639
|
+
* import { iMerchant } from '@imerchant/sdk';
|
|
640
|
+
*
|
|
641
|
+
* const client = new iMerchant({
|
|
642
|
+
* apiKey: 'sk_test_your_api_key',
|
|
643
|
+
* });
|
|
644
|
+
*
|
|
645
|
+
* // Create a payment
|
|
646
|
+
* const payment = await client.payments.create({
|
|
647
|
+
* amount: 1000,
|
|
648
|
+
* currency: 'usd',
|
|
649
|
+
* reference: 'order_123',
|
|
650
|
+
* });
|
|
651
|
+
*
|
|
652
|
+
* // Create a customer
|
|
653
|
+
* const customer = await client.customers.create({
|
|
654
|
+
* email: 'john@example.com',
|
|
655
|
+
* firstName: 'John',
|
|
656
|
+
* });
|
|
657
|
+
*
|
|
658
|
+
* // Create a subscription
|
|
659
|
+
* const subscription = await client.subscriptions.create({
|
|
660
|
+
* customerId: customer.id,
|
|
661
|
+
* amount: 2999,
|
|
662
|
+
* currency: 'usd',
|
|
663
|
+
* interval: 'month',
|
|
664
|
+
* });
|
|
665
|
+
* ```
|
|
666
|
+
*/
|
|
667
|
+
declare class iMerchant {
|
|
668
|
+
/**
|
|
669
|
+
* Payments API for creating and managing payments
|
|
670
|
+
*/
|
|
671
|
+
readonly payments: Payments;
|
|
672
|
+
/**
|
|
673
|
+
* Refunds API for creating and managing refunds
|
|
674
|
+
*/
|
|
675
|
+
readonly refunds: Refunds;
|
|
676
|
+
/**
|
|
677
|
+
* Customers API for creating and managing customers
|
|
678
|
+
*/
|
|
679
|
+
readonly customers: Customers;
|
|
680
|
+
/**
|
|
681
|
+
* Subscriptions API for managing recurring billing
|
|
682
|
+
*/
|
|
683
|
+
readonly subscriptions: Subscriptions;
|
|
684
|
+
/**
|
|
685
|
+
* Static webhook utilities for signature verification
|
|
686
|
+
*/
|
|
687
|
+
static readonly webhooks: typeof Webhooks;
|
|
688
|
+
private readonly http;
|
|
689
|
+
/**
|
|
690
|
+
* Create a new iMerchant client
|
|
691
|
+
*
|
|
692
|
+
* @param config - Client configuration
|
|
693
|
+
* @param config.apiKey - Your iMerchant API key (required)
|
|
694
|
+
* @param config.baseUrl - API base URL (optional, defaults to https://api.imerchant.com)
|
|
695
|
+
* @param config.timeout - Request timeout in ms (optional, defaults to 30000)
|
|
696
|
+
* @param config.apiVersion - API version (optional, defaults to 'v1')
|
|
697
|
+
*/
|
|
698
|
+
constructor(config: iMerchantConfig);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Base error class for all iMerchant SDK errors
|
|
703
|
+
*/
|
|
704
|
+
declare class iMerchantError extends Error {
|
|
705
|
+
constructor(message: string);
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* Error thrown when API request fails
|
|
709
|
+
*/
|
|
710
|
+
declare class APIError extends iMerchantError {
|
|
711
|
+
readonly statusCode: number;
|
|
712
|
+
readonly code: string;
|
|
713
|
+
readonly details?: Record<string, unknown>;
|
|
714
|
+
constructor(message: string, statusCode: number, code: string, details?: Record<string, unknown>);
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Error thrown when authentication fails
|
|
718
|
+
*/
|
|
719
|
+
declare class AuthenticationError extends iMerchantError {
|
|
720
|
+
constructor(message?: string);
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* Error thrown when a resource is not found
|
|
724
|
+
*/
|
|
725
|
+
declare class NotFoundError extends APIError {
|
|
726
|
+
constructor(resource: string, id: string);
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Error thrown when request validation fails
|
|
730
|
+
*/
|
|
731
|
+
declare class ValidationError extends APIError {
|
|
732
|
+
readonly errors: Record<string, string[]>;
|
|
733
|
+
constructor(message: string, errors: Record<string, string[]>);
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Error thrown when rate limit is exceeded
|
|
737
|
+
*/
|
|
738
|
+
declare class RateLimitError extends APIError {
|
|
739
|
+
readonly retryAfter?: number;
|
|
740
|
+
constructor(retryAfter?: number);
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* Error thrown when webhook signature verification fails
|
|
744
|
+
*/
|
|
745
|
+
declare class WebhookSignatureError extends iMerchantError {
|
|
746
|
+
constructor(message?: string);
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
export { APIError, type APIError$1 as APIErrorType, type Address, type Amount, AuthenticationError, type BillingInterval, type CapturePaymentParams, type CardDetails, type CreateCustomerParams, type CreatePaymentParams, type CreateRefundParams, type CreateSubscriptionParams, type Customer, Customers, type ListCustomersParams, type ListPaymentsParams, type ListRefundsParams, NotFoundError, type PaginatedResponse, type PaginationParams, type Payment, type PaymentMethod, type PaymentMethodType, type PaymentStatus, Payments, RateLimitError, type Refund, type RefundStatus, Refunds, type RequestOptions, type Subscription, type SubscriptionStatus, Subscriptions, type UpdateCustomerParams, ValidationError, type WebhookEvent, type WebhookEventType, type WebhookPayload, WebhookSignatureError, Webhooks, iMerchant, type iMerchantConfig, iMerchantError };
|