@godaddy/react
Version:
The `createCheckoutSession` function creates a new checkout session with GoDaddy's commerce API.
54 lines (50 loc) • 2.4 kB
JavaScript
import { o as useCheckoutContext, rt as useGoDaddyContext } from "./checkout-B7yB0DfE.js";
import { b as getDraftOrderShippingMethods, x as getDraftOrderTaxes, y as getDraftOrderPriceAdjustments } from "./utils-DWBfAHfx.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: ["get-price-adjustments-by-discount-code", session?.id ?? "no-session"],
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: session?.id ? ["get-shipping-method-by-address", session.id] : ["get-shipping-method-by-address"],
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: session?.id ? ["get-taxes-without-order", session.id] : ["get-taxes-without-order"],
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 };