@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,189 @@
1
+ /**
2
+ * Checkout Resource Client
3
+ * Axios-based API client for checkout endpoints
4
+ */
5
+ import { ApiClient } from './apiClient';
6
+ export interface CheckoutLineItem {
7
+ externalProductId?: string | null;
8
+ externalVariantId?: string | null;
9
+ variantId?: string | null;
10
+ priceId?: string | null;
11
+ quantity: number;
12
+ }
13
+ export interface CheckoutInitParams {
14
+ lineItems: CheckoutLineItem[];
15
+ cartToken?: string;
16
+ promotionIds?: string[];
17
+ returnUrl?: string;
18
+ draft?: boolean;
19
+ useCustomDomain?: boolean;
20
+ customerMetadata?: Record<string, unknown>;
21
+ metadata?: Record<string, unknown>;
22
+ storeId?: string;
23
+ customer?: {
24
+ currency?: string;
25
+ locale?: string;
26
+ };
27
+ }
28
+ export interface CheckoutSession {
29
+ id: string;
30
+ checkoutToken: string;
31
+ status: string;
32
+ storeId: string;
33
+ accountId: string;
34
+ customerId: string;
35
+ draft: boolean;
36
+ createdAt: string;
37
+ updatedAt: string;
38
+ lastActiveDate: string;
39
+ selectedPresentmentCurrency: string;
40
+ [key: string]: any;
41
+ }
42
+ export interface CheckoutData {
43
+ checkoutSession: CheckoutSession;
44
+ customerIsClubMember: boolean;
45
+ clubProductId?: string;
46
+ summary: any;
47
+ availablePromotions: any[];
48
+ }
49
+ export interface Promotion {
50
+ id: string;
51
+ name: string;
52
+ description: string | null;
53
+ type: string;
54
+ rules: any[];
55
+ actions: any[];
56
+ }
57
+ export declare class CheckoutResource {
58
+ private apiClient;
59
+ constructor(apiClient: ApiClient);
60
+ /**
61
+ * Initialize a new checkout session
62
+ */
63
+ initCheckout(params: CheckoutInitParams): Promise<{
64
+ checkoutUrl: string;
65
+ checkoutSession: CheckoutSession;
66
+ checkoutToken: string;
67
+ }>;
68
+ /**
69
+ * Get checkout session by token
70
+ */
71
+ getCheckout(checkoutToken: string, currency?: string): Promise<CheckoutData>;
72
+ /**
73
+ * Update checkout address
74
+ */
75
+ updateAddress(checkoutSessionId: string, data: {
76
+ shippingAddress: any;
77
+ billingAddress?: any;
78
+ }): Promise<{
79
+ success: boolean;
80
+ errors?: Record<string, {
81
+ message: string;
82
+ type: string;
83
+ }>;
84
+ shippingCountryChanged: boolean;
85
+ billingCountryChanged: boolean;
86
+ }>;
87
+ /**
88
+ * Set checkout info
89
+ */
90
+ setCheckoutInfo(checkoutSessionId: string, data: {
91
+ shippingAddress: any;
92
+ billingAddress?: any;
93
+ differentBillingAddress?: boolean;
94
+ }): Promise<{
95
+ success: boolean;
96
+ errors?: Record<string, {
97
+ message: string;
98
+ type: string;
99
+ }>;
100
+ shippingCountryChanged?: boolean;
101
+ billingCountryChanged?: boolean;
102
+ }>;
103
+ /**
104
+ * Apply promotion code
105
+ */
106
+ applyPromotionCode(checkoutSessionId: string, code: string): Promise<{
107
+ success: boolean;
108
+ error?: any;
109
+ }>;
110
+ /**
111
+ * Remove promotion
112
+ */
113
+ removePromotion(checkoutSessionId: string, promotionId: string): Promise<{
114
+ success: boolean;
115
+ error?: any;
116
+ }>;
117
+ /**
118
+ * Get applied promotions
119
+ */
120
+ getAppliedPromotions(checkoutSessionId: string): Promise<Promotion[]>;
121
+ /**
122
+ * Update line items
123
+ */
124
+ updateLineItems(checkoutSessionId: string, lineItems: CheckoutLineItem[]): Promise<{
125
+ success: boolean;
126
+ error?: any;
127
+ }>;
128
+ /**
129
+ * Add line items
130
+ */
131
+ addLineItems(checkoutSessionId: string, lineItems: CheckoutLineItem[]): Promise<{
132
+ success: boolean;
133
+ error?: any;
134
+ }>;
135
+ /**
136
+ * Remove line items
137
+ */
138
+ removeLineItems(checkoutSessionId: string, lineItems: {
139
+ variantId: string;
140
+ quantity?: number;
141
+ }[]): Promise<{
142
+ success: boolean;
143
+ error?: any;
144
+ }>;
145
+ /**
146
+ * Set item quantity
147
+ */
148
+ setItemQuantity(checkoutSessionId: string, variantId: string, quantity: number, priceId?: string): Promise<{
149
+ success: boolean;
150
+ error?: any;
151
+ }>;
152
+ /**
153
+ * Toggle order bump
154
+ */
155
+ toggleOrderBump(checkoutSessionId: string, orderBumpOfferId: string, selected: boolean): Promise<{
156
+ success: boolean;
157
+ error?: any;
158
+ }>;
159
+ /**
160
+ * Update customer
161
+ */
162
+ updateCustomer(checkoutSessionId: string, data: {
163
+ email: string;
164
+ acceptsMarketing?: boolean;
165
+ }): Promise<{
166
+ success: boolean;
167
+ error?: any;
168
+ }>;
169
+ /**
170
+ * Update customer and session info
171
+ */
172
+ updateCustomerAndSessionInfo(checkoutSessionId: string, data: {
173
+ customerData: {
174
+ email: string;
175
+ acceptsMarketing?: boolean;
176
+ };
177
+ shippingAddress: any;
178
+ billingAddress?: any;
179
+ differentBillingAddress?: boolean;
180
+ }): Promise<{
181
+ success: boolean;
182
+ errors?: Record<string, {
183
+ message: string;
184
+ type: string;
185
+ }>;
186
+ shippingCountryChanged?: boolean;
187
+ billingCountryChanged?: boolean;
188
+ }>;
189
+ }
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Checkout Resource Client
3
+ * Axios-based API client for checkout endpoints
4
+ */
5
+ export class CheckoutResource {
6
+ constructor(apiClient) {
7
+ this.apiClient = apiClient;
8
+ }
9
+ /**
10
+ * Initialize a new checkout session
11
+ */
12
+ async initCheckout(params) {
13
+ return this.apiClient.post('/api/v1/checkout/session/init', params);
14
+ }
15
+ /**
16
+ * Get checkout session by token
17
+ */
18
+ async getCheckout(checkoutToken, currency) {
19
+ const queryParams = new URLSearchParams();
20
+ if (currency) {
21
+ queryParams.set('currency', currency);
22
+ }
23
+ const url = `/api/v1/checkout-sessions/${checkoutToken}/v2${queryParams.toString() ? `?${queryParams.toString()}` : ''}`;
24
+ return this.apiClient.get(url);
25
+ }
26
+ /**
27
+ * Update checkout address
28
+ */
29
+ async updateAddress(checkoutSessionId, data) {
30
+ return this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/address`, {
31
+ data,
32
+ });
33
+ }
34
+ /**
35
+ * Set checkout info
36
+ */
37
+ async setCheckoutInfo(checkoutSessionId, data) {
38
+ return this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/checkout-info`, {
39
+ shippingAddress: data.shippingAddress,
40
+ billingAddress: data.differentBillingAddress ? data.billingAddress : data.shippingAddress,
41
+ differentBillingAddress: data.differentBillingAddress || false,
42
+ });
43
+ }
44
+ /**
45
+ * Apply promotion code
46
+ */
47
+ async applyPromotionCode(checkoutSessionId, code) {
48
+ return this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/promotions/apply`, {
49
+ code,
50
+ });
51
+ }
52
+ /**
53
+ * Remove promotion
54
+ */
55
+ async removePromotion(checkoutSessionId, promotionId) {
56
+ return this.apiClient.delete(`/api/v1/checkout-sessions/${checkoutSessionId}/promotions/${promotionId}`);
57
+ }
58
+ /**
59
+ * Get applied promotions
60
+ */
61
+ async getAppliedPromotions(checkoutSessionId) {
62
+ return this.apiClient.get(`/api/v1/checkout-sessions/${checkoutSessionId}/promotions`);
63
+ }
64
+ /**
65
+ * Update line items
66
+ */
67
+ async updateLineItems(checkoutSessionId, lineItems) {
68
+ return this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/line-items`, {
69
+ lineItems,
70
+ });
71
+ }
72
+ /**
73
+ * Add line items
74
+ */
75
+ async addLineItems(checkoutSessionId, lineItems) {
76
+ return this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/line-items/add`, {
77
+ lineItems,
78
+ });
79
+ }
80
+ /**
81
+ * Remove line items
82
+ */
83
+ async removeLineItems(checkoutSessionId, lineItems) {
84
+ return this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/line-items/remove`, {
85
+ lineItems,
86
+ });
87
+ }
88
+ /**
89
+ * Set item quantity
90
+ */
91
+ async setItemQuantity(checkoutSessionId, variantId, quantity, priceId) {
92
+ return this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/line-items/set-quantity`, {
93
+ variantId,
94
+ quantity,
95
+ priceId,
96
+ });
97
+ }
98
+ /**
99
+ * Toggle order bump
100
+ */
101
+ async toggleOrderBump(checkoutSessionId, orderBumpOfferId, selected) {
102
+ return this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/toggle-order-bump`, {
103
+ orderBumpOfferId,
104
+ selected,
105
+ });
106
+ }
107
+ /**
108
+ * Update customer
109
+ */
110
+ async updateCustomer(checkoutSessionId, data) {
111
+ return this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/customer`, data);
112
+ }
113
+ /**
114
+ * Update customer and session info
115
+ */
116
+ async updateCustomerAndSessionInfo(checkoutSessionId, data) {
117
+ return this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/customer-and-session-info`, data);
118
+ }
119
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Resource Clients
3
+ * Axios-based API clients for all endpoints
4
+ */
5
+ export * from './apiClient';
6
+ export * from './products';
7
+ export * from './orders';
8
+ export * from './payments';
9
+ export * from './checkout';
10
+ export * from './promotions';
11
+ export * from './postPurchases';
12
+ export * from './offers';
13
+ export * from './threeds';
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Resource Clients
3
+ * Axios-based API clients for all endpoints
4
+ */
5
+ export * from './apiClient';
6
+ export * from './products';
7
+ export * from './orders';
8
+ export * from './payments';
9
+ export * from './checkout';
10
+ export * from './promotions';
11
+ export * from './postPurchases';
12
+ export * from './offers';
13
+ export * from './threeds';
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Offers Resource Client
3
+ * Axios-based API client for offers endpoints
4
+ */
5
+ import { ApiClient } from './apiClient';
6
+ export interface OfferItem {
7
+ id: string;
8
+ product: {
9
+ name: string;
10
+ description: string;
11
+ };
12
+ variant: {
13
+ name: string;
14
+ imageUrl: string;
15
+ };
16
+ quantity: number;
17
+ unitAmount: number;
18
+ amount: number;
19
+ adjustedAmount: number;
20
+ currency: string;
21
+ }
22
+ export interface OfferSummary {
23
+ items: OfferItem[];
24
+ totalAmount: number;
25
+ totalAdjustedAmount: number;
26
+ totalPromotionAmount: number;
27
+ currency: string;
28
+ adjustments: {
29
+ type: string;
30
+ description: string;
31
+ amount: number;
32
+ }[];
33
+ }
34
+ import type { CurrencyOptions, VariantOption, OrderSummaryItem, OrderSummary, CheckoutSessionState } from './postPurchases';
35
+ export type { CurrencyOptions, VariantOption, OrderSummaryItem, OrderSummary, CheckoutSessionState };
36
+ export interface Offer {
37
+ id: string;
38
+ titleTrans: Record<string, string>;
39
+ summaries: OfferSummary[];
40
+ }
41
+ export declare class OffersResource {
42
+ private apiClient;
43
+ constructor(apiClient: ApiClient);
44
+ /**
45
+ * Get offers for a store
46
+ */
47
+ getOffers(storeId: string): Promise<Offer[]>;
48
+ /**
49
+ * Get offers by IDs
50
+ */
51
+ getOffersByIds(storeId: string, offerIds: string[]): Promise<Offer[]>;
52
+ /**
53
+ * Initialize checkout session for an offer
54
+ */
55
+ initCheckoutSession(offerId: string, orderId: string, customerId?: string): Promise<{
56
+ checkoutSessionId: string;
57
+ }>;
58
+ /**
59
+ * Create checkout session for an offer
60
+ */
61
+ createCheckoutSession(offerId: string, returnUrl?: string): Promise<{
62
+ checkoutUrl: string;
63
+ }>;
64
+ /**
65
+ * Pay with checkout session
66
+ */
67
+ payWithCheckoutSession(checkoutSessionId: string, orderId?: string): Promise<void>;
68
+ /**
69
+ * Pay for an offer directly
70
+ */
71
+ payOffer(offerId: string, orderId?: string): Promise<any>;
72
+ /**
73
+ * Transform offer to checkout session with dynamic variant selection
74
+ */
75
+ transformToCheckout(offerId: string, returnUrl?: string): Promise<{
76
+ checkoutUrl: string;
77
+ }>;
78
+ /**
79
+ * Initialize checkout session for an offer with variants (similar to postPurchases)
80
+ */
81
+ initCheckoutSessionWithVariants(offerId: string, lineItems: {
82
+ variantId: string;
83
+ quantity: number;
84
+ }[], returnUrl?: string): Promise<{
85
+ checkoutSessionId: string;
86
+ }>;
87
+ /**
88
+ * Get order summary for a checkout session
89
+ */
90
+ getOrderSummary(sessionId: string, includeVariantOptions?: boolean): Promise<any>;
91
+ /**
92
+ * Update line items for a checkout session
93
+ */
94
+ updateLineItems(sessionId: string, lineItems: {
95
+ variantId: string;
96
+ quantity: number;
97
+ }[]): Promise<any>;
98
+ }
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Offers Resource Client
3
+ * Axios-based API client for offers endpoints
4
+ */
5
+ export class OffersResource {
6
+ constructor(apiClient) {
7
+ this.apiClient = apiClient;
8
+ }
9
+ /**
10
+ * Get offers for a store
11
+ */
12
+ async getOffers(storeId) {
13
+ const response = await this.apiClient.get(`/api/v1/stores/${storeId}/offers`);
14
+ return response.offers || [];
15
+ }
16
+ /**
17
+ * Get offers by IDs
18
+ */
19
+ async getOffersByIds(storeId, offerIds) {
20
+ const allOffers = await this.getOffers(storeId);
21
+ return allOffers.filter(offer => offerIds.includes(offer.id));
22
+ }
23
+ /**
24
+ * Initialize checkout session for an offer
25
+ */
26
+ async initCheckoutSession(offerId, orderId, customerId) {
27
+ const response = await this.apiClient.post('/api/v1/checkout/offer/init', {
28
+ offerId,
29
+ returnUrl: typeof window !== 'undefined' ? window.location.href : '',
30
+ customerId: customerId || '',
31
+ orderId,
32
+ });
33
+ return { checkoutSessionId: response.checkoutSessionId };
34
+ }
35
+ /**
36
+ * Create checkout session for an offer
37
+ */
38
+ async createCheckoutSession(offerId, returnUrl) {
39
+ const response = await this.apiClient.post(`/api/v1/offers/${offerId}/checkout`, {
40
+ returnUrl: returnUrl || (typeof window !== 'undefined' ? window.location.origin : ''),
41
+ });
42
+ return { checkoutUrl: response.checkoutUrl };
43
+ }
44
+ /**
45
+ * Pay with checkout session
46
+ */
47
+ async payWithCheckoutSession(checkoutSessionId, orderId) {
48
+ await this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/pay`, {
49
+ checkoutSessionId,
50
+ draft: false,
51
+ returnUrl: typeof window !== 'undefined' ? window.location.href : '',
52
+ metadata: {
53
+ comingFromPostPurchase: true,
54
+ postOrder: orderId,
55
+ upsell: true,
56
+ source: 'offer',
57
+ },
58
+ });
59
+ }
60
+ /**
61
+ * Pay for an offer directly
62
+ */
63
+ async payOffer(offerId, orderId) {
64
+ return this.apiClient.post(`/api/v1/offers/${offerId}/pay`, {
65
+ offerId,
66
+ draft: false,
67
+ returnUrl: typeof window !== 'undefined' ? window.location.href : '',
68
+ metadata: orderId ? {
69
+ comingFromPostPurchase: true,
70
+ postOrder: orderId,
71
+ upsell: true,
72
+ source: 'offer',
73
+ } : {
74
+ upsell: true,
75
+ source: 'offer',
76
+ },
77
+ });
78
+ }
79
+ /**
80
+ * Transform offer to checkout session with dynamic variant selection
81
+ */
82
+ async transformToCheckout(offerId, returnUrl) {
83
+ const response = await this.apiClient.post(`/api/v1/offers/${offerId}/transform-to-checkout`, {
84
+ returnUrl: returnUrl || (typeof window !== 'undefined' ? window.location.origin : ''),
85
+ });
86
+ return { checkoutUrl: response.checkoutUrl };
87
+ }
88
+ /**
89
+ * Initialize checkout session for an offer with variants (similar to postPurchases)
90
+ */
91
+ async initCheckoutSessionWithVariants(offerId, lineItems, returnUrl) {
92
+ const response = await this.apiClient.post(`/api/v1/offers/${offerId}/transform-to-checkout`, {
93
+ offerId,
94
+ lineItems,
95
+ returnUrl: returnUrl || (typeof window !== 'undefined' ? window.location.href : ''),
96
+ });
97
+ return { checkoutSessionId: response.checkoutSessionId };
98
+ }
99
+ /**
100
+ * Get order summary for a checkout session
101
+ */
102
+ async getOrderSummary(sessionId, includeVariantOptions = false) {
103
+ return this.apiClient.post(`/api/v1/checkout-sessions/${sessionId}/order-summary`, {
104
+ includeVariantOptions,
105
+ });
106
+ }
107
+ /**
108
+ * Update line items for a checkout session
109
+ */
110
+ async updateLineItems(sessionId, lineItems) {
111
+ return this.apiClient.post(`/api/v1/checkout-sessions/${sessionId}/line-items`, {
112
+ lineItems,
113
+ });
114
+ }
115
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Orders Resource Client
3
+ * Axios-based API client for order endpoints
4
+ */
5
+ import { Order, OrderLineItem } from '../utils/order';
6
+ import { ApiClient } from './apiClient';
7
+ export declare class OrdersResource {
8
+ private apiClient;
9
+ constructor(apiClient: ApiClient);
10
+ /**
11
+ * Fetch order by ID
12
+ */
13
+ getOrder(orderId: string): Promise<Order>;
14
+ /**
15
+ * Create a new order
16
+ */
17
+ createOrder(checkoutSessionId: string): Promise<{
18
+ success: boolean;
19
+ order?: Order;
20
+ error?: string;
21
+ }>;
22
+ /**
23
+ * Update order status
24
+ */
25
+ updateOrderStatus(orderId: string, status: string): Promise<{
26
+ success: boolean;
27
+ error?: string;
28
+ }>;
29
+ /**
30
+ * Add items to an order
31
+ */
32
+ addOrderItems(orderId: string, items: Omit<OrderLineItem, 'id'>[]): Promise<{
33
+ success: boolean;
34
+ error?: string;
35
+ }>;
36
+ /**
37
+ * Get order line items
38
+ */
39
+ getOrderLineItems(orderId: string): Promise<OrderLineItem[]>;
40
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Orders Resource Client
3
+ * Axios-based API client for order endpoints
4
+ */
5
+ export class OrdersResource {
6
+ constructor(apiClient) {
7
+ this.apiClient = apiClient;
8
+ }
9
+ /**
10
+ * Fetch order by ID
11
+ */
12
+ async getOrder(orderId) {
13
+ const response = await this.apiClient.get(`/api/v1/orders/${orderId}`);
14
+ // Handle both response formats: { success, order } and { order }
15
+ if (typeof response === 'object' && response !== null && 'success' in response && response.success === false) {
16
+ throw new Error(response.error || 'Failed to fetch order');
17
+ }
18
+ // If response has success property, use response.order
19
+ // Otherwise, assume the response itself is the order data or has order property
20
+ const orderData = typeof response === 'object' && response !== null && 'order' in response
21
+ ? response.order
22
+ : response;
23
+ if (!orderData) {
24
+ throw new Error('Order not found');
25
+ }
26
+ return orderData;
27
+ }
28
+ /**
29
+ * Create a new order
30
+ */
31
+ async createOrder(checkoutSessionId) {
32
+ return this.apiClient.post('/api/v1/orders', {
33
+ checkoutSessionId,
34
+ });
35
+ }
36
+ /**
37
+ * Update order status
38
+ */
39
+ async updateOrderStatus(orderId, status) {
40
+ return this.apiClient.patch(`/api/v1/orders/${orderId}/status`, {
41
+ status,
42
+ });
43
+ }
44
+ /**
45
+ * Add items to an order
46
+ */
47
+ async addOrderItems(orderId, items) {
48
+ return this.apiClient.post(`/api/v1/orders/${orderId}/items`, {
49
+ items,
50
+ });
51
+ }
52
+ /**
53
+ * Get order line items
54
+ */
55
+ async getOrderLineItems(orderId) {
56
+ const order = await this.getOrder(orderId);
57
+ return order.items || [];
58
+ }
59
+ }