@godaddy/react
Version:
The `createCheckoutSession` function creates a new checkout session with GoDaddy's commerce API.
40 lines (38 loc) • 2.06 kB
JavaScript
import { A as CheckoutSectionHeader, G as DeliveryMethods, O as PaymentMethodType, P as AddressForm, b as PaymentAddressToggle, j as CheckoutSection, o as useCheckoutContext, rt as useGoDaddyContext } from "./checkout-B7yB0DfE.js";
import "./utils-DWBfAHfx.js";
import { useCallback } from "react";
import { useFormContext } from "react-hook-form";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
//#region src/components/checkout/payment/payment-methods/credit-card/container.tsx
function CreditCardContainer({ children }) {
const { session } = useCheckoutContext();
const form = useFormContext();
const { t } = useGoDaddyContext();
const paymentMethod = form.watch("paymentMethod");
const useShippingAddress = form.watch("paymentUseShippingAddress");
const deliveryMethod = form.watch("deliveryMethod");
const isShipping = deliveryMethod === DeliveryMethods.SHIP;
const isPickup = deliveryMethod === DeliveryMethods.PICKUP;
const isBillingAddressRequired = !session?.enableShipping || session?.enableBillingAddressCollection && (!useShippingAddress || isPickup) && paymentMethod === PaymentMethodType.CREDIT_CARD;
const description = useCallback(() => {
if (paymentMethod === "card") return t.payment.descriptions?.creditCard;
}, [paymentMethod, t])();
if (!children) return null;
return /* @__PURE__ */ jsxs(Fragment, { children: [
description && /* @__PURE__ */ jsx("div", {
className: "pb-4",
children: description
}),
children,
session?.enableShipping && isShipping && paymentMethod === PaymentMethodType.CREDIT_CARD && session?.enableBillingAddressCollection && /* @__PURE__ */ jsx(PaymentAddressToggle, { className: "pt-4" }),
isBillingAddressRequired ? /* @__PURE__ */ jsxs(CheckoutSection, {
className: "pt-5",
children: [/* @__PURE__ */ jsx(CheckoutSectionHeader, {
title: t.payment.billingAddress.title,
description: t.payment.billingAddress.description
}), /* @__PURE__ */ jsx(AddressForm, { sectionKey: "billing" })]
}) : null
] });
}
//#endregion
export { CreditCardContainer };