@orcarail/node 1.0.1

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,521 @@
1
+ /**
2
+ * Configuration options for the OrcaRail client
3
+ */
4
+ interface OrcaRailConfig {
5
+ /**
6
+ * Base URL for the OrcaRail API
7
+ * @default "https://api.orcarail.com/api/v1"
8
+ */
9
+ baseUrl?: string;
10
+ /**
11
+ * API version
12
+ * @default "v1"
13
+ */
14
+ apiVersion?: string;
15
+ /**
16
+ * Request timeout in milliseconds
17
+ * @default 30000
18
+ */
19
+ timeout?: number;
20
+ }
21
+ /**
22
+ * Parameters for creating a Payment Intent
23
+ */
24
+ interface PaymentIntentCreateParams {
25
+ /**
26
+ * Amount to charge (e.g., "100.00")
27
+ */
28
+ amount: string;
29
+ /**
30
+ * Currency code (e.g., "usd")
31
+ */
32
+ currency: string;
33
+ /**
34
+ * Payment method types (must include "crypto")
35
+ * @default ["crypto"]
36
+ */
37
+ payment_method_types?: string[];
38
+ /**
39
+ * Token ID (e.g., USDC, USDT)
40
+ */
41
+ tokenId: number;
42
+ /**
43
+ * Network ID (e.g., Ethereum, Polygon)
44
+ */
45
+ networkId: number;
46
+ /**
47
+ * Return URL after payment completion
48
+ */
49
+ return_url: string;
50
+ /**
51
+ * Cancel URL if payment is canceled
52
+ */
53
+ cancel_url?: string | null;
54
+ /**
55
+ * Payment description
56
+ */
57
+ description?: string;
58
+ /**
59
+ * Custom metadata object
60
+ */
61
+ metadata?: Record<string, unknown> | null;
62
+ /**
63
+ * ISO 8601 expiration timestamp
64
+ */
65
+ expires_at?: string | null;
66
+ }
67
+ /**
68
+ * Parameters for updating a Payment Intent
69
+ */
70
+ interface PaymentIntentUpdateParams {
71
+ /**
72
+ * Updated amount
73
+ */
74
+ amount?: string;
75
+ /**
76
+ * Updated currency
77
+ */
78
+ currency?: string;
79
+ /**
80
+ * Updated payment method types
81
+ */
82
+ payment_method_types?: string[];
83
+ /**
84
+ * Updated token ID
85
+ */
86
+ tokenId?: number;
87
+ /**
88
+ * Updated network ID
89
+ */
90
+ networkId?: number;
91
+ /**
92
+ * Updated return URL
93
+ */
94
+ return_url?: string;
95
+ /**
96
+ * Updated cancel URL
97
+ */
98
+ cancel_url?: string | null;
99
+ /**
100
+ * Updated description
101
+ */
102
+ description?: string;
103
+ /**
104
+ * Updated metadata
105
+ */
106
+ metadata?: Record<string, unknown> | null;
107
+ /**
108
+ * Updated expiration timestamp
109
+ */
110
+ expires_at?: string | null;
111
+ }
112
+ /**
113
+ * Parameters for confirming a Payment Intent
114
+ */
115
+ interface PaymentIntentConfirmParams {
116
+ /**
117
+ * Client secret for the payment intent (from create/retrieve response)
118
+ */
119
+ client_secret: string;
120
+ /**
121
+ * Return URL after payment completion
122
+ */
123
+ return_url: string;
124
+ }
125
+ /**
126
+ * Payment Link object
127
+ */
128
+ interface PaymentLink {
129
+ /**
130
+ * Payment link ID
131
+ */
132
+ id: number;
133
+ /**
134
+ * Unique slug
135
+ */
136
+ unique_slug?: string;
137
+ /**
138
+ * Payment link URL
139
+ */
140
+ link: string;
141
+ }
142
+ /**
143
+ * Latest transaction details
144
+ */
145
+ interface LatestTransaction {
146
+ /**
147
+ * Transaction ID
148
+ */
149
+ id: string;
150
+ /**
151
+ * Transaction status
152
+ */
153
+ status: string;
154
+ /**
155
+ * Transaction hash
156
+ */
157
+ hash?: string;
158
+ /**
159
+ * Transaction amount
160
+ */
161
+ amount?: string;
162
+ /**
163
+ * Transaction address
164
+ */
165
+ address?: string;
166
+ }
167
+ /**
168
+ * Payment Intent object
169
+ */
170
+ interface PaymentIntent {
171
+ /**
172
+ * Payment Intent ID (e.g., "pi_1234567890")
173
+ */
174
+ id: string;
175
+ /**
176
+ * Object type (always "payment_intent")
177
+ */
178
+ object: string;
179
+ /**
180
+ * Amount to charge
181
+ */
182
+ amount: string;
183
+ /**
184
+ * Currency code
185
+ */
186
+ currency: string;
187
+ /**
188
+ * Current status
189
+ */
190
+ status: string;
191
+ /**
192
+ * Payment method types
193
+ */
194
+ payment_method_types: string[];
195
+ /**
196
+ * Client secret used to confirm the payment intent from the frontend
197
+ */
198
+ client_secret?: string;
199
+ /**
200
+ * Checkout URL (clean URL without secrets)
201
+ */
202
+ checkout_url?: string;
203
+ /**
204
+ * Return URL
205
+ */
206
+ return_url: string;
207
+ /**
208
+ * Cancel URL
209
+ */
210
+ cancel_url?: string | null;
211
+ /**
212
+ * Payment description
213
+ */
214
+ description?: string | null;
215
+ /**
216
+ * Custom metadata
217
+ */
218
+ metadata?: Record<string, unknown> | null;
219
+ /**
220
+ * Payment link object
221
+ */
222
+ payment_link?: PaymentLink;
223
+ /**
224
+ * Expiration timestamp
225
+ */
226
+ expiresAt?: string;
227
+ /**
228
+ * Latest transaction details (for complete intents)
229
+ */
230
+ latestTransaction?: LatestTransaction;
231
+ /**
232
+ * Creation timestamp
233
+ */
234
+ createdAt: string;
235
+ /**
236
+ * Last update timestamp
237
+ */
238
+ updatedAt: string;
239
+ }
240
+ /**
241
+ * Webhook event types
242
+ */
243
+ type WebhookEventType = 'payment_intent.complete' | 'payment_intent.processing' | 'payment_intent.canceled' | 'payment_intent.requires_payment_method' | 'payment_intent.requires_confirmation';
244
+ /**
245
+ * Webhook event data object
246
+ */
247
+ interface WebhookEventData {
248
+ /**
249
+ * Payment Intent object
250
+ */
251
+ object: PaymentIntent;
252
+ }
253
+ /**
254
+ * Webhook event structure
255
+ */
256
+ interface WebhookEvent {
257
+ /**
258
+ * Event type
259
+ */
260
+ type: WebhookEventType;
261
+ /**
262
+ * Event data
263
+ */
264
+ data: WebhookEventData;
265
+ /**
266
+ * Unix timestamp when the event was created
267
+ */
268
+ created: number;
269
+ }
270
+
271
+ /**
272
+ * HTTP client for making requests to the OrcaRail API
273
+ */
274
+ declare class HttpClient {
275
+ private readonly apiKey;
276
+ private readonly apiSecret;
277
+ private readonly baseUrl;
278
+ private readonly timeout;
279
+ constructor(apiKey: string, apiSecret: string, config?: OrcaRailConfig);
280
+ /**
281
+ * Create Basic Auth header from API key and secret
282
+ */
283
+ private getAuthHeader;
284
+ /**
285
+ * Build full URL from path
286
+ */
287
+ private buildUrl;
288
+ /**
289
+ * Make an HTTP request with timeout and error handling
290
+ */
291
+ private request;
292
+ /**
293
+ * GET request
294
+ */
295
+ get<T>(path: string, requireAuth?: boolean): Promise<T>;
296
+ /**
297
+ * POST request
298
+ */
299
+ post<T>(path: string, body?: unknown, requireAuth?: boolean): Promise<T>;
300
+ /**
301
+ * PATCH request
302
+ */
303
+ patch<T>(path: string, body?: unknown, requireAuth?: boolean): Promise<T>;
304
+ /**
305
+ * PUT request
306
+ */
307
+ put<T>(path: string, body?: unknown, requireAuth?: boolean): Promise<T>;
308
+ /**
309
+ * DELETE request
310
+ */
311
+ delete<T>(path: string, requireAuth?: boolean): Promise<T>;
312
+ }
313
+
314
+ /**
315
+ * Checkout resource for slug-based checkout flows (public endpoints)
316
+ */
317
+ declare class Checkout {
318
+ private readonly client;
319
+ constructor(client: HttpClient);
320
+ /**
321
+ * Get checkout details by slug
322
+ *
323
+ * @param slug - Checkout slug from the payment link URL
324
+ * @returns Checkout details including payment intent
325
+ */
326
+ get(slug: string): Promise<PaymentIntent & Record<string, unknown>>;
327
+ /**
328
+ * Cancel payment intent by checkout slug
329
+ *
330
+ * @param slug - Checkout slug from the payment link URL
331
+ * @returns The canceled payment intent and optional cancel_url for redirect
332
+ */
333
+ cancel(slug: string): Promise<PaymentIntent & {
334
+ cancel_url?: string;
335
+ }>;
336
+ }
337
+
338
+ /**
339
+ * Payment Intents resource for managing payment intents
340
+ */
341
+ declare class PaymentIntents {
342
+ private readonly client;
343
+ constructor(client: HttpClient);
344
+ /**
345
+ * Create a new Payment Intent
346
+ *
347
+ * @param params - Payment Intent creation parameters
348
+ * @returns The created Payment Intent
349
+ */
350
+ create(params: PaymentIntentCreateParams): Promise<PaymentIntent>;
351
+ /**
352
+ * Retrieve a Payment Intent by ID
353
+ *
354
+ * @param id - Payment Intent ID (e.g., "pi_1234567890")
355
+ * @returns The Payment Intent
356
+ */
357
+ retrieve(id: string): Promise<PaymentIntent>;
358
+ /**
359
+ * Cancel a Payment Intent (API: POST /payment_intents/:id/cancel).
360
+ * Use when the user is redirected to your cancel_url (e.g. https://yourapp.com/cancel?payment_intent=pi_20)
361
+ * and you want to mark the intent as canceled on the backend.
362
+ *
363
+ * @param id - Payment Intent ID (e.g. "pi_20" or "20")
364
+ * @returns The canceled Payment Intent
365
+ *
366
+ * @example
367
+ * // When user lands on https://localhost:3001/cancel?payment_intent=pi_20
368
+ * const intent = await orcarail.paymentIntents.cancel('pi_20');
369
+ */
370
+ cancel(id: string): Promise<PaymentIntent>;
371
+ /**
372
+ * Confirm a Payment Intent (API: POST /payment_intents/:id/confirm).
373
+ * Redirects the customer to the hosted checkout page.
374
+ *
375
+ * @param id - Payment Intent ID (e.g. "pi_20" or "20")
376
+ * @param params - Confirmation parameters including client_secret and return_url
377
+ * @returns The confirmed Payment Intent
378
+ *
379
+ * @example
380
+ * const intent = await orcarail.paymentIntents.confirm('pi_20', {
381
+ * client_secret: intent.client_secret,
382
+ * return_url: 'https://yourapp.com/return',
383
+ * });
384
+ */
385
+ confirm(id: string, params: PaymentIntentConfirmParams): Promise<PaymentIntent>;
386
+ /**
387
+ * Complete a Payment Intent (API: POST /payment_intents/:id/complete).
388
+ * Sets the intent to processing and fires the payment_intent.processing webhook.
389
+ * Use when the user is redirected to your success/return URL (e.g. https://yourapp.com/success?payment_intent=pi_34).
390
+ *
391
+ * @param id - Payment Intent ID (e.g. "pi_34" or "34")
392
+ * @returns The updated Payment Intent (status processing)
393
+ *
394
+ * @example
395
+ * // When user lands on https://localhost:3001/success?payment_intent=pi_34
396
+ * const intent = await orcarail.paymentIntents.complete('pi_34');
397
+ */
398
+ complete(id: string): Promise<PaymentIntent>;
399
+ /**
400
+ * Update a Payment Intent
401
+ *
402
+ * @param id - Payment Intent ID
403
+ * @param params - Update parameters (all optional)
404
+ * @returns The updated Payment Intent
405
+ */
406
+ update(id: string, params: PaymentIntentUpdateParams): Promise<PaymentIntent>;
407
+ }
408
+
409
+ /**
410
+ * Webhook utilities for verifying webhook signatures
411
+ */
412
+ declare class Webhooks {
413
+ /**
414
+ * Verify webhook signature
415
+ *
416
+ * @param rawBody - Raw request body (string or Buffer)
417
+ * @param signature - Signature from x-webhook-signature header
418
+ * @param secret - Webhook secret (API key's secretHash)
419
+ * @returns True if signature is valid, false otherwise
420
+ */
421
+ verifySignature(rawBody: string | Buffer, signature: string, secret: string): boolean;
422
+ /**
423
+ * Construct and verify a webhook event from raw body and signature
424
+ *
425
+ * @param rawBody - Raw request body (string or Buffer)
426
+ * @param signature - Signature from x-webhook-signature header
427
+ * @param secret - Webhook secret (API key's secretHash)
428
+ * @returns Parsed webhook event
429
+ * @throws OrcaRailSignatureVerificationError if signature is invalid
430
+ */
431
+ constructEvent(rawBody: string | Buffer, signature: string, secret: string): WebhookEvent;
432
+ }
433
+
434
+ /**
435
+ * Base error class for all OrcaRail errors
436
+ */
437
+ declare class OrcaRailError extends Error {
438
+ constructor(message: string);
439
+ }
440
+ /**
441
+ * Error thrown when the API returns a non-2xx status code
442
+ */
443
+ declare class OrcaRailAPIError extends OrcaRailError {
444
+ /**
445
+ * HTTP status code
446
+ */
447
+ readonly statusCode: number;
448
+ /**
449
+ * Error type from the API response
450
+ */
451
+ readonly type?: string;
452
+ /**
453
+ * Additional error details from the API
454
+ */
455
+ readonly details?: unknown;
456
+ constructor(message: string, statusCode: number, type?: string, details?: unknown);
457
+ }
458
+ /**
459
+ * Error thrown when authentication fails (401)
460
+ */
461
+ declare class OrcaRailAuthenticationError extends OrcaRailAPIError {
462
+ constructor(message?: string);
463
+ }
464
+ /**
465
+ * Error thrown when webhook signature verification fails
466
+ */
467
+ declare class OrcaRailSignatureVerificationError extends OrcaRailError {
468
+ /**
469
+ * The signature that was provided
470
+ */
471
+ readonly signature: string;
472
+ constructor(message?: string, signature?: string);
473
+ }
474
+
475
+ /**
476
+ * OrcaRail Node.js SDK
477
+ *
478
+ * @example
479
+ * ```typescript
480
+ * import OrcaRail from '@orcarail/node';
481
+ *
482
+ * const orcarail = new OrcaRail('ak_live_xxx', 'sk_live_xxx');
483
+ *
484
+ * // Create a payment intent
485
+ * const intent = await orcarail.paymentIntents.create({
486
+ * amount: '100.00',
487
+ * currency: 'usd',
488
+ * payment_method_types: ['crypto'],
489
+ * tokenId: 1,
490
+ * networkId: 1,
491
+ * return_url: 'https://merchant.example.com/return',
492
+ * });
493
+ * ```
494
+ */
495
+ declare class OrcaRail {
496
+ /**
497
+ * Payment Intents resource
498
+ */
499
+ readonly paymentIntents: PaymentIntents;
500
+ /**
501
+ * Checkout resource (slug-based get/cancel)
502
+ */
503
+ readonly checkout: Checkout;
504
+ /**
505
+ * Webhooks utilities
506
+ */
507
+ readonly webhooks: Webhooks;
508
+ private readonly client;
509
+ /**
510
+ * Create a new OrcaRail client instance
511
+ *
512
+ * @param apiKey - Your OrcaRail API key (e.g., "ak_live_xxx")
513
+ * @param apiSecret - Your OrcaRail API secret (e.g., "sk_live_xxx")
514
+ * @param config - Optional configuration
515
+ */
516
+ constructor(apiKey: string, apiSecret: string, config?: OrcaRailConfig);
517
+ }
518
+
519
+ // @ts-ignore
520
+ export = OrcaRail;
521
+ export { type LatestTransaction, OrcaRail, OrcaRailAPIError, OrcaRailAuthenticationError, type OrcaRailConfig, OrcaRailError, OrcaRailSignatureVerificationError, type PaymentIntent, type PaymentIntentConfirmParams, type PaymentIntentCreateParams, type PaymentIntentUpdateParams, type PaymentLink, type WebhookEvent, type WebhookEventData, type WebhookEventType };