UNPKG

@godaddy/react

Version:

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

514 lines (513 loc) 20.8 kB
import { $ as SKUPrice, A as ConfirmCheckoutMutationInput, B as PaymentMethodType, C as CartTax, D as CheckoutSessionOptions, E as CheckoutSessionLocation, F as GetCheckoutSessionShippingRatesInput, G as SKU, H as PaymentMethods, I as GetCheckoutSessionTaxesInput, J as SKUGroupAttribute, K as SKUAttributeValue, L as MutationVerifyAddress, M as DraftOrder, N as DraftOrderPriceAdjustmentsQueryInput, O as CheckoutSessionResult, P as DraftOrderSession, Q as SKUMedia, R as PaymentMethodConfig, S as CartShippingInfo, T as CheckoutSessionInput, U as PaymentProvider, V as PaymentMethodValue, W as RemoveAppliedCheckoutSessionShippingMethodInput, X as SKUGroupSKU, Y as SKUGroupAttributeValue, Z as SKUInventoryCount, _ as CartLineItemDetails, _t as LinkComponentProps, a as ApplyCheckoutSessionDeliveryMethodInput, at as SkuInput, b as CartOrder, c as ApplyCheckoutSessionShippingMethodInput, ct as UpdateCartOrderInput, d as AvailablePaymentProviders, dt as CSSVariables, et as SKUProduct, f as CalculateCheckoutSessionTaxesInput, ft as GoDaddyAppearance, g as CartLineItem, gt as GoDaddyVariables, h as CartDiscount, ht as GoDaddyTheme, i as Address, it as SkuGroupsInput, j as DeleteLineItemByIdInput, k as CheckoutType, l as ApplyDiscountCodesInput, lt as UpdateDraftOrderInput, m as CalculatedTaxes, mt as GoDaddyProviderProps, n as AddCartOrderInput, nt as ShippingMethod, o as ApplyCheckoutSessionDiscountInput, ot as StoreHours, p as CalculatedAdjustments, pt as GoDaddyProvider, q as SKUGroup, r as AddLineItemBySkuIdInput, rt as SkuGroupInput, s as ApplyCheckoutSessionFulfillmentLocationInput, st as Totals, t as $Values, tt as ShippingLines, u as AuthorizeCheckoutSessionInput, ut as UpdateLineItemByIdInput, v as CartLineItemTotals, vt as queryClient, w as CheckoutSession, x as CartOrderTotals, y as CartNote, yt as useGoDaddyContext, z as PaymentMethodKey } from "./types-Di3nqeZ1.js"; import React$1, { ReactNode } from "react"; import { z } from "zod"; import * as react_jsx_runtime11 from "react/jsx-runtime"; //#region src/components/checkout/delivery/delivery-method.d.ts declare enum DeliveryMethods { NONE = "NONE", PICKUP = "PICKUP", SHIP = "SHIP", CURBSIDE = "CURBSIDE", DELIVERY = "DELIVERY", DRIVE_THRU = "DRIVE_THRU", FOR_HERE = "FOR_HERE", TO_GO = "TO_GO", DIGITAL = "DIGITAL", PURCHASE = "PURCHASE", GENERAL_CONTAINER = "GENERAL_CONTAINER", QUICK_STAY = "QUICK_STAY", REGULAR_STAY = "REGULAR_STAY", NON_LODGING_NRR = "NON_LODGING_NRR", NON_LODGING_SALE = "NON_LODGING_SALE", GIFT_CARD = "GIFT_CARD", } //#endregion //#region src/hooks/use-theme.d.ts declare const themes: { readonly base: { readonly value: "theme-base"; readonly label: "Base"; }; readonly purple: { readonly value: "theme-purple"; readonly label: "Purple"; }; readonly orange: { readonly value: "theme-orange"; readonly label: "Orange"; }; }; type Theme = keyof typeof themes; //#endregion //#region src/tracking/event-properties.d.ts type TrackingProperties = { [key: string]: string | number | boolean | null; }; //#endregion //#region src/components/checkout/target/target.d.ts type Target = 'checkout.before' | 'checkout.after' | 'checkout.form.before' | 'checkout.form.after' | 'checkout.form.contact.before' | 'checkout.form.contact.after' | 'checkout.form.express-checkout.before' | 'checkout.form.express-checkout.after' | 'checkout.form.pickup.before' | 'checkout.form.pickup.after' | 'checkout.form.pickup.form.before' | 'checkout.form.delivery.before' | 'checkout.form.delivery.after' | 'checkout.form.tips.before' | 'checkout.form.tips.after' | 'checkout.form.shipping.before' | 'checkout.form.shipping.after' | 'checkout.form.payment.before' | 'checkout.form.payment.after' | 'checkout.form.submit.before' | 'checkout.form.submit.after' | 'checkout.summary.before' | 'checkout.summary.after'; declare function Target({ id }: { id: Target; }): react_jsx_runtime11.JSX.Element; //#endregion //#region src/components/checkout/checkout.d.ts declare function redirectToSuccessUrl(successUrl?: string): void; interface CheckoutElements { input?: string; select?: string; button?: string; card?: string; checkbox?: string; radio?: string; } interface Appearance { theme?: Theme; elements?: CheckoutElements; variables?: Omit<GoDaddyVariables, 'checkout'>; } type LayoutSection = 'express-checkout' | 'contact' | 'shipping' | 'payment' | 'pickup' | 'tips' | 'delivery'; declare const LayoutSections: { readonly EXPRESS_CHECKOUT: "express-checkout"; readonly CONTACT: "contact"; readonly SHIPPING: "shipping"; readonly PAYMENT: "payment"; readonly PICKUP: "pickup"; readonly DELIVERY: "delivery"; readonly TIPS: "tips"; }; type StripeConfig = { publishableKey: string; testMode?: boolean; }; type GodaddyPaymentsConfig = { businessId?: string; appId: string; }; type SquareConfig = { locationId: string; appId: string; }; type PayPalConfig = { clientId: string; disableFunding?: Array<'credit' | 'card' | 'paylater' | 'venmo'>; }; type MercadoPagoConfig = { publicKey: string; country: 'AR' | 'BR' | 'CO' | 'CL' | 'PE' | 'MX'; }; type CCAvenueConfig = { accessCodeId: string; }; interface CheckoutContextValue { elements?: CheckoutElements; targets?: Partial<Record<Target, (session?: CheckoutSession | null) => ReactNode>>; session?: CheckoutSession | null; jwt?: string; isCheckoutDisabled?: boolean; stripeConfig?: StripeConfig; godaddyPaymentsConfig?: GodaddyPaymentsConfig; squareConfig?: SquareConfig; paypalConfig?: PayPalConfig; mercadoPagoConfig?: MercadoPagoConfig; ccavenueConfig?: CCAvenueConfig; isConfirmingCheckout: boolean; setIsConfirmingCheckout: (isConfirming: boolean) => void; checkoutErrors?: string[] | undefined; setCheckoutErrors: (error?: string[] | undefined) => void; requiredFields?: { [key: string]: boolean; }; } declare const checkoutContext: React$1.Context<CheckoutContextValue>; declare const useCheckoutContext: () => CheckoutContextValue; declare const baseCheckoutSchema: z.ZodObject<{ contactEmail: z.ZodString; deliveryMethod: z.ZodNativeEnum<typeof DeliveryMethods>; paymentUseShippingAddress: z.ZodDefault<z.ZodBoolean>; shippingFirstName: z.ZodString; shippingLastName: z.ZodString; shippingPhone: z.ZodOptional<z.ZodString>; shippingAddressLine1: z.ZodString; shippingAddressLine2: z.ZodOptional<z.ZodString>; shippingAddressLine3: z.ZodOptional<z.ZodString>; shippingAdminArea4: z.ZodOptional<z.ZodString>; shippingAdminArea3: z.ZodOptional<z.ZodString>; shippingAdminArea2: z.ZodString; shippingAdminArea1: z.ZodString; shippingPostalCode: z.ZodString; shippingCountryCode: z.ZodString; shippingMethod: z.ZodOptional<z.ZodString>; shippingValid: z.ZodLiteral<true>; billingFirstName: z.ZodString; billingLastName: z.ZodString; billingPhone: z.ZodOptional<z.ZodString>; billingAddressLine1: z.ZodString; billingAddressLine2: z.ZodOptional<z.ZodString>; billingAddressLine3: z.ZodOptional<z.ZodString>; billingAdminArea4: z.ZodOptional<z.ZodString>; billingAdminArea3: z.ZodOptional<z.ZodString>; billingAdminArea2: z.ZodString; billingAdminArea1: z.ZodString; billingPostalCode: z.ZodString; billingCountryCode: z.ZodString; billingValid: z.ZodLiteral<true>; paymentCardNumber: z.ZodOptional<z.ZodString>; paymentCardNumberDisplay: z.ZodOptional<z.ZodString>; paymentCardType: z.ZodOptional<z.ZodString>; paymentExpiryDate: z.ZodOptional<z.ZodString>; paymentMonth: z.ZodOptional<z.ZodNullable<z.ZodString>>; paymentYear: z.ZodOptional<z.ZodNullable<z.ZodString>>; paymentSecurityCode: z.ZodOptional<z.ZodString>; paymentNameOnCard: z.ZodOptional<z.ZodString>; notes: z.ZodOptional<z.ZodString>; pickupDate: z.ZodOptional<z.ZodNullable<z.ZodUnion<[z.ZodString, z.ZodDate]>>>; pickupTime: z.ZodOptional<z.ZodNullable<z.ZodString>>; pickupLocationId: z.ZodOptional<z.ZodNullable<z.ZodString>>; pickupLeadTime: z.ZodOptional<z.ZodNullable<z.ZodNumber>>; pickupTimezone: z.ZodOptional<z.ZodNullable<z.ZodString>>; tipAmount: z.ZodOptional<z.ZodNumber>; tipPercentage: z.ZodOptional<z.ZodNumber>; paymentMethod: z.ZodString; stripePaymentIntent: z.ZodOptional<z.ZodString>; stripePaymentIntentId: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { paymentMethod: string; contactEmail: string; deliveryMethod: DeliveryMethods; paymentUseShippingAddress: boolean; shippingFirstName: string; shippingLastName: string; shippingAddressLine1: string; shippingAdminArea2: string; shippingAdminArea1: string; shippingPostalCode: string; shippingCountryCode: string; shippingValid: true; billingFirstName: string; billingLastName: string; billingAddressLine1: string; billingAdminArea2: string; billingAdminArea1: string; billingPostalCode: string; billingCountryCode: string; billingValid: true; notes?: string | undefined; shippingPhone?: string | undefined; shippingAddressLine2?: string | undefined; shippingAddressLine3?: string | undefined; shippingAdminArea4?: string | undefined; shippingAdminArea3?: string | undefined; shippingMethod?: string | undefined; billingPhone?: string | undefined; billingAddressLine2?: string | undefined; billingAddressLine3?: string | undefined; billingAdminArea4?: string | undefined; billingAdminArea3?: string | undefined; paymentCardNumber?: string | undefined; paymentCardNumberDisplay?: string | undefined; paymentCardType?: string | undefined; paymentExpiryDate?: string | undefined; paymentMonth?: string | null | undefined; paymentYear?: string | null | undefined; paymentSecurityCode?: string | undefined; paymentNameOnCard?: string | undefined; pickupDate?: string | Date | null | undefined; pickupTime?: string | null | undefined; pickupLocationId?: string | null | undefined; pickupLeadTime?: number | null | undefined; pickupTimezone?: string | null | undefined; tipAmount?: number | undefined; tipPercentage?: number | undefined; stripePaymentIntent?: string | undefined; stripePaymentIntentId?: string | undefined; }, { paymentMethod: string; contactEmail: string; deliveryMethod: DeliveryMethods; shippingFirstName: string; shippingLastName: string; shippingAddressLine1: string; shippingAdminArea2: string; shippingAdminArea1: string; shippingPostalCode: string; shippingCountryCode: string; shippingValid: true; billingFirstName: string; billingLastName: string; billingAddressLine1: string; billingAdminArea2: string; billingAdminArea1: string; billingPostalCode: string; billingCountryCode: string; billingValid: true; notes?: string | undefined; paymentUseShippingAddress?: boolean | undefined; shippingPhone?: string | undefined; shippingAddressLine2?: string | undefined; shippingAddressLine3?: string | undefined; shippingAdminArea4?: string | undefined; shippingAdminArea3?: string | undefined; shippingMethod?: string | undefined; billingPhone?: string | undefined; billingAddressLine2?: string | undefined; billingAddressLine3?: string | undefined; billingAdminArea4?: string | undefined; billingAdminArea3?: string | undefined; paymentCardNumber?: string | undefined; paymentCardNumberDisplay?: string | undefined; paymentCardType?: string | undefined; paymentExpiryDate?: string | undefined; paymentMonth?: string | null | undefined; paymentYear?: string | null | undefined; paymentSecurityCode?: string | undefined; paymentNameOnCard?: string | undefined; pickupDate?: string | Date | null | undefined; pickupTime?: string | null | undefined; pickupLocationId?: string | null | undefined; pickupLeadTime?: number | null | undefined; pickupTimezone?: string | null | undefined; tipAmount?: number | undefined; tipPercentage?: number | undefined; stripePaymentIntent?: string | undefined; stripePaymentIntentId?: string | undefined; }>; type CheckoutFormSchema = Partial<{ [K in keyof z.infer<typeof baseCheckoutSchema>]: z.ZodTypeAny }> & z.ZodRawShape; type CheckoutFormData = z.infer<typeof baseCheckoutSchema>; interface CheckoutProps { session?: CheckoutSession | undefined; appearance?: Appearance; isCheckoutDisabled?: boolean; stripeConfig?: StripeConfig; godaddyPaymentsConfig?: GodaddyPaymentsConfig; squareConfig?: SquareConfig; paypalConfig?: PayPalConfig; mercadoPagoConfig?: MercadoPagoConfig; ccavenueConfig?: CCAvenueConfig; layout?: LayoutSection[]; direction?: 'ltr' | 'rtl'; showStoreHours?: boolean; enableTracking?: boolean; trackingProperties?: TrackingProperties; targets?: Partial<Record<Target, () => ReactNode>>; checkoutFormSchema?: CheckoutFormSchema; defaultValues?: Pick<CheckoutFormData, 'contactEmail'>; } declare function Checkout(props: CheckoutProps): react_jsx_runtime11.JSX.Element; //#endregion //#region src/components/checkout/express-checkout/express-checkout.d.ts interface ExpressCheckoutAppearance { theme?: Theme; elements?: CheckoutElements; variables?: Omit<GoDaddyVariables, 'checkout'>; } interface ExpressCheckoutProps { session: CheckoutSession | undefined; appearance?: ExpressCheckoutAppearance; stripeConfig?: CheckoutProps['stripeConfig']; godaddyPaymentsConfig?: CheckoutProps['godaddyPaymentsConfig']; squareConfig?: CheckoutProps['squareConfig']; paypalConfig?: CheckoutProps['paypalConfig']; direction?: 'ltr' | 'rtl'; enableTracking?: boolean; targets?: Partial<Record<string, () => ReactNode>>; } declare function DraftOrderExpressCheckout(props: ExpressCheckoutProps): react_jsx_runtime11.JSX.Element | null; //#endregion //#region src/components/checkout/line-items/line-items.d.ts interface Note { content: string | null; id: string | null; } interface CostAdjustment { currencyCode?: string; value?: number; } interface AddonValue { amountIncreased?: number; costAdjustment?: CostAdjustment; name?: string; } interface SelectedAddon { attribute?: string; sku?: string; values?: AddonValue[]; } interface SelectedOption { attribute?: string; values?: string[]; } type ProductDiscount = { amount: { currencyCode: string; value: number; }; code: string; name: string; ratePercentage: string | null; }; type Product = Partial<SKUProduct> & { image: string; quantity: number; originalPrice: number; price: number; notes?: Note[] | null; addons?: SelectedAddon[]; selectedOptions?: SelectedOption[]; discounts?: ProductDiscount[]; }; interface DraftOrderLineItemsProps { items: Product[]; currencyCode?: string; inputInMinorUnits?: boolean; onRemoveFromCart?: (itemId: string) => void; isRemovingFromCart?: boolean; removingItemId?: string; } declare function DraftOrderLineItems({ items, currencyCode, inputInMinorUnits, onRemoveFromCart, isRemovingFromCart, removingItemId }: DraftOrderLineItemsProps): react_jsx_runtime11.JSX.Element; //#endregion //#region src/components/checkout/payment/utils/use-is-payment-disabled.d.ts declare function useIsPaymentDisabled(): boolean; //#endregion //#region src/components/checkout/totals/totals.d.ts interface DraftOrderTotalsProps { subtotal?: number; discount?: number; isDiscountLoading?: boolean; shipping?: number; isShippingLoading?: boolean; totalSavings?: number; currencyCode?: string; itemCount?: number; total?: number; tip?: number; taxes?: number; isTaxLoading?: boolean; enableTaxes?: boolean | null; enableDiscounts?: boolean | null; enableShipping?: boolean | null; inputInMinorUnits?: boolean; } declare function DraftOrderTotals({ subtotal, discount, shipping, currencyCode, itemCount, total, tip, taxes, enableDiscounts, enableTaxes, isTaxLoading, isShippingLoading, isDiscountLoading, enableShipping, inputInMinorUnits }: DraftOrderTotalsProps): react_jsx_runtime11.JSX.Element; //#endregion //#region src/components/storefront/cart.d.ts interface CartProps { open: boolean; onOpenChange: (open: boolean) => void; onCheckout?: (orderId: string) => void; isCheckingOut?: boolean; } declare function Cart({ open, onOpenChange, onCheckout, isCheckingOut }: CartProps): react_jsx_runtime11.JSX.Element; //#endregion //#region src/components/storefront/cart-line-items.d.ts declare function CartLineItems({ ...props }: DraftOrderLineItemsProps): react_jsx_runtime11.JSX.Element; //#endregion //#region src/components/storefront/cart-totals.d.ts declare function CartTotals({ ...props }: Omit<DraftOrderTotalsProps, 'enableDiscounts'>): react_jsx_runtime11.JSX.Element; //#endregion //#region src/components/storefront/product-card.d.ts interface ProductCardProps { product?: SKUGroup; productId?: string; storeId?: string; clientId?: string; href?: string; getProductHref?: (productId: string) => string; onAddToCartSuccess?: () => void; onAddToCartError?: (error: Error) => void; } declare function ProductCard({ product: productProp, productId, storeId: storeIdProp, clientId: clientIdProp, href: hrefProp, getProductHref, onAddToCartSuccess, onAddToCartError }: ProductCardProps): react_jsx_runtime11.JSX.Element; //#endregion //#region src/components/storefront/product-details.d.ts interface ProductDetailsProps { productId: string; storeId?: string; clientId?: string; onAddToCartSuccess?: () => void; onAddToCartError?: (error: Error) => void; } declare function ProductDetails({ productId, storeId: storeIdProp, clientId: clientIdProp, onAddToCartSuccess, onAddToCartError }: ProductDetailsProps): react_jsx_runtime11.JSX.Element; //#endregion //#region src/components/storefront/product-grid.d.ts interface ProductGridProps { storeId?: string; clientId?: string; /** Filter products by specific product IDs */ productIds?: string[]; /** Filter products by category IDs (maps to listId in GraphQL) */ categoryIds?: string[]; enablePagination?: boolean; getProductHref?: (productId: string) => string; onAddToCartSuccess?: () => void; onAddToCartError?: (error: Error) => void; } declare function ProductGrid({ storeId: storeIdProp, clientId: clientIdProp, productIds, categoryIds, enablePagination, getProductHref, onAddToCartSuccess, onAddToCartError }: ProductGridProps): react_jsx_runtime11.JSX.Element; //#endregion //#region src/components/storefront/product-search.d.ts interface ProductSearchProps { showButton?: boolean; onSearch?: (query: string) => void; } declare function ProductSearch({ showButton, onSearch }: ProductSearchProps): react_jsx_runtime11.JSX.Element; //#endregion export { $Values, AddCartOrderInput, AddLineItemBySkuIdInput, Address, ApplyCheckoutSessionDeliveryMethodInput, ApplyCheckoutSessionDiscountInput, ApplyCheckoutSessionFulfillmentLocationInput, ApplyCheckoutSessionShippingMethodInput, ApplyDiscountCodesInput, AuthorizeCheckoutSessionInput, AvailablePaymentProviders, CCAvenueConfig, CSSVariables, CalculateCheckoutSessionTaxesInput, CalculatedAdjustments, CalculatedTaxes, Cart, CartDiscount, CartLineItem, CartLineItemDetails, CartLineItemTotals, CartLineItems, CartNote, CartOrder, CartOrderTotals, CartShippingInfo, CartTax, CartTotals, Checkout, CheckoutElements, CheckoutFormData, CheckoutFormSchema, CheckoutProps, CheckoutSession, CheckoutSessionInput, CheckoutSessionLocation, CheckoutSessionOptions, CheckoutSessionResult, CheckoutType, ConfirmCheckoutMutationInput, DeleteLineItemByIdInput, DraftOrder, DraftOrderExpressCheckout, DraftOrderLineItems, type DraftOrderLineItemsProps, DraftOrderPriceAdjustmentsQueryInput, DraftOrderSession, DraftOrderTotals, type DraftOrderTotalsProps, type ExpressCheckoutProps, GetCheckoutSessionShippingRatesInput, GetCheckoutSessionTaxesInput, GoDaddyAppearance, GoDaddyProvider, GoDaddyProviderProps, GoDaddyTheme, GoDaddyVariables, GodaddyPaymentsConfig, LayoutSection, LayoutSections, LinkComponentProps, MercadoPagoConfig, MutationVerifyAddress, PayPalConfig, PaymentMethodConfig, PaymentMethodKey, PaymentMethodType, PaymentMethodValue, PaymentMethods, PaymentProvider, type Product, ProductCard, type ProductCardProps, ProductDetails, type ProductDetailsProps, ProductGrid, ProductSearch, type ProductSearchProps, RemoveAppliedCheckoutSessionShippingMethodInput, SKU, SKUAttributeValue, SKUGroup, SKUGroupAttribute, SKUGroupAttributeValue, SKUGroupSKU, SKUInventoryCount, SKUMedia, SKUPrice, SKUProduct, ShippingLines, ShippingMethod, SkuGroupInput, SkuGroupsInput, SkuInput, SquareConfig, StoreHours, StripeConfig, Totals, UpdateCartOrderInput, UpdateDraftOrderInput, UpdateLineItemByIdInput, baseCheckoutSchema, checkoutContext, queryClient, redirectToSuccessUrl, useCheckoutContext, useGoDaddyContext, useIsPaymentDisabled };