recurrente-js 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,1277 @@
1
+ /**
2
+ * Represents the details required to create a product.
3
+ */
4
+ export interface CreateProductRequest {
5
+ /**
6
+ * The name of the product.
7
+ * @required
8
+ */
9
+ name: string;
10
+ /**
11
+ * Optional description of the product.
12
+ * @optional
13
+ */
14
+ description?: string;
15
+ /**
16
+ * Optional URL for the product image.
17
+ * @optional
18
+ */
19
+ imageUrl?: string;
20
+ /**
21
+ * An array of price attributes for the product, including currency, charge type, and amount.
22
+ * @required
23
+ */
24
+ pricesAttributes: {
25
+ /**
26
+ * The currency for the price (GTQ or USD).
27
+ * @required
28
+ */
29
+ currency: 'GTQ' | 'USD';
30
+ /**
31
+ * The charge type for the product, e.g., 'one_time'.
32
+ * @required
33
+ */
34
+ chargeType: 'one_time';
35
+ /**
36
+ * The amount to charge in cents.
37
+ * @required
38
+ */
39
+ amountInCents: number;
40
+ }[];
41
+ /**
42
+ * Optional URL to redirect the user after canceling the transaction.
43
+ * @optional
44
+ */
45
+ cancelUrl?: string;
46
+ /**
47
+ * Optional URL to redirect the user after a successful transaction.
48
+ * @optional
49
+ */
50
+ successUrl?: string;
51
+ /**
52
+ * Optional custom terms and conditions for the product.
53
+ * @optional
54
+ */
55
+ customTermsAndConditions?: string;
56
+ /**
57
+ * Defines whether a phone number is required ('required', 'optional', or 'none').
58
+ * @required
59
+ */
60
+ phoneRequirement: 'required' | 'optional' | 'none';
61
+ /**
62
+ * Defines whether an address is required ('required', 'optional', or 'none').
63
+ * @required
64
+ */
65
+ addressRequirement: 'required' | 'optional' | 'none';
66
+ /**
67
+ * Defines whether billing information is required ('optional' or 'none').
68
+ * @required
69
+ */
70
+ billingInfoRequirement: 'optional' | 'none';
71
+ /**
72
+ * Whether the quantity of the product is adjustable by the customer.
73
+ * @optional
74
+ */
75
+ adjustableQuantity?: boolean;
76
+ /**
77
+ * Optional metadata for additional information about the product.
78
+ * @optional
79
+ */
80
+ metadata?: Record<string, string>;
81
+ }
82
+ /**
83
+ * Represents the response after creating a product.
84
+ */
85
+ export interface CreateProductResponse {
86
+ /**
87
+ * The unique identifier for the product.
88
+ * @required
89
+ */
90
+ id: string;
91
+ /**
92
+ * The status of the product, either 'active' or 'inactive'.
93
+ * @required
94
+ */
95
+ status: 'active' | 'inactive';
96
+ /**
97
+ * The name of the product.
98
+ * @required
99
+ */
100
+ name: string;
101
+ /**
102
+ * Optional description of the product.
103
+ * @optional
104
+ */
105
+ description?: string;
106
+ /**
107
+ * URL to redirect the user after a successful transaction.
108
+ * @required
109
+ */
110
+ successUrl: string;
111
+ /**
112
+ * URL to redirect the user after canceling the transaction.
113
+ * @required
114
+ */
115
+ cancelUrl: string;
116
+ /**
117
+ * Optional custom terms and conditions for the product.
118
+ * @optional
119
+ */
120
+ customTermsAndConditions?: string;
121
+ /**
122
+ * Defines whether a phone number is required ('required', 'optional', or 'none').
123
+ * @required
124
+ */
125
+ phoneRequirement: 'required' | 'optional' | 'none';
126
+ /**
127
+ * Defines whether an address is required ('required', 'optional', or 'none').
128
+ * @required
129
+ */
130
+ addressRequirement: 'required' | 'optional' | 'none';
131
+ /**
132
+ * Defines whether billing information is required ('optional' or 'none').
133
+ * @required
134
+ */
135
+ billingInfoRequirement: 'optional' | 'none';
136
+ /**
137
+ * An array of price attributes for the product, including currency, charge type, and amount.
138
+ * @required
139
+ */
140
+ prices: {
141
+ /**
142
+ * The unique identifier for the price object.
143
+ * @required
144
+ */
145
+ id: string;
146
+ /**
147
+ * The amount to charge in cents.
148
+ * @required
149
+ */
150
+ amountInCents: number;
151
+ /**
152
+ * The currency for the price (GTQ or USD).
153
+ * @required
154
+ */
155
+ currency: 'GTQ' | 'USD';
156
+ /**
157
+ * The charge type for the product, e.g., 'one_time'.
158
+ * @required
159
+ */
160
+ chargeType: 'one_time';
161
+ }[];
162
+ /**
163
+ * A storefront link for the product.
164
+ * @required
165
+ */
166
+ storefrontLink: string;
167
+ /**
168
+ * Optional metadata for additional information about the product.
169
+ * @optional
170
+ */
171
+ metadata?: Record<string, string>;
172
+ }
173
+ /**
174
+ * Represents the response from the API when fetching a product by its ID.
175
+ */
176
+ export interface GetProductResponse {
177
+ /**
178
+ * The unique identifier for the product.
179
+ */
180
+ id: string;
181
+ /**
182
+ * The status of the product (e.g., active, inactive).
183
+ */
184
+ status: 'active' | 'inactive';
185
+ /**
186
+ * The name of the product.
187
+ */
188
+ name: string;
189
+ /**
190
+ * Optional description of the product.
191
+ */
192
+ description?: string;
193
+ /**
194
+ * URL to redirect the user after a successful checkout.
195
+ */
196
+ successUrl: string;
197
+ /**
198
+ * URL to redirect the user after canceling.
199
+ */
200
+ cancelUrl: string;
201
+ /**
202
+ * Optional custom terms and conditions for the product.
203
+ */
204
+ customTermsAndConditions?: string;
205
+ /**
206
+ * Defines whether a phone number is required ('required', 'optional', or 'none').
207
+ */
208
+ phoneRequirement: 'required' | 'optional' | 'none';
209
+ /**
210
+ * Defines whether an address is required ('required', 'optional', or 'none').
211
+ */
212
+ addressRequirement: 'required' | 'optional' | 'none';
213
+ /**
214
+ * Defines whether billing information is required ('optional' or 'none').
215
+ */
216
+ billingInfoRequirement: 'optional' | 'none';
217
+ /**
218
+ * The price details associated with the product.
219
+ */
220
+ prices: {
221
+ /**
222
+ * The unique identifier for the price object.
223
+ */
224
+ id: string;
225
+ /**
226
+ * The amount to charge in cents.
227
+ */
228
+ amountInCents: number;
229
+ /**
230
+ * The currency for the price (GTQ or USD).
231
+ */
232
+ currency: 'GTQ' | 'USD';
233
+ /**
234
+ * The count of the billing interval (e.g., every 1 month).
235
+ */
236
+ billingIntervalCount: number;
237
+ /**
238
+ * The billing interval period (e.g., month, week, year).
239
+ */
240
+ billingInterval: 'month' | 'week' | 'year' | '';
241
+ /**
242
+ * The charge type (e.g., one_time or recurring).
243
+ */
244
+ chargeType: 'one_time' | 'recurring';
245
+ /**
246
+ * Optional number of periods before automatic cancellation.
247
+ */
248
+ periodsBeforeAutomaticCancellation?: number | null;
249
+ /**
250
+ * Optional free trial interval count.
251
+ */
252
+ freeTrialIntervalCount?: number | null;
253
+ /**
254
+ * Optional free trial interval period.
255
+ */
256
+ freeTrialInterval?: 'month' | 'week' | 'year' | null;
257
+ }[];
258
+ /**
259
+ * The storefront link for the product.
260
+ */
261
+ storefrontLink: string;
262
+ /**
263
+ * Optional metadata for additional information about the product.
264
+ */
265
+ metadata?: Record<string, string>;
266
+ }
267
+ /**
268
+ * Represents the response from the API when fetching all products.
269
+ * It is an array of product objects.
270
+ */
271
+ export type GetAllProductsResponse = GetProductResponse[];
272
+ /**
273
+ * Represents the details required to update a product.
274
+ * Includes optional parameters for updating product attributes and deleting prices.
275
+ */
276
+ export interface UpdateProductRequest {
277
+ /**
278
+ * The name of the product.
279
+ * @optional
280
+ */
281
+ name?: string;
282
+ /**
283
+ * Optional description of the product.
284
+ * @optional
285
+ */
286
+ description?: string;
287
+ /**
288
+ * URL to redirect the user after a successful transaction.
289
+ * @optional
290
+ */
291
+ successUrl?: string;
292
+ /**
293
+ * URL to redirect the user after canceling.
294
+ * @optional
295
+ */
296
+ cancelUrl?: string;
297
+ /**
298
+ * Optional custom terms and conditions for the product.
299
+ * @optional
300
+ */
301
+ customTermsAndConditions?: string;
302
+ /**
303
+ * Defines whether a phone number is required ('required', 'optional', or 'none').
304
+ * @optional
305
+ */
306
+ phoneRequirement?: 'required' | 'optional' | 'none';
307
+ /**
308
+ * Defines whether an address is required ('required', 'optional', or 'none').
309
+ * @optional
310
+ */
311
+ addressRequirement?: 'required' | 'optional' | 'none';
312
+ /**
313
+ * Defines whether billing information is required ('optional' or 'none').
314
+ * @optional
315
+ */
316
+ billingInfoRequirement?: 'optional' | 'none';
317
+ /**
318
+ * Optional array of price attributes, including details for updating or deleting prices.
319
+ * @optional
320
+ */
321
+ pricesAttributes?: {
322
+ /**
323
+ * The unique identifier for the price object.
324
+ */
325
+ id: string;
326
+ /**
327
+ * The amount to charge in cents.
328
+ * @optional
329
+ */
330
+ amountInCents?: number;
331
+ /**
332
+ * The currency for the price (GTQ or USD).
333
+ * @optional
334
+ */
335
+ currency?: 'GTQ' | 'USD';
336
+ /**
337
+ * The billing interval count (e.g., every 1 month).
338
+ * @optional
339
+ */
340
+ billingIntervalCount?: number;
341
+ /**
342
+ * The billing interval period (e.g., month, week, year).
343
+ * @optional
344
+ */
345
+ billingInterval?: 'month' | 'week' | 'year' | '';
346
+ /**
347
+ * The charge type (e.g., one_time or recurring).
348
+ * @optional
349
+ */
350
+ chargeType?: 'one_time' | 'recurring';
351
+ /**
352
+ * Indicates if the price should be deleted.
353
+ * @optional
354
+ */
355
+ _destroy?: boolean;
356
+ }[];
357
+ /**
358
+ * Optional metadata for additional information about the product.
359
+ * @optional
360
+ */
361
+ metadata?: Record<string, string>;
362
+ }
363
+ /**
364
+ * Represents the details of a product subscription.
365
+ */
366
+ export interface ProductSubscription {
367
+ product: {
368
+ /**
369
+ * The name of the product.
370
+ * @required
371
+ */
372
+ name: string;
373
+ /**
374
+ * Optional description of the product.
375
+ * Provides a brief overview or additional details about the product.
376
+ */
377
+ description?: string;
378
+ /**
379
+ * Optional URL for the product image.
380
+ * Can be used to display an image associated with the product.
381
+ */
382
+ imageUrl?: string;
383
+ /**
384
+ * The pricing details of the product.
385
+ * @required
386
+ */
387
+ pricesAttributes: {
388
+ /**
389
+ * The currency for the product, e.g., GTQ (Guatemalan Quetzal) or USD (United States Dollar).
390
+ * @required
391
+ */
392
+ currency: 'GTQ' | 'USD';
393
+ /**
394
+ * The charge type for the subscription.
395
+ * Currently, only 'recurring' is supported, indicating that charges will happen periodically.
396
+ * @required
397
+ */
398
+ chargeType: 'recurring';
399
+ /**
400
+ * The amount to charge in cents.
401
+ * Represents the price of the product in the smallest currency unit (e.g., 100 cents = $1.00).
402
+ * @required
403
+ */
404
+ amountInCents: number;
405
+ /**
406
+ * The interval count for billing.
407
+ * Specifies the number of billing intervals between charges (e.g., every 1 month, every 3 weeks).
408
+ * @required
409
+ */
410
+ billingIntervalCount: number;
411
+ /**
412
+ * The interval period for billing.
413
+ * Specifies the time unit for billing intervals (e.g., month, week, year).
414
+ * @required
415
+ */
416
+ billingInterval: 'month' | 'week' | 'year';
417
+ /**
418
+ * Optional free trial period count.
419
+ * Specifies the number of free intervals before billing starts (e.g., 1 free month).
420
+ */
421
+ freeTrialIntervalCount?: number;
422
+ /**
423
+ * Optional free trial interval period.
424
+ * Specifies the time unit for the free trial period (e.g., month, week, year).
425
+ */
426
+ freeTrialInterval?: 'month' | 'week' | 'year';
427
+ /**
428
+ * Optional number of periods before automatic cancellation.
429
+ * Specifies the number of billing periods after which the subscription will be automatically canceled.
430
+ */
431
+ periodsBeforeAutomaticCancellation?: number;
432
+ /**
433
+ * Optional number of periods before the customer is allowed to cancel.
434
+ * Specifies how many billing periods must pass before the customer is eligible to cancel the subscription.
435
+ */
436
+ periodsBeforeAllowedToCancel?: number;
437
+ }[];
438
+ /**
439
+ * Optional URL to redirect the user after canceling.
440
+ * If specified, the user will be redirected to this URL upon successful cancellation.
441
+ */
442
+ cancelUrl?: string;
443
+ /**
444
+ * Optional URL to redirect the user after a successful purchase or subscription.
445
+ * If specified, the user will be redirected to this URL after a successful transaction.
446
+ */
447
+ successUrl?: string;
448
+ /**
449
+ * Optional custom terms and conditions for the product.
450
+ * Allows the specification of custom terms that the customer must agree to.
451
+ */
452
+ customTermsAndConditions?: string;
453
+ /**
454
+ * Defines whether a phone number is required.
455
+ * Options:
456
+ * - 'required': A phone number must be provided.
457
+ * - 'optional': A phone number is optional.
458
+ * - 'none': A phone number is not required.
459
+ */
460
+ phoneRequirement?: 'required' | 'optional' | 'none';
461
+ /**
462
+ * Defines whether an address is required.
463
+ * Options:
464
+ * - 'required': An address must be provided.
465
+ * - 'optional': An address is optional.
466
+ * - 'none': An address is not required.
467
+ */
468
+ addressRequirement?: 'required' | 'optional' | 'none';
469
+ /**
470
+ * Defines whether billing information is required.
471
+ * Options:
472
+ * - 'optional': Billing information is optional.
473
+ * - 'none': Billing information is not required.
474
+ */
475
+ billingInfoRequirement?: 'optional' | 'none';
476
+ /**
477
+ * Whether adjustable quantity is allowed.
478
+ * If true, customers can adjust the quantity of the product they are subscribing to. Default is true.
479
+ */
480
+ adjustableQuantity?: boolean;
481
+ };
482
+ /**
483
+ * Optional metadata for additional product information.
484
+ * A key-value map to store extra information about the product (e.g., tags, custom properties).
485
+ */
486
+ metadata?: Record<string, string>;
487
+ }
488
+ /**
489
+ * Represents the pricing details for a subscription.
490
+ */
491
+ export interface SubscriptionPrice {
492
+ /**
493
+ * Unique identifier for the subscription price.
494
+ */
495
+ id: string;
496
+ /**
497
+ * The amount to charge in cents.
498
+ * Represents the price of the product in the smallest currency unit (e.g., 100 cents = $1.00).
499
+ */
500
+ amountInCents: number;
501
+ /**
502
+ * The currency for the product, e.g., GTQ (Guatemalan Quetzal) or USD (United States Dollar).
503
+ */
504
+ currency: 'GTQ' | 'USD';
505
+ /**
506
+ * The billing interval count.
507
+ * Specifies the number of billing intervals between charges (e.g., every 1 month, every 3 weeks).
508
+ */
509
+ billingIntervalCount: number;
510
+ /**
511
+ * The billing interval period.
512
+ * Specifies the time unit for billing intervals (e.g., month, week, year).
513
+ */
514
+ billingInterval: 'month' | 'week' | 'year';
515
+ /**
516
+ * The charge type for the subscription.
517
+ * Currently, only 'recurring' is supported, indicating that charges will happen periodically.
518
+ */
519
+ chargeType: 'recurring';
520
+ /**
521
+ * Optional number of periods before automatic cancellation.
522
+ * Specifies the number of billing periods after which the subscription will be automatically canceled.
523
+ * If null, automatic cancellation is not applicable.
524
+ */
525
+ periodsBeforeAutomaticCancellation?: number | null;
526
+ /**
527
+ * Optional free trial interval count.
528
+ * Specifies the number of free intervals before billing starts (e.g., 1 free month).
529
+ * If null, there is no free trial period.
530
+ */
531
+ freeTrialIntervalCount?: number | null;
532
+ /**
533
+ * Optional free trial interval period.
534
+ * Specifies the time unit for the free trial period (e.g., month, week, year).
535
+ * If null, there is no free trial period.
536
+ */
537
+ freeTrialInterval?: 'month' | 'week' | 'year' | null;
538
+ }
539
+ /**
540
+ * Represents the response from creating a subscription.
541
+ */
542
+ export interface CreateSubscriptionResponse {
543
+ /**
544
+ * Unique identifier for the created subscription.
545
+ */
546
+ id: string;
547
+ /**
548
+ * The status of the subscription.
549
+ * Possible values:
550
+ * - 'active': The subscription is currently active.
551
+ * - 'inactive': The subscription is inactive.
552
+ * - 'pending': The subscription is pending and may need further actions (e.g., verification).
553
+ */
554
+ status: 'active' | 'inactive' | 'pending';
555
+ /**
556
+ * The name of the subscription.
557
+ */
558
+ name: string;
559
+ /**
560
+ * Optional description of the subscription.
561
+ * Provides additional details about the subscription.
562
+ */
563
+ description?: string;
564
+ /**
565
+ * The URL to redirect the user to after a successful subscription creation or payment.
566
+ */
567
+ successUrl: string;
568
+ /**
569
+ * The URL to redirect the user to if they cancel the subscription process.
570
+ */
571
+ cancelUrl: string;
572
+ /**
573
+ * Optional custom terms and conditions for the subscription.
574
+ * Specifies any custom terms that the user must agree to when subscribing.
575
+ */
576
+ customTermsAndConditions?: string;
577
+ /**
578
+ * Defines whether a phone number is required.
579
+ * Options:
580
+ * - 'required': A phone number must be provided.
581
+ * - 'optional': A phone number is optional.
582
+ * - 'none': No phone number is required.
583
+ */
584
+ phoneRequirement: 'required' | 'optional' | 'none';
585
+ /**
586
+ * Defines whether an address is required.
587
+ * Options:
588
+ * - 'required': An address must be provided.
589
+ * - 'optional': An address is optional.
590
+ * - 'none': No address is required.
591
+ */
592
+ addressRequirement: 'required' | 'optional' | 'none';
593
+ /**
594
+ * Defines whether billing information is required.
595
+ * Options:
596
+ * - 'optional': Billing information is optional.
597
+ * - 'none': Billing information is not required.
598
+ */
599
+ billingInfoRequirement: 'optional' | 'none';
600
+ /**
601
+ * An array of pricing details associated with the subscription.
602
+ * Each item in the array represents a price option for the subscription.
603
+ */
604
+ prices: SubscriptionPrice[];
605
+ /**
606
+ * A storefront link for the subscription.
607
+ * Provides a link to the storefront where the user can manage or view their subscription.
608
+ */
609
+ storefrontLink: string;
610
+ /**
611
+ * Optional metadata for additional information.
612
+ * A key-value map to store extra information related to the subscription (e.g., tags, custom properties).
613
+ */
614
+ metadata?: Record<string, string>;
615
+ }
616
+ /**
617
+ * Represents the details of a subscription status.
618
+ */
619
+ export interface SubscriptionStatusResponse {
620
+ /**
621
+ * Unique identifier for the subscription.
622
+ */
623
+ id: string;
624
+ /**
625
+ * A description of the subscription.
626
+ * Provides additional details or information about the subscription.
627
+ */
628
+ description: string;
629
+ /**
630
+ * The current status of the subscription.
631
+ * Possible values:
632
+ * - 'active': The subscription is currently active.
633
+ * - 'inactive': The subscription is inactive.
634
+ * - 'pending': The subscription is pending further action.
635
+ * - 'canceled': The subscription has been canceled.
636
+ */
637
+ status: 'active' | 'inactive' | 'pending' | 'canceled';
638
+ /**
639
+ * The date and time when the subscription was created.
640
+ * Represented as an ISO date string.
641
+ */
642
+ createdAt: string;
643
+ /**
644
+ * The date and time when the subscription was last updated.
645
+ * Represented as an ISO date string.
646
+ */
647
+ updatedAt: string;
648
+ /**
649
+ * The start date and time of the current billing period.
650
+ * Represented as an ISO date string.
651
+ */
652
+ currentPeriodStart: string;
653
+ /**
654
+ * The end date and time of the current billing period.
655
+ * Represented as an ISO date string.
656
+ */
657
+ currentPeriodEnd: string;
658
+ /**
659
+ * The name of the tax applied to the subscription, if applicable.
660
+ * If no tax is applied, this will be null.
661
+ */
662
+ taxName: string | null;
663
+ /**
664
+ * The tax identification number associated with the subscription, if applicable.
665
+ * If no tax is applied, this will be null.
666
+ */
667
+ taxId: string | null;
668
+ /**
669
+ * Information about the subscriber.
670
+ */
671
+ subscriber: {
672
+ /**
673
+ * Unique identifier for the subscriber.
674
+ */
675
+ id: string;
676
+ /**
677
+ * The subscriber's first name.
678
+ */
679
+ firstName: string;
680
+ /**
681
+ * The subscriber's last name.
682
+ */
683
+ lastName: string;
684
+ /**
685
+ * The full name of the subscriber, typically a combination of first and last names.
686
+ */
687
+ fullName: string;
688
+ /**
689
+ * The subscriber's email address.
690
+ */
691
+ email: string;
692
+ /**
693
+ * The subscriber's phone number, if provided.
694
+ * If no phone number is provided, this will be null.
695
+ */
696
+ phoneNumber: string | null;
697
+ };
698
+ /**
699
+ * Information related to the subscription checkout.
700
+ */
701
+ checkout: {
702
+ /**
703
+ * Unique identifier for the checkout associated with this subscription.
704
+ */
705
+ id: string;
706
+ };
707
+ /**
708
+ * Information related to the product associated with the subscription.
709
+ */
710
+ product: {
711
+ /**
712
+ * Unique identifier for the product.
713
+ */
714
+ id: string;
715
+ };
716
+ }
717
+ /**
718
+ * Represents an error response from the API.
719
+ */
720
+ export interface ErrorResponse {
721
+ /**
722
+ * The status of the response, indicating an error occurred.
723
+ * This field will always have the value 'error'.
724
+ */
725
+ status: 'error';
726
+ /**
727
+ * A descriptive message providing details about the error.
728
+ * This message gives a general explanation of what went wrong.
729
+ */
730
+ message: string;
731
+ /**
732
+ * Optional validation errors for specific fields.
733
+ * This is a key-value map where each key is the name of a field and the value is an array of error messages related to that field.
734
+ * This is typically used for form or input validation errors.
735
+ */
736
+ errors?: Record<string, string[]>;
737
+ }
738
+ /**
739
+ * Represents the details of a successful payment intent event.
740
+ * This webhook event is triggered when a payment is successfully completed.
741
+ */
742
+ export interface PaymentIntentSucceeded {
743
+ /**
744
+ * Unique identifier for the payment intent.
745
+ */
746
+ id: string;
747
+ /**
748
+ * The event type, which is 'payment_intent.succeeded' for this event.
749
+ */
750
+ eventType: 'payment_intent.succeeded';
751
+ /**
752
+ * The version of the API used during the event.
753
+ */
754
+ apiVersion: string;
755
+ /**
756
+ * Checkout details associated with the payment intent.
757
+ */
758
+ checkout: {
759
+ /**
760
+ * Unique identifier for the checkout session.
761
+ */
762
+ id: string;
763
+ /**
764
+ * The status of the checkout session.
765
+ */
766
+ status: string;
767
+ /**
768
+ * Payment details associated with the checkout.
769
+ */
770
+ payment: {
771
+ /**
772
+ * Unique identifier for the payment.
773
+ */
774
+ id: string;
775
+ /**
776
+ * Details about the entity responsible for the payment, e.g., a subscription or one-time payment.
777
+ */
778
+ paymentable: {
779
+ /**
780
+ * The type of paymentable entity (e.g., 'OneTimePayment').
781
+ */
782
+ type: string;
783
+ /**
784
+ * Unique identifier for the paymentable entity.
785
+ */
786
+ id: string;
787
+ /**
788
+ * The name of the tax applied, if applicable.
789
+ * Null if no tax is applied.
790
+ */
791
+ taxName: string | null;
792
+ /**
793
+ * The tax identification number, if applicable.
794
+ * Null if no tax is applied.
795
+ */
796
+ taxId: string | null;
797
+ /**
798
+ * The address associated with the payment, if provided.
799
+ * Null if no address is provided.
800
+ */
801
+ address: string | null;
802
+ /**
803
+ * The phone number associated with the payment, if provided.
804
+ * Null if no phone number is provided.
805
+ */
806
+ phoneNumber: string | null;
807
+ };
808
+ };
809
+ /**
810
+ * Details of the payment method used for the checkout.
811
+ */
812
+ paymentMethod: {
813
+ /**
814
+ * Unique identifier for the payment method.
815
+ */
816
+ id: string;
817
+ /**
818
+ * The type of payment method, e.g., 'card'.
819
+ */
820
+ type: string;
821
+ /**
822
+ * Card details for the payment method.
823
+ */
824
+ card: {
825
+ /**
826
+ * The last four digits of the card used.
827
+ */
828
+ last4: string;
829
+ /**
830
+ * The card network, e.g., 'visa'.
831
+ */
832
+ network: string;
833
+ };
834
+ };
835
+ /**
836
+ * Array of transfer setups, if any are needed for the payment.
837
+ */
838
+ transferSetups: string[];
839
+ /**
840
+ * Optional metadata for additional information.
841
+ * This is a key-value map storing extra details about the checkout session.
842
+ */
843
+ metadata: Record<string, string>;
844
+ };
845
+ /**
846
+ * The date and time when the payment intent was created, in ISO date format.
847
+ */
848
+ createdAt: string;
849
+ /**
850
+ * The reason for any failure, or null if the payment was successful.
851
+ */
852
+ failureReason: string | null;
853
+ /**
854
+ * The total amount of the payment in cents.
855
+ */
856
+ amountInCents: number;
857
+ /**
858
+ * The currency of the payment (e.g., 'GTQ', 'USD').
859
+ */
860
+ currency: string;
861
+ /**
862
+ * The fee charged for the transaction, in cents.
863
+ */
864
+ fee: number;
865
+ /**
866
+ * The amount of VAT withheld for the transaction, in cents.
867
+ */
868
+ vatWithheld: number;
869
+ /**
870
+ * The currency in which the VAT is withheld.
871
+ */
872
+ vatWithheldCurrency: string;
873
+ /**
874
+ * Customer details associated with the payment.
875
+ */
876
+ customer: {
877
+ /**
878
+ * The customer's email address.
879
+ */
880
+ email: string;
881
+ /**
882
+ * The customer's full name.
883
+ */
884
+ fullName: string;
885
+ /**
886
+ * Unique identifier for the customer.
887
+ */
888
+ id: string;
889
+ };
890
+ /**
891
+ * Additional payment details.
892
+ */
893
+ payment: {
894
+ /**
895
+ * Unique identifier for the payment.
896
+ */
897
+ id: string;
898
+ /**
899
+ * Details about the paymentable entity, including address and tax information.
900
+ */
901
+ paymentable: {
902
+ /**
903
+ * Unique identifier for the paymentable entity.
904
+ */
905
+ id: string;
906
+ /**
907
+ * The tax identification number, if applicable.
908
+ */
909
+ taxId: string | null;
910
+ /**
911
+ * The name of the tax applied, if applicable.
912
+ */
913
+ taxName: string | null;
914
+ /**
915
+ * The type of paymentable entity (e.g., 'Subscription').
916
+ */
917
+ type: string;
918
+ /**
919
+ * The address associated with the paymentable entity.
920
+ */
921
+ address: {
922
+ /**
923
+ * The first line of the address.
924
+ */
925
+ addressLine1: string;
926
+ /**
927
+ * The second line of the address, if any.
928
+ */
929
+ addressLine2: string | null;
930
+ /**
931
+ * The city associated with the address.
932
+ */
933
+ city: string;
934
+ /**
935
+ * The country associated with the address.
936
+ */
937
+ country: string;
938
+ /**
939
+ * The postal code or zip code for the address.
940
+ */
941
+ zipCode: string;
942
+ };
943
+ /**
944
+ * The phone number associated with the paymentable entity.
945
+ */
946
+ phoneNumber: string;
947
+ };
948
+ };
949
+ /**
950
+ * The product associated with the payment intent.
951
+ */
952
+ product: {
953
+ /**
954
+ * Unique identifier for the product.
955
+ */
956
+ id: string;
957
+ };
958
+ /**
959
+ * Invoice details related to the payment, if available.
960
+ */
961
+ invoice: {
962
+ /**
963
+ * Unique identifier for the invoice.
964
+ */
965
+ id: string;
966
+ /**
967
+ * The URL to view or download the tax invoice, if available.
968
+ * Null if no tax invoice is available.
969
+ */
970
+ taxInvoiceUrl: string | null;
971
+ };
972
+ }
973
+ /**
974
+ * Represents the details of a failed payment intent event.
975
+ * This webhook event is triggered when a payment attempt fails.
976
+ */
977
+ export interface PaymentIntentFailed {
978
+ /**
979
+ * Unique identifier for the payment intent.
980
+ */
981
+ id: string;
982
+ /**
983
+ * The event type, which is 'payment_intent.failed' for this event.
984
+ */
985
+ eventType: 'payment_intent.failed';
986
+ /**
987
+ * The version of the API used during the event.
988
+ */
989
+ apiVersion: string;
990
+ /**
991
+ * Checkout details associated with the failed payment intent.
992
+ */
993
+ checkout: {
994
+ /**
995
+ * Unique identifier for the checkout session.
996
+ */
997
+ id: string;
998
+ };
999
+ /**
1000
+ * The date and time when the payment intent was created, in ISO date format.
1001
+ */
1002
+ createdAt: string;
1003
+ /**
1004
+ * The reason for the failure of the payment attempt.
1005
+ */
1006
+ failureReason: string;
1007
+ /**
1008
+ * The total amount of the attempted payment in cents.
1009
+ */
1010
+ amountInCents: number;
1011
+ /**
1012
+ * The currency of the attempted payment (e.g., 'GTQ', 'USD').
1013
+ */
1014
+ currency: string;
1015
+ /**
1016
+ * The fee charged for the transaction, in cents, even if the payment failed.
1017
+ */
1018
+ fee: number;
1019
+ /**
1020
+ * The amount of VAT withheld for the transaction, in cents.
1021
+ */
1022
+ vatWithheld: number;
1023
+ /**
1024
+ * The currency in which the VAT is withheld.
1025
+ */
1026
+ vatWithheldCurrency: string;
1027
+ /**
1028
+ * Customer details associated with the failed payment attempt.
1029
+ */
1030
+ customer: {
1031
+ /**
1032
+ * The customer's email address.
1033
+ */
1034
+ email: string;
1035
+ /**
1036
+ * The customer's full name.
1037
+ */
1038
+ fullName: string;
1039
+ /**
1040
+ * Unique identifier for the customer.
1041
+ */
1042
+ id: string;
1043
+ };
1044
+ /**
1045
+ * Additional payment details.
1046
+ */
1047
+ payment: {
1048
+ /**
1049
+ * Unique identifier for the payment.
1050
+ */
1051
+ id: string;
1052
+ /**
1053
+ * Details about the paymentable entity, including address and tax information.
1054
+ */
1055
+ paymentable: {
1056
+ /**
1057
+ * Unique identifier for the paymentable entity.
1058
+ */
1059
+ id: string;
1060
+ /**
1061
+ * The tax identification number, if applicable.
1062
+ * Null if no tax is applied.
1063
+ */
1064
+ taxId: string | null;
1065
+ /**
1066
+ * The name of the tax applied, if applicable.
1067
+ * Null if no tax is applied.
1068
+ */
1069
+ taxName: string | null;
1070
+ /**
1071
+ * The type of paymentable entity (e.g., 'Subscription').
1072
+ */
1073
+ type: string;
1074
+ /**
1075
+ * The address associated with the paymentable entity.
1076
+ */
1077
+ address: {
1078
+ /**
1079
+ * The first line of the address.
1080
+ */
1081
+ addressLine1: string;
1082
+ /**
1083
+ * The second line of the address, if any.
1084
+ */
1085
+ addressLine2: string | null;
1086
+ /**
1087
+ * The city associated with the address.
1088
+ */
1089
+ city: string;
1090
+ /**
1091
+ * The country associated with the address.
1092
+ */
1093
+ country: string;
1094
+ /**
1095
+ * The postal code or zip code for the address.
1096
+ */
1097
+ zipCode: string;
1098
+ };
1099
+ /**
1100
+ * The phone number associated with the paymentable entity.
1101
+ */
1102
+ phoneNumber: string;
1103
+ };
1104
+ };
1105
+ /**
1106
+ * The product associated with the failed payment intent.
1107
+ */
1108
+ product: {
1109
+ /**
1110
+ * Unique identifier for the product.
1111
+ */
1112
+ id: string;
1113
+ };
1114
+ /**
1115
+ * Invoice details related to the payment, if available.
1116
+ */
1117
+ invoice: {
1118
+ /**
1119
+ * Unique identifier for the invoice.
1120
+ */
1121
+ id: string;
1122
+ /**
1123
+ * The URL to view or download the tax invoice, if available.
1124
+ * Null if no tax invoice is available.
1125
+ */
1126
+ taxInvoiceUrl: string | null;
1127
+ };
1128
+ }
1129
+ /**
1130
+ * Represents the details of a subscription creation event.
1131
+ * This webhook event is triggered when a new subscription is created.
1132
+ */
1133
+ export interface SubscriptionCreate {
1134
+ /**
1135
+ * Unique identifier for the subscription event.
1136
+ */
1137
+ id: string;
1138
+ /**
1139
+ * The event type, which is 'subscription.create' for this event.
1140
+ */
1141
+ eventType: 'subscription.create';
1142
+ /**
1143
+ * The version of the API used during the event.
1144
+ */
1145
+ apiVersion: string;
1146
+ /**
1147
+ * The date and time when the subscription was created, in ISO date format.
1148
+ */
1149
+ createdAt: string;
1150
+ /**
1151
+ * The email address of the customer who created the subscription.
1152
+ */
1153
+ customerEmail: string;
1154
+ /**
1155
+ * Unique identifier for the customer.
1156
+ */
1157
+ customerId: string;
1158
+ /**
1159
+ * The full name of the customer who created the subscription.
1160
+ */
1161
+ customerName: string;
1162
+ }
1163
+ /**
1164
+ * Represents the details of a subscription past due event.
1165
+ * This webhook event is triggered when a subscription becomes past due, indicating that payment has not been made on time.
1166
+ */
1167
+ export interface SubscriptionPastDue {
1168
+ /**
1169
+ * Unique identifier for the past due subscription event.
1170
+ */
1171
+ id: string;
1172
+ /**
1173
+ * The event type, which is 'subscription.past_due' for this event.
1174
+ */
1175
+ eventType: 'subscription.past_due';
1176
+ /**
1177
+ * The version of the API used during the event.
1178
+ */
1179
+ apiVersion: string;
1180
+ /**
1181
+ * The date and time when the subscription became past due, in ISO date format.
1182
+ */
1183
+ createdAt: string;
1184
+ /**
1185
+ * The email address of the customer with the past due subscription.
1186
+ */
1187
+ customerEmail: string;
1188
+ /**
1189
+ * Unique identifier for the customer with the past due subscription.
1190
+ */
1191
+ customerId: string;
1192
+ /**
1193
+ * The full name of the customer with the past due subscription.
1194
+ */
1195
+ customerName: string;
1196
+ }
1197
+ /**
1198
+ * Represents the details of a subscription paused event.
1199
+ * This webhook event is triggered when a subscription is paused.
1200
+ */
1201
+ export interface SubscriptionPaused {
1202
+ /**
1203
+ * Unique identifier for the paused subscription event.
1204
+ */
1205
+ id: string;
1206
+ /**
1207
+ * The event type, which is 'subscription.paused' for this event.
1208
+ */
1209
+ eventType: 'subscription.paused';
1210
+ /**
1211
+ * The version of the API used during the event.
1212
+ */
1213
+ apiVersion: string;
1214
+ /**
1215
+ * The date and time when the subscription was paused, in ISO date format.
1216
+ */
1217
+ createdAt: string;
1218
+ /**
1219
+ * The email address of the customer with the paused subscription.
1220
+ */
1221
+ customerEmail: string;
1222
+ /**
1223
+ * Unique identifier for the customer with the paused subscription.
1224
+ */
1225
+ customerId: string;
1226
+ /**
1227
+ * The full name of the customer with the paused subscription.
1228
+ */
1229
+ customerName: string;
1230
+ }
1231
+ /**
1232
+ * Represents the details of a subscription cancellation event.
1233
+ * This webhook event is triggered when a subscription is canceled.
1234
+ */
1235
+ export interface SubscriptionCancel {
1236
+ /**
1237
+ * Unique identifier for the canceled subscription event.
1238
+ */
1239
+ id: string;
1240
+ /**
1241
+ * The event type, which is 'subscription.cancel' for this event.
1242
+ */
1243
+ eventType: 'subscription.cancel';
1244
+ /**
1245
+ * The version of the API used during the event.
1246
+ */
1247
+ apiVersion: string;
1248
+ /**
1249
+ * The date and time when the subscription was canceled, in ISO date format.
1250
+ */
1251
+ createdAt: string;
1252
+ /**
1253
+ * The email address of the customer whose subscription was canceled.
1254
+ */
1255
+ customerEmail: string;
1256
+ /**
1257
+ * Unique identifier for the customer whose subscription was canceled.
1258
+ */
1259
+ customerId: string;
1260
+ /**
1261
+ * The full name of the customer whose subscription was canceled.
1262
+ */
1263
+ customerName: string;
1264
+ }
1265
+ /**
1266
+ * Represents the possible webhook events that can be triggered in the Recurrente system.
1267
+ * These events correspond to various stages of the payment or subscription lifecycle.
1268
+ */
1269
+ export type RecurrenteWebhookEvent = PaymentIntentSucceeded | PaymentIntentFailed | SubscriptionCreate | SubscriptionPastDue | SubscriptionPaused | SubscriptionCancel;
1270
+ /**
1271
+ * A generic type for handling webhook events.
1272
+ * The handler function receives an event of type T and performs some action.
1273
+ *
1274
+ * @template T - The type of the webhook event being handled.
1275
+ * @param event - The webhook event object.
1276
+ */
1277
+ export type WebhookHandler<T> = (event: T) => void;