UNPKG

@godaddy/react

Version:

The `createCheckoutSession` function creates a new checkout session with GoDaddy's commerce API.

43 lines (41 loc) • 2.22 kB
import { $ as PaymentMethodType, H as useCanOfferShippingAddressAsBilling, St as CheckoutSection, U as BillingCollectionLocations, V as useBillingPolicy, W as BillingCollectionModes, nt as CheckoutSectionHeader, rt as AddressForm, z as PaymentAddressToggle } from "./checkout-CYyQY2Wk.js"; import "./godaddy-diAn6flX.js"; import { d as useGoDaddyContext } from "./utils-7H42wSPT.js"; import "./utils-CL8rvaTY.js"; import { useCallback } from "react"; import { Fragment, jsx, jsxs } from "react/jsx-runtime"; import { useFormContext } from "react-hook-form"; //#region src/components/checkout/payment/payment-methods/credit-card/container.tsx function CreditCardContainer({ children }) { const form = useFormContext(); const { t } = useGoDaddyContext(); const paymentMethod = form.watch("paymentMethod"); const billingPolicy = useBillingPolicy(); const canOfferShippingAddressAsBilling = useCanOfferShippingAddressAsBilling(); const shouldShowBilling = billingPolicy.location === BillingCollectionLocations.INLINE_PAYMENT_FORM && paymentMethod === PaymentMethodType.CREDIT_CARD && billingPolicy.mode !== BillingCollectionModes.NONE; const billingCopy = billingPolicy.mode === BillingCollectionModes.NAMES && t.payment.billingInformation ? t.payment.billingInformation : t.payment.billingAddress; 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, canOfferShippingAddressAsBilling && paymentMethod === PaymentMethodType.CREDIT_CARD && /* @__PURE__ */ jsx(PaymentAddressToggle, { className: "pt-4" }), shouldShowBilling ? /* @__PURE__ */ jsxs(CheckoutSection, { className: "pt-5", children: [/* @__PURE__ */ jsx(CheckoutSectionHeader, { title: billingCopy.title, description: billingCopy.description }), /* @__PURE__ */ jsx(AddressForm, { sectionKey: "billing", onlyNames: billingPolicy.mode === BillingCollectionModes.NAMES })] }) : null ] }); } //#endregion export { CreditCardContainer };