@godaddy/react
Version:
The `createCheckoutSession` function creates a new checkout session with GoDaddy's commerce API.
43 lines (41 loc) • 2.21 kB
JavaScript
import { K as CheckoutSectionHeader, M as useCanOfferShippingAddressAsBilling, N as BillingCollectionLocations, P as BillingCollectionModes, U as PaymentMethodType, ft as CheckoutSection, j as useBillingPolicy, k as PaymentAddressToggle, q as AddressForm } from "./checkout-CXoZls_3.js";
import "./godaddy-BJi9zezb.js";
import { d as useGoDaddyContext } from "./utils-COGudLge.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 };