@tagadapay/plugin-sdk 2.7.8 → 2.7.9
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.
|
@@ -308,4 +308,13 @@ export declare class CheckoutResource {
|
|
|
308
308
|
shippingCountryChanged?: boolean;
|
|
309
309
|
billingCountryChanged?: boolean;
|
|
310
310
|
}>;
|
|
311
|
+
previewCheckoutSession(params: {
|
|
312
|
+
lineItems: CheckoutLineItem[];
|
|
313
|
+
storeId?: string;
|
|
314
|
+
currency: string;
|
|
315
|
+
promotionIds?: string[];
|
|
316
|
+
}): Promise<{
|
|
317
|
+
success: boolean;
|
|
318
|
+
preview: CheckoutSessionPreview;
|
|
319
|
+
}>;
|
|
311
320
|
}
|
|
@@ -117,4 +117,7 @@ export class CheckoutResource {
|
|
|
117
117
|
async updateCustomerAndSessionInfo(checkoutSessionId, data) {
|
|
118
118
|
return this.apiClient.post(`/api/v1/checkout-sessions/${checkoutSessionId}/customer-and-session-info`, data);
|
|
119
119
|
}
|
|
120
|
+
async previewCheckoutSession(params) {
|
|
121
|
+
return this.apiClient.post('/api/v1/checkout-sessions/preview', params);
|
|
122
|
+
}
|
|
120
123
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Checkout Hook using TanStack Query
|
|
3
3
|
* Replaces the coordinator pattern with automatic cache invalidation
|
|
4
4
|
*/
|
|
5
|
-
import { CheckoutData, CheckoutInitParams, CheckoutLineItem } from '../../core/resources/checkout';
|
|
5
|
+
import { CheckoutData, CheckoutInitParams, CheckoutLineItem, CheckoutSessionPreview } from '../../core/resources/checkout';
|
|
6
6
|
export interface UseCheckoutQueryOptions {
|
|
7
7
|
checkoutToken?: string;
|
|
8
8
|
enabled?: boolean;
|
|
@@ -36,5 +36,9 @@ export interface UseCheckoutQueryResult {
|
|
|
36
36
|
}) => Promise<any>;
|
|
37
37
|
applyPromotionCode: (code: string) => Promise<any>;
|
|
38
38
|
removePromotion: (promotionId: string) => Promise<any>;
|
|
39
|
+
previewCheckoutSession: (lineItems: CheckoutLineItem[], promotionIds?: string[]) => Promise<{
|
|
40
|
+
success: boolean;
|
|
41
|
+
preview: CheckoutSessionPreview;
|
|
42
|
+
}>;
|
|
39
43
|
}
|
|
40
44
|
export declare function useCheckoutQuery(options?: UseCheckoutQueryOptions): UseCheckoutQueryResult;
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
* Checkout Hook using TanStack Query
|
|
3
3
|
* Replaces the coordinator pattern with automatic cache invalidation
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
6
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
7
7
|
import { CheckoutResource } from '../../core/resources/checkout';
|
|
8
8
|
import { useTagadaContext } from '../providers/TagadaProvider';
|
|
9
|
-
import { usePluginConfig } from './usePluginConfig';
|
|
10
|
-
import { useCurrency } from './useCurrency';
|
|
11
9
|
import { getGlobalApiClient } from './useApiQuery';
|
|
10
|
+
import { useCurrency } from './useCurrency';
|
|
11
|
+
import { usePluginConfig } from './usePluginConfig';
|
|
12
12
|
export function useCheckoutQuery(options = {}) {
|
|
13
13
|
const { checkoutToken: providedToken, enabled = true } = options;
|
|
14
14
|
const { storeId } = usePluginConfig();
|
|
@@ -237,6 +237,14 @@ export function useCheckoutQuery(options = {}) {
|
|
|
237
237
|
}
|
|
238
238
|
},
|
|
239
239
|
});
|
|
240
|
+
const previewCheckoutSessionMutation = useMutation({
|
|
241
|
+
mutationFn: ({ lineItems, promotionIds }) => checkoutResource.previewCheckoutSession({
|
|
242
|
+
lineItems,
|
|
243
|
+
storeId,
|
|
244
|
+
currency: currency.code,
|
|
245
|
+
promotionIds,
|
|
246
|
+
}),
|
|
247
|
+
});
|
|
240
248
|
return {
|
|
241
249
|
// Query data
|
|
242
250
|
checkout,
|
|
@@ -265,5 +273,6 @@ export function useCheckoutQuery(options = {}) {
|
|
|
265
273
|
updateCustomerAndSessionInfo: (data) => customerAndSessionMutation.mutateAsync(data),
|
|
266
274
|
applyPromotionCode: (code) => promotionMutation.mutateAsync({ code }),
|
|
267
275
|
removePromotion: (promotionId) => removePromotionMutation.mutateAsync({ promotionId }),
|
|
276
|
+
previewCheckoutSession: (lineItems, promotionIds) => previewCheckoutSessionMutation.mutateAsync({ lineItems, promotionIds }),
|
|
268
277
|
};
|
|
269
278
|
}
|