@tagadapay/plugin-sdk 2.4.38 → 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 (112) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +2 -0
  3. package/dist/react/hooks/useCheckout.js +21 -33
  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 +94 -29
  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/usePayment.d.ts +1 -1
  14. package/dist/react/hooks/usePayment.js +2 -18
  15. package/dist/react/hooks/usePluginConfig.js +2 -13
  16. package/dist/react/hooks/usePostPurchases.js +11 -5
  17. package/dist/react/hooks/useProducts.js +2 -16
  18. package/dist/react/index.d.ts +9 -1
  19. package/dist/react/index.js +5 -1
  20. package/dist/react/providers/TagadaProvider.d.ts +0 -1
  21. package/dist/react/providers/TagadaProvider.js +16 -12
  22. package/dist/react/services/apiService.d.ts +1 -0
  23. package/dist/react/services/apiService.js +3 -0
  24. package/dist/v2/core/googleAutocomplete.d.ts +65 -0
  25. package/dist/v2/core/googleAutocomplete.js +94 -0
  26. package/dist/v2/core/index.d.ts +8 -0
  27. package/dist/v2/core/index.js +11 -0
  28. package/dist/v2/core/isoData.d.ts +50 -0
  29. package/dist/v2/core/isoData.js +103 -0
  30. package/dist/v2/core/resources/apiClient.d.ts +25 -0
  31. package/dist/v2/core/resources/apiClient.js +95 -0
  32. package/dist/v2/core/resources/checkout.d.ts +189 -0
  33. package/dist/v2/core/resources/checkout.js +119 -0
  34. package/dist/v2/core/resources/index.d.ts +13 -0
  35. package/dist/v2/core/resources/index.js +13 -0
  36. package/dist/v2/core/resources/offers.d.ts +98 -0
  37. package/dist/v2/core/resources/offers.js +115 -0
  38. package/dist/v2/core/resources/orders.d.ts +40 -0
  39. package/dist/v2/core/resources/orders.js +59 -0
  40. package/dist/v2/core/resources/payments.d.ts +140 -0
  41. package/dist/v2/core/resources/payments.js +126 -0
  42. package/dist/v2/core/resources/postPurchases.d.ts +182 -0
  43. package/dist/v2/core/resources/postPurchases.js +116 -0
  44. package/dist/v2/core/resources/products.d.ts +29 -0
  45. package/dist/v2/core/resources/products.js +49 -0
  46. package/dist/v2/core/resources/promotions.d.ts +45 -0
  47. package/dist/v2/core/resources/promotions.js +87 -0
  48. package/dist/v2/core/resources/threeds.d.ts +23 -0
  49. package/dist/v2/core/resources/threeds.js +15 -0
  50. package/dist/v2/core/utils/checkout.d.ts +24 -0
  51. package/dist/v2/core/utils/checkout.js +30 -0
  52. package/dist/v2/core/utils/currency.d.ts +28 -0
  53. package/dist/v2/core/utils/currency.js +272 -0
  54. package/dist/v2/core/utils/index.d.ts +12 -0
  55. package/dist/v2/core/utils/index.js +12 -0
  56. package/dist/v2/core/utils/order.d.ts +159 -0
  57. package/dist/v2/core/utils/order.js +42 -0
  58. package/dist/v2/core/utils/orderBump.d.ts +40 -0
  59. package/dist/v2/core/utils/orderBump.js +47 -0
  60. package/dist/v2/core/utils/pluginConfig.d.ts +43 -0
  61. package/dist/v2/core/utils/pluginConfig.js +155 -0
  62. package/dist/v2/core/utils/postPurchases.d.ts +32 -0
  63. package/dist/v2/core/utils/postPurchases.js +42 -0
  64. package/dist/v2/core/utils/products.d.ts +58 -0
  65. package/dist/v2/core/utils/products.js +64 -0
  66. package/dist/v2/core/utils/promotions.d.ts +24 -0
  67. package/dist/v2/core/utils/promotions.js +30 -0
  68. package/dist/v2/index.d.ts +19 -0
  69. package/dist/v2/index.js +15 -0
  70. package/dist/v2/react/components/DebugDrawer.d.ts +7 -0
  71. package/dist/v2/react/components/DebugDrawer.js +383 -0
  72. package/dist/v2/react/hooks/useApiQuery.d.ts +28 -0
  73. package/dist/v2/react/hooks/useApiQuery.js +84 -0
  74. package/dist/v2/react/hooks/useCheckoutQuery.d.ts +39 -0
  75. package/dist/v2/react/hooks/useCheckoutQuery.js +208 -0
  76. package/dist/v2/react/hooks/useCheckoutToken.d.ts +17 -0
  77. package/dist/v2/react/hooks/useCheckoutToken.js +80 -0
  78. package/dist/v2/react/hooks/useCurrency.d.ts +9 -0
  79. package/dist/v2/react/hooks/useCurrency.js +21 -0
  80. package/dist/v2/react/hooks/useGeoLocation.d.ts +138 -0
  81. package/dist/v2/react/hooks/useGeoLocation.js +126 -0
  82. package/dist/v2/react/hooks/useGoogleAutocomplete.d.ts +74 -0
  83. package/dist/v2/react/hooks/useGoogleAutocomplete.js +207 -0
  84. package/dist/v2/react/hooks/useISOData.d.ts +61 -0
  85. package/dist/v2/react/hooks/useISOData.js +176 -0
  86. package/dist/v2/react/hooks/useOffersQuery.d.ts +65 -0
  87. package/dist/v2/react/hooks/useOffersQuery.js +353 -0
  88. package/dist/v2/react/hooks/useOrderBumpQuery.d.ts +20 -0
  89. package/dist/v2/react/hooks/useOrderBumpQuery.js +88 -0
  90. package/dist/v2/react/hooks/useOrderQuery.d.ts +29 -0
  91. package/dist/v2/react/hooks/useOrderQuery.js +98 -0
  92. package/dist/v2/react/hooks/usePaymentPolling.d.ts +45 -0
  93. package/dist/v2/react/hooks/usePaymentPolling.js +153 -0
  94. package/dist/v2/react/hooks/usePaymentQuery.d.ts +19 -0
  95. package/dist/v2/react/hooks/usePaymentQuery.js +283 -0
  96. package/dist/v2/react/hooks/usePluginConfig.d.ts +16 -0
  97. package/dist/v2/react/hooks/usePluginConfig.js +36 -0
  98. package/dist/v2/react/hooks/usePostPurchasesQuery.d.ts +63 -0
  99. package/dist/v2/react/hooks/usePostPurchasesQuery.js +365 -0
  100. package/dist/v2/react/hooks/useProductsQuery.d.ts +31 -0
  101. package/dist/v2/react/hooks/useProductsQuery.js +102 -0
  102. package/dist/v2/react/hooks/usePromotionsQuery.d.ts +28 -0
  103. package/dist/v2/react/hooks/usePromotionsQuery.js +97 -0
  104. package/dist/v2/react/hooks/useThreeds.d.ts +36 -0
  105. package/dist/v2/react/hooks/useThreeds.js +166 -0
  106. package/dist/v2/react/hooks/useThreedsModal.d.ts +13 -0
  107. package/dist/v2/react/hooks/useThreedsModal.js +343 -0
  108. package/dist/v2/react/index.d.ts +38 -0
  109. package/dist/v2/react/index.js +27 -0
  110. package/dist/v2/react/providers/TagadaProvider.d.ts +63 -0
  111. package/dist/v2/react/providers/TagadaProvider.js +680 -0
  112. package/package.json +10 -3
@@ -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
+ }
@@ -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
+ }