@godaddy/react
Version:
The `createCheckoutSession` function creates a new checkout session with GoDaddy's commerce API.
55 lines (51 loc) • 2.37 kB
JavaScript
import { lt as checkoutMutationKeys, o as useCheckoutContext } from "./checkout-CXoZls_3.js";
import { _ as getDraftOrderTaxes, g as getDraftOrderShippingMethods, h as getDraftOrderPriceAdjustments } from "./godaddy-BJi9zezb.js";
import { d as useGoDaddyContext } from "./utils-COGudLge.js";
import { useMutation } from "@tanstack/react-query";
//#region src/components/checkout/discount/utils/use-get-price-adjustments.ts
function useGetPriceAdjustments() {
const { session, jwt } = useCheckoutContext();
const { apiHost } = useGoDaddyContext();
return useMutation({
mutationKey: checkoutMutationKeys.getPriceAdjustments(session?.id),
mutationFn: async ({ discountCodes, shippingLines }) => {
return (jwt ? await getDraftOrderPriceAdjustments({ accessToken: jwt }, discountCodes, shippingLines, apiHost) : await getDraftOrderPriceAdjustments(session, discountCodes, shippingLines, apiHost)).checkoutSession?.draftOrder?.calculatedAdjustments;
}
});
}
//#endregion
//#region src/components/checkout/shipping/utils/use-get-shipping-methods.ts
function useGetShippingMethodByAddress() {
const { session, jwt } = useCheckoutContext();
const { apiHost } = useGoDaddyContext();
return useMutation({
mutationKey: checkoutMutationKeys.getShippingMethodByAddress(session?.id),
mutationFn: async (destination) => {
if (!session) return;
return (jwt ? await getDraftOrderShippingMethods({ accessToken: jwt }, destination, apiHost) : await getDraftOrderShippingMethods(session, destination, apiHost)).checkoutSession?.draftOrder?.calculatedShippingRates?.rates || [];
}
});
}
//#endregion
//#region src/components/checkout/taxes/utils/use-get-taxes.ts
function useGetTaxes() {
const { session, jwt } = useCheckoutContext();
const { apiHost } = useGoDaddyContext();
return useMutation({
mutationKey: checkoutMutationKeys.getTaxes(session?.id),
mutationFn: async ({ destination, lines, discountAdjustments }) => {
if (!session) return;
return (jwt ? await getDraftOrderTaxes({ accessToken: jwt }, {
destination,
lines,
discountAdjustments
}, apiHost) : await getDraftOrderTaxes(session, {
destination,
lines,
discountAdjustments
}, apiHost)).checkoutSession?.draftOrder?.calculatedTaxes;
}
});
}
//#endregion
export { useGetShippingMethodByAddress as n, useGetPriceAdjustments as r, useGetTaxes as t };