@tagadapay/plugin-sdk 2.4.39 → 2.5.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.
Files changed (106) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +2 -0
  3. package/dist/react/hooks/useCheckout.js +19 -2
  4. package/dist/react/hooks/useCheckoutSession.d.ts +19 -0
  5. package/dist/react/hooks/useCheckoutSession.js +108 -0
  6. package/dist/react/hooks/useCheckoutToken.d.ts +17 -0
  7. package/dist/react/hooks/useCheckoutToken.js +80 -0
  8. package/dist/react/hooks/useOrderBump.js +92 -13
  9. package/dist/react/hooks/useOrderBumpV2.d.ts +17 -0
  10. package/dist/react/hooks/useOrderBumpV2.js +95 -0
  11. package/dist/react/hooks/useOrderBumpV3.d.ts +23 -0
  12. package/dist/react/hooks/useOrderBumpV3.js +109 -0
  13. package/dist/react/hooks/usePostPurchases.js +11 -5
  14. package/dist/react/index.d.ts +8 -0
  15. package/dist/react/index.js +4 -0
  16. package/dist/react/services/apiService.d.ts +1 -0
  17. package/dist/react/services/apiService.js +3 -0
  18. package/dist/v2/core/googleAutocomplete.d.ts +65 -0
  19. package/dist/v2/core/googleAutocomplete.js +94 -0
  20. package/dist/v2/core/index.d.ts +8 -0
  21. package/dist/v2/core/index.js +11 -0
  22. package/dist/v2/core/isoData.d.ts +50 -0
  23. package/dist/v2/core/isoData.js +103 -0
  24. package/dist/v2/core/resources/apiClient.d.ts +25 -0
  25. package/dist/v2/core/resources/apiClient.js +95 -0
  26. package/dist/v2/core/resources/checkout.d.ts +189 -0
  27. package/dist/v2/core/resources/checkout.js +119 -0
  28. package/dist/v2/core/resources/index.d.ts +13 -0
  29. package/dist/v2/core/resources/index.js +13 -0
  30. package/dist/v2/core/resources/offers.d.ts +98 -0
  31. package/dist/v2/core/resources/offers.js +115 -0
  32. package/dist/v2/core/resources/orders.d.ts +40 -0
  33. package/dist/v2/core/resources/orders.js +59 -0
  34. package/dist/v2/core/resources/payments.d.ts +140 -0
  35. package/dist/v2/core/resources/payments.js +126 -0
  36. package/dist/v2/core/resources/postPurchases.d.ts +182 -0
  37. package/dist/v2/core/resources/postPurchases.js +116 -0
  38. package/dist/v2/core/resources/products.d.ts +29 -0
  39. package/dist/v2/core/resources/products.js +49 -0
  40. package/dist/v2/core/resources/promotions.d.ts +45 -0
  41. package/dist/v2/core/resources/promotions.js +87 -0
  42. package/dist/v2/core/resources/threeds.d.ts +23 -0
  43. package/dist/v2/core/resources/threeds.js +15 -0
  44. package/dist/v2/core/utils/checkout.d.ts +24 -0
  45. package/dist/v2/core/utils/checkout.js +30 -0
  46. package/dist/v2/core/utils/currency.d.ts +28 -0
  47. package/dist/v2/core/utils/currency.js +272 -0
  48. package/dist/v2/core/utils/index.d.ts +12 -0
  49. package/dist/v2/core/utils/index.js +12 -0
  50. package/dist/v2/core/utils/order.d.ts +159 -0
  51. package/dist/v2/core/utils/order.js +42 -0
  52. package/dist/v2/core/utils/orderBump.d.ts +40 -0
  53. package/dist/v2/core/utils/orderBump.js +47 -0
  54. package/dist/v2/core/utils/pluginConfig.d.ts +43 -0
  55. package/dist/v2/core/utils/pluginConfig.js +155 -0
  56. package/dist/v2/core/utils/postPurchases.d.ts +32 -0
  57. package/dist/v2/core/utils/postPurchases.js +42 -0
  58. package/dist/v2/core/utils/products.d.ts +58 -0
  59. package/dist/v2/core/utils/products.js +64 -0
  60. package/dist/v2/core/utils/promotions.d.ts +24 -0
  61. package/dist/v2/core/utils/promotions.js +30 -0
  62. package/dist/v2/index.d.ts +19 -0
  63. package/dist/v2/index.js +15 -0
  64. package/dist/v2/react/components/DebugDrawer.d.ts +7 -0
  65. package/dist/v2/react/components/DebugDrawer.js +383 -0
  66. package/dist/v2/react/hooks/useApiQuery.d.ts +28 -0
  67. package/dist/v2/react/hooks/useApiQuery.js +84 -0
  68. package/dist/v2/react/hooks/useCheckoutQuery.d.ts +39 -0
  69. package/dist/v2/react/hooks/useCheckoutQuery.js +208 -0
  70. package/dist/v2/react/hooks/useCheckoutToken.d.ts +17 -0
  71. package/dist/v2/react/hooks/useCheckoutToken.js +80 -0
  72. package/dist/v2/react/hooks/useCurrency.d.ts +9 -0
  73. package/dist/v2/react/hooks/useCurrency.js +21 -0
  74. package/dist/v2/react/hooks/useGeoLocation.d.ts +138 -0
  75. package/dist/v2/react/hooks/useGeoLocation.js +126 -0
  76. package/dist/v2/react/hooks/useGoogleAutocomplete.d.ts +74 -0
  77. package/dist/v2/react/hooks/useGoogleAutocomplete.js +207 -0
  78. package/dist/v2/react/hooks/useISOData.d.ts +61 -0
  79. package/dist/v2/react/hooks/useISOData.js +176 -0
  80. package/dist/v2/react/hooks/useOffersQuery.d.ts +65 -0
  81. package/dist/v2/react/hooks/useOffersQuery.js +353 -0
  82. package/dist/v2/react/hooks/useOrderBumpQuery.d.ts +20 -0
  83. package/dist/v2/react/hooks/useOrderBumpQuery.js +88 -0
  84. package/dist/v2/react/hooks/useOrderQuery.d.ts +29 -0
  85. package/dist/v2/react/hooks/useOrderQuery.js +98 -0
  86. package/dist/v2/react/hooks/usePaymentPolling.d.ts +45 -0
  87. package/dist/v2/react/hooks/usePaymentPolling.js +153 -0
  88. package/dist/v2/react/hooks/usePaymentQuery.d.ts +19 -0
  89. package/dist/v2/react/hooks/usePaymentQuery.js +283 -0
  90. package/dist/v2/react/hooks/usePluginConfig.d.ts +16 -0
  91. package/dist/v2/react/hooks/usePluginConfig.js +36 -0
  92. package/dist/v2/react/hooks/usePostPurchasesQuery.d.ts +63 -0
  93. package/dist/v2/react/hooks/usePostPurchasesQuery.js +365 -0
  94. package/dist/v2/react/hooks/useProductsQuery.d.ts +31 -0
  95. package/dist/v2/react/hooks/useProductsQuery.js +102 -0
  96. package/dist/v2/react/hooks/usePromotionsQuery.d.ts +28 -0
  97. package/dist/v2/react/hooks/usePromotionsQuery.js +97 -0
  98. package/dist/v2/react/hooks/useThreeds.d.ts +36 -0
  99. package/dist/v2/react/hooks/useThreeds.js +166 -0
  100. package/dist/v2/react/hooks/useThreedsModal.d.ts +13 -0
  101. package/dist/v2/react/hooks/useThreedsModal.js +343 -0
  102. package/dist/v2/react/index.d.ts +38 -0
  103. package/dist/v2/react/index.js +27 -0
  104. package/dist/v2/react/providers/TagadaProvider.d.ts +63 -0
  105. package/dist/v2/react/providers/TagadaProvider.js +680 -0
  106. package/package.json +10 -3
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Payments Resource Client
3
+ * Axios-based API client for payment endpoints
4
+ */
5
+ import { ApiClient } from './apiClient';
6
+ export interface Payment {
7
+ id: string;
8
+ status: string;
9
+ subStatus: string;
10
+ requireAction: 'none' | 'redirect' | 'error';
11
+ requireActionData?: {
12
+ type: 'redirect' | 'threeds_auth' | 'processor_auth' | 'error';
13
+ url?: string;
14
+ processed: boolean;
15
+ processorId?: string;
16
+ metadata?: {
17
+ type: 'redirect';
18
+ redirect?: {
19
+ redirectUrl: string;
20
+ returnUrl: string;
21
+ };
22
+ threedsSession?: {
23
+ externalSessionId: string;
24
+ acsChallengeUrl: string;
25
+ acsTransID: string;
26
+ messageVersion: string;
27
+ };
28
+ };
29
+ redirectUrl?: string;
30
+ resumeToken?: string;
31
+ message?: string;
32
+ errorCode?: string;
33
+ };
34
+ }
35
+ export interface PaymentResponse {
36
+ paymentId: string;
37
+ payment: Payment;
38
+ order?: any;
39
+ }
40
+ export interface PaymentInstrumentResponse {
41
+ id: string;
42
+ token: string;
43
+ type: string;
44
+ card?: {
45
+ maskedCardNumber?: string;
46
+ expirationMonth?: number;
47
+ expirationYear?: number;
48
+ brand?: string;
49
+ };
50
+ }
51
+ export interface PaymentInstrumentCustomer {
52
+ id: string;
53
+ type: 'card';
54
+ card: {
55
+ last4: string;
56
+ exp_month: number;
57
+ exp_year: number;
58
+ brand: string;
59
+ bin: string;
60
+ };
61
+ us_bank_account: null;
62
+ sepa_debit: null;
63
+ tokenizer: string;
64
+ token: string;
65
+ isDefault: boolean;
66
+ isActive: boolean;
67
+ metadata: Record<string, unknown>;
68
+ customerId: string;
69
+ accountId: string;
70
+ createdAt: string;
71
+ updatedAt: string;
72
+ }
73
+ export type PaymentInstrumentCustomerResponse = PaymentInstrumentCustomer[];
74
+ export interface PaymentOptions {
75
+ enableThreeds?: boolean;
76
+ threedsProvider?: 'basis_theory';
77
+ initiatedBy?: 'customer' | 'merchant';
78
+ source?: 'upsell' | 'checkout' | 'offer' | 'missing_club' | 'forced';
79
+ onSuccess?: (response: PaymentResponse) => void;
80
+ onFailure?: (error: string) => void;
81
+ onRequireAction?: (payment: Payment) => void;
82
+ }
83
+ export interface CardPaymentMethod {
84
+ cardNumber: string;
85
+ expiryDate: string;
86
+ cvc: string;
87
+ cardholderName?: string;
88
+ }
89
+ export interface ApplePayToken {
90
+ id: string;
91
+ type: string;
92
+ card: {
93
+ bin: string;
94
+ last4: string;
95
+ expiration_month: number;
96
+ expiration_year: number;
97
+ brand: string;
98
+ };
99
+ }
100
+ export declare class PaymentsResource {
101
+ private apiClient;
102
+ constructor(apiClient: ApiClient);
103
+ /**
104
+ * Create payment instrument
105
+ */
106
+ createPaymentInstrument(paymentInstrumentData: any): Promise<PaymentInstrumentResponse>;
107
+ /**
108
+ * Create card payment instrument
109
+ */
110
+ createCardPaymentInstrument(basisTheory: any, // BasisTheory instance from @basis-theory/basis-theory-react
111
+ cardData: CardPaymentMethod): Promise<PaymentInstrumentResponse>;
112
+ /**
113
+ * Create Apple Pay payment instrument
114
+ */
115
+ createApplePayPaymentInstrument(basisTheory: any, // BasisTheory instance from @basis-theory/basis-theory-react
116
+ applePayToken: ApplePayToken): Promise<PaymentInstrumentResponse>;
117
+ /**
118
+ * Helper function to format expiry date
119
+ */
120
+ private getCardMonthAndYear;
121
+ /**
122
+ * Process payment directly with checkout session
123
+ */
124
+ processPaymentDirect(checkoutSessionId: string, paymentInstrumentId: string, threedsSessionId?: string, options?: {
125
+ initiatedBy?: 'customer' | 'merchant';
126
+ source?: 'upsell' | 'checkout' | 'offer' | 'missing_club' | 'forced';
127
+ }): Promise<PaymentResponse>;
128
+ /**
129
+ * Get card payment instruments for customer
130
+ */
131
+ getCardPaymentInstruments(): Promise<PaymentInstrumentCustomerResponse>;
132
+ /**
133
+ * Mark payment action as processed
134
+ */
135
+ markPaymentActionProcessed(paymentId: string): Promise<void>;
136
+ /**
137
+ * Get payment status
138
+ */
139
+ getPaymentStatus(paymentId: string): Promise<Payment>;
140
+ }
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Payments Resource Client
3
+ * Axios-based API client for payment endpoints
4
+ */
5
+ export class PaymentsResource {
6
+ constructor(apiClient) {
7
+ this.apiClient = apiClient;
8
+ }
9
+ /**
10
+ * Create payment instrument
11
+ */
12
+ async createPaymentInstrument(paymentInstrumentData) {
13
+ return this.apiClient.post('/api/v1/payment/create-payment-instrument', {
14
+ paymentInstrumentData,
15
+ });
16
+ }
17
+ /**
18
+ * Create card payment instrument
19
+ */
20
+ async createCardPaymentInstrument(basisTheory, // BasisTheory instance from @basis-theory/basis-theory-react
21
+ cardData) {
22
+ if (!basisTheory) {
23
+ throw new Error('Payment processor not initialized');
24
+ }
25
+ console.log('Creating card payment instrument');
26
+ // Create token using BasisTheory
27
+ const btResponse = await basisTheory.tokens.create({
28
+ type: 'card',
29
+ data: {
30
+ cvc: cardData.cvc,
31
+ number: Number(cardData.cardNumber.replace(/\s+/g, '')),
32
+ ...this.getCardMonthAndYear(cardData.expiryDate),
33
+ },
34
+ metadata: {
35
+ nonSensitiveField: 'nonSensitiveValue',
36
+ },
37
+ });
38
+ // Create payment instrument through API
39
+ const { expiration_month, expiration_year } = this.getCardMonthAndYear(cardData.expiryDate);
40
+ const paymentInstrumentData = {
41
+ type: btResponse.type,
42
+ card: {
43
+ maskedCardNumber: btResponse.enrichments?.cardDetails?.bin ?
44
+ `${btResponse.enrichments.cardDetails.bin}****${btResponse.enrichments.cardDetails.last4}` :
45
+ cardData.cardNumber.replace(/\d(?=\d{4})/g, '*'),
46
+ expirationMonth: expiration_month,
47
+ expirationYear: expiration_year,
48
+ },
49
+ token: btResponse.id,
50
+ };
51
+ const response = await this.apiClient.post('/api/v1/payment/create-payment-instrument', { paymentInstrumentData });
52
+ console.log('Payment instrument created:', response);
53
+ return response;
54
+ }
55
+ /**
56
+ * Create Apple Pay payment instrument
57
+ */
58
+ async createApplePayPaymentInstrument(basisTheory, // BasisTheory instance from @basis-theory/basis-theory-react
59
+ applePayToken) {
60
+ if (!basisTheory) {
61
+ throw new Error('Payment processor not initialized');
62
+ }
63
+ if (!applePayToken.id) {
64
+ throw new Error('Apple Pay token is missing');
65
+ }
66
+ const paymentInstrumentData = {
67
+ type: 'apple_pay',
68
+ token: applePayToken.id,
69
+ dpanType: applePayToken.type,
70
+ card: {
71
+ bin: applePayToken.card.bin,
72
+ last4: applePayToken.card.last4,
73
+ expirationMonth: applePayToken.card.expiration_month,
74
+ expirationYear: applePayToken.card.expiration_year,
75
+ brand: applePayToken.card.brand,
76
+ },
77
+ };
78
+ const response = await this.apiClient.post('/api/v1/payment/create-payment-instrument', { paymentInstrumentData });
79
+ return response;
80
+ }
81
+ /**
82
+ * Helper function to format expiry date
83
+ */
84
+ getCardMonthAndYear(expiryDate) {
85
+ const [month, year] = expiryDate.split('/');
86
+ const currentYear = new Date().getFullYear();
87
+ const century = Math.floor(currentYear / 100) * 100;
88
+ const fullYear = Number(year) + century;
89
+ return {
90
+ expiration_month: Number(month),
91
+ expiration_year: fullYear,
92
+ };
93
+ }
94
+ /**
95
+ * Process payment directly with checkout session
96
+ */
97
+ async processPaymentDirect(checkoutSessionId, paymentInstrumentId, threedsSessionId, options = {}) {
98
+ return this.apiClient.post('/api/public/v1/checkout/pay-v2', {
99
+ checkoutSessionId,
100
+ paymentInstrumentId,
101
+ ...(threedsSessionId && { threedsSessionId }),
102
+ ...(options.initiatedBy && { initiatedBy: options.initiatedBy }),
103
+ ...(options.source && { source: options.source }),
104
+ });
105
+ }
106
+ /**
107
+ * Get card payment instruments for customer
108
+ */
109
+ async getCardPaymentInstruments() {
110
+ return this.apiClient.get('/api/v1/payment-instruments/customer');
111
+ }
112
+ /**
113
+ * Mark payment action as processed
114
+ */
115
+ async markPaymentActionProcessed(paymentId) {
116
+ return this.apiClient.post('/api/v1/payments/require-action/processed', {
117
+ paymentId,
118
+ });
119
+ }
120
+ /**
121
+ * Get payment status
122
+ */
123
+ async getPaymentStatus(paymentId) {
124
+ return this.apiClient.get(`/api/v1/payments/${paymentId}`);
125
+ }
126
+ }
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Post Purchases Resource Client
3
+ * Axios-based API client for post-purchase endpoints
4
+ */
5
+ import { ApiClient } from './apiClient';
6
+ export interface PostPurchaseOfferItem {
7
+ id: string;
8
+ productId: string;
9
+ variantId: string;
10
+ product: {
11
+ name: string;
12
+ description: string;
13
+ };
14
+ variant: {
15
+ name: string;
16
+ description: string;
17
+ imageUrl: string;
18
+ grams: number | null;
19
+ };
20
+ unitAmount: number;
21
+ quantity: number;
22
+ amount: number;
23
+ adjustedAmount: number;
24
+ }
25
+ export interface PostPurchaseOfferSummary {
26
+ currency: string;
27
+ totalAmount: number;
28
+ totalAdjustedAmount: number;
29
+ items: PostPurchaseOfferItem[];
30
+ }
31
+ export interface PostPurchaseOfferLineItem {
32
+ id: string;
33
+ quantity: number;
34
+ price: {
35
+ variant: {
36
+ id: string;
37
+ name: string;
38
+ description: string | null;
39
+ grams: number | null;
40
+ product: {
41
+ id: string;
42
+ name: string;
43
+ description: string;
44
+ };
45
+ };
46
+ };
47
+ }
48
+ export interface PostPurchaseOffer {
49
+ id: string;
50
+ titleTrans: Record<string, string> | null;
51
+ summaries: PostPurchaseOfferSummary[];
52
+ offerLineItems: PostPurchaseOfferLineItem[];
53
+ }
54
+ export interface CurrencyOptions {
55
+ rate: number;
56
+ date: string;
57
+ amount: number;
58
+ lock: boolean;
59
+ }
60
+ export interface VariantOption {
61
+ id: string;
62
+ name: string;
63
+ sku: string | null;
64
+ default: boolean | null;
65
+ externalVariantId: string | null;
66
+ prices: {
67
+ id: string;
68
+ currencyOptions: CurrencyOptions;
69
+ }[];
70
+ }
71
+ export interface OrderSummaryItem {
72
+ id: string;
73
+ productId: string;
74
+ productName: string;
75
+ productDescription: string | null;
76
+ variantId: string;
77
+ variantName: string;
78
+ variantSku: string | null;
79
+ variantDefault: boolean | null;
80
+ variantExternalId: string | null;
81
+ priceId: string;
82
+ currencyOptions: CurrencyOptions;
83
+ quantity: number;
84
+ unitAmount: number;
85
+ amount: number;
86
+ adjustedAmount: number;
87
+ imageUrl?: string;
88
+ product: {
89
+ name: string;
90
+ description: string;
91
+ };
92
+ variant: {
93
+ name: string;
94
+ description: string;
95
+ imageUrl: string;
96
+ grams: number | null;
97
+ };
98
+ }
99
+ export interface OrderSummary {
100
+ items: OrderSummaryItem[];
101
+ totalAmount: number;
102
+ totalAdjustedAmount: number;
103
+ totalPromotionAmount: number;
104
+ currency: string;
105
+ options: Record<string, VariantOption[]>;
106
+ }
107
+ export interface CheckoutSessionState {
108
+ checkoutSessionId: string | null;
109
+ orderSummary: OrderSummary | null;
110
+ selectedVariants: Record<string, string>;
111
+ loadingVariants: Record<string, boolean>;
112
+ isUpdatingSummary: boolean;
113
+ }
114
+ export declare class PostPurchasesResource {
115
+ private apiClient;
116
+ constructor(apiClient: ApiClient);
117
+ /**
118
+ * Get post-purchase offers for an order
119
+ */
120
+ getPostPurchaseOffers(orderId: string): Promise<PostPurchaseOffer[]>;
121
+ /**
122
+ * Accept a post-purchase offer
123
+ */
124
+ acceptOffer(orderId: string, offerId: string, items: PostPurchaseOfferItem[]): Promise<{
125
+ success: boolean;
126
+ summary?: PostPurchaseOfferSummary;
127
+ error?: string;
128
+ }>;
129
+ /**
130
+ * Decline a post-purchase offer
131
+ */
132
+ declineOffer(orderId: string, offerId: string): Promise<{
133
+ success: boolean;
134
+ error?: string;
135
+ }>;
136
+ /**
137
+ * Preview a post-purchase offer
138
+ */
139
+ previewOffer(orderId: string, offerId: string, items: PostPurchaseOfferItem[]): Promise<{
140
+ success: boolean;
141
+ summary?: PostPurchaseOfferSummary;
142
+ error?: string;
143
+ }>;
144
+ /**
145
+ * Create a post-purchase order
146
+ */
147
+ createPostPurchaseOrder(orderId: string, offers: PostPurchaseOffer[]): Promise<{
148
+ success: boolean;
149
+ error?: string;
150
+ orderId?: string;
151
+ }>;
152
+ /**
153
+ * Initialize a checkout session for a post-purchase offer
154
+ */
155
+ initCheckoutSession(offerId: string, orderId: string, customerId?: string): Promise<{
156
+ checkoutSessionId: string;
157
+ }>;
158
+ /**
159
+ * Initialize a checkout session for a post-purchase offer with specific variants
160
+ */
161
+ initCheckoutSessionWithVariants(offerId: string, orderId: string, lineItems: {
162
+ variantId: string;
163
+ quantity: number;
164
+ }[]): Promise<{
165
+ checkoutSessionId: string;
166
+ }>;
167
+ /**
168
+ * Pay with a checkout session for a post-purchase offer
169
+ */
170
+ payWithCheckoutSession(checkoutSessionId: string, orderId?: string): Promise<void>;
171
+ /**
172
+ * Get order summary for a checkout session
173
+ */
174
+ getOrderSummary(sessionId: string, includeVariantOptions?: boolean): Promise<any>;
175
+ /**
176
+ * Update line items for a checkout session
177
+ */
178
+ updateLineItems(sessionId: string, lineItems: {
179
+ variantId: string;
180
+ quantity: number;
181
+ }[]): Promise<any>;
182
+ }
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Post Purchases Resource Client
3
+ * Axios-based API client for post-purchase endpoints
4
+ */
5
+ export class PostPurchasesResource {
6
+ constructor(apiClient) {
7
+ this.apiClient = apiClient;
8
+ }
9
+ /**
10
+ * Get post-purchase offers for an order
11
+ */
12
+ async getPostPurchaseOffers(orderId) {
13
+ const response = await this.apiClient.get(`/api/v1/post-purchase/${orderId}/offers`);
14
+ return response || [];
15
+ }
16
+ /**
17
+ * Accept a post-purchase offer
18
+ */
19
+ async acceptOffer(orderId, offerId, items) {
20
+ return this.apiClient.post(`/api/v1/orders/${orderId}/post-purchase-offers/${offerId}/accept`, {
21
+ items,
22
+ });
23
+ }
24
+ /**
25
+ * Decline a post-purchase offer
26
+ */
27
+ async declineOffer(orderId, offerId) {
28
+ return this.apiClient.post(`/api/v1/orders/${orderId}/post-purchase-offers/${offerId}/decline`);
29
+ }
30
+ /**
31
+ * Preview a post-purchase offer
32
+ */
33
+ async previewOffer(orderId, offerId, items) {
34
+ return this.apiClient.post(`/api/v1/orders/${orderId}/post-purchase-offers/${offerId}/preview`, {
35
+ items,
36
+ });
37
+ }
38
+ /**
39
+ * Create a post-purchase order
40
+ */
41
+ async createPostPurchaseOrder(orderId, offers) {
42
+ try {
43
+ const response = await this.apiClient.post(`/api/v1/orders/${orderId}/post-purchase`, {
44
+ offers, // Use all offers since they don't have isSelected property
45
+ });
46
+ if (response.success) {
47
+ return { success: true, orderId: response.orderId };
48
+ }
49
+ else {
50
+ return { success: false, error: response.error || 'Failed to create post-purchase order' };
51
+ }
52
+ }
53
+ catch (error) {
54
+ return {
55
+ success: false,
56
+ error: error instanceof Error ? error.message : 'Failed to create post-purchase order',
57
+ };
58
+ }
59
+ }
60
+ /**
61
+ * Initialize a checkout session for a post-purchase offer
62
+ */
63
+ async initCheckoutSession(offerId, orderId, customerId) {
64
+ const response = await this.apiClient.post('/api/v1/checkout/offer/init', {
65
+ offerId,
66
+ returnUrl: typeof window !== 'undefined' ? window.location.href : '',
67
+ customerId: customerId || '',
68
+ orderId,
69
+ });
70
+ return { checkoutSessionId: response.checkoutSessionId };
71
+ }
72
+ /**
73
+ * Initialize a checkout session for a post-purchase offer with specific variants
74
+ */
75
+ async initCheckoutSessionWithVariants(offerId, orderId, lineItems) {
76
+ const response = await this.apiClient.post(`/api/v1/offers/${offerId}/transform-to-checkout`, {
77
+ offerId,
78
+ lineItems,
79
+ returnUrl: typeof window !== 'undefined' ? window.location.href : '',
80
+ mainOrderId: orderId,
81
+ });
82
+ return { checkoutSessionId: response.checkoutSessionId };
83
+ }
84
+ /**
85
+ * Pay with a checkout session for a post-purchase offer
86
+ */
87
+ async payWithCheckoutSession(checkoutSessionId, orderId) {
88
+ await this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/pay`, {
89
+ checkoutSessionId,
90
+ draft: false,
91
+ returnUrl: typeof window !== 'undefined' ? window.location.href : '',
92
+ metadata: {
93
+ comingFromPostPurchase: true,
94
+ postOrder: orderId,
95
+ upsell: true,
96
+ source: 'post_purchase_offer',
97
+ },
98
+ });
99
+ }
100
+ /**
101
+ * Get order summary for a checkout session
102
+ */
103
+ async getOrderSummary(sessionId, includeVariantOptions = false) {
104
+ return this.apiClient.post(`/api/v1/checkout-sessions/${sessionId}/order-summary`, {
105
+ includeVariantOptions,
106
+ });
107
+ }
108
+ /**
109
+ * Update line items for a checkout session
110
+ */
111
+ async updateLineItems(sessionId, lineItems) {
112
+ return this.apiClient.post(`/api/v1/checkout-sessions/${sessionId}/line-items`, {
113
+ lineItems,
114
+ });
115
+ }
116
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Products Resource Client
3
+ * Axios-based API client for product endpoints
4
+ */
5
+ import type { Product, ProductVariant, ProductPrice } from '../utils/products';
6
+ import { ApiClient } from './apiClient';
7
+ export interface GetProductsOptions {
8
+ storeId: string;
9
+ productIds?: string[];
10
+ includeVariants?: boolean;
11
+ includePrices?: boolean;
12
+ }
13
+ export type { Product, ProductVariant, ProductPrice };
14
+ export declare class ProductsResource {
15
+ private apiClient;
16
+ constructor(apiClient: ApiClient);
17
+ /**
18
+ * Get all products for a store
19
+ */
20
+ getProducts(options: GetProductsOptions): Promise<Product[]>;
21
+ /**
22
+ * Get a specific product by ID
23
+ */
24
+ getProduct(productId: string, options: GetProductsOptions): Promise<Product | null>;
25
+ /**
26
+ * Get multiple products by IDs
27
+ */
28
+ getProductsByIds(productIds: string[], options: GetProductsOptions): Promise<Product[]>;
29
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Products Resource Client
3
+ * Axios-based API client for product endpoints
4
+ */
5
+ export class ProductsResource {
6
+ constructor(apiClient) {
7
+ this.apiClient = apiClient;
8
+ }
9
+ /**
10
+ * Get all products for a store
11
+ */
12
+ async getProducts(options) {
13
+ const { storeId, includeVariants = true, includePrices = true } = options;
14
+ const response = await this.apiClient.post('/api/v1/products', {
15
+ storeId,
16
+ includeVariants,
17
+ includePrices,
18
+ });
19
+ return Array.isArray(response) ? response : response.items ?? [];
20
+ }
21
+ /**
22
+ * Get a specific product by ID
23
+ */
24
+ async getProduct(productId, options) {
25
+ const { storeId } = options;
26
+ try {
27
+ const response = await this.apiClient.post(`/api/v1/products/${productId}`, {
28
+ productId,
29
+ storeId,
30
+ });
31
+ return response || null;
32
+ }
33
+ catch (error) {
34
+ console.error('Error fetching product:', error);
35
+ return null;
36
+ }
37
+ }
38
+ /**
39
+ * Get multiple products by IDs
40
+ */
41
+ async getProductsByIds(productIds, options) {
42
+ const { storeId, includeVariants = true, includePrices = true } = options;
43
+ const fetchPromises = productIds.map(async (productId) => {
44
+ return this.getProduct(productId, { storeId, includeVariants, includePrices });
45
+ });
46
+ const results = await Promise.all(fetchPromises);
47
+ return results.filter((product) => product !== null);
48
+ }
49
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Promotions Resource Client
3
+ * Axios-based API client for promotion endpoints
4
+ */
5
+ import { ApiClient } from './apiClient';
6
+ import { Promotion } from './checkout';
7
+ export interface PromotionCodeValidation {
8
+ isValid: boolean;
9
+ code: string;
10
+ error?: string;
11
+ promotion?: {
12
+ id: string;
13
+ name: string;
14
+ type: string;
15
+ value: number;
16
+ currency: string;
17
+ };
18
+ }
19
+ export declare class PromotionsResource {
20
+ private apiClient;
21
+ constructor(apiClient: ApiClient);
22
+ /**
23
+ * Get applied promotions for a checkout session
24
+ */
25
+ getAppliedPromotions(checkoutSessionId: string): Promise<Promotion[]>;
26
+ /**
27
+ * Apply a promotion code to a checkout session
28
+ */
29
+ applyPromotionCode(checkoutSessionId: string, code: string): Promise<{
30
+ success: boolean;
31
+ error?: string;
32
+ promotion?: Promotion;
33
+ }>;
34
+ /**
35
+ * Remove a promotion from a checkout session
36
+ */
37
+ removePromotionCode(checkoutSessionId: string, promotionId: string): Promise<{
38
+ success: boolean;
39
+ error?: string;
40
+ }>;
41
+ /**
42
+ * Validate a promotion code without applying it
43
+ */
44
+ validatePromotionCode(checkoutSessionId: string, code: string): Promise<PromotionCodeValidation>;
45
+ }