Skip to content

useCheckout

Definition

Composable to manage checkout process

Basic usage

ts
const { 
 shippingMethods,
 paymentMethods,
 shippingAddress,
 billingAddress,
 selectedShippingMethod,
 selectedPaymentMethod,
 getShippingMethods,
 getPaymentMethods,
 createOrder,
 setShippingMethod,
 setPaymentMethod 
} = useCheckout();

Signature

ts
export function useCheckout(): UseCheckoutReturn 

Return type

See UseCheckoutReturn
ts
export type UseCheckoutReturn = {
  /**
   * Fetches all available shipping methods
   */
  getShippingMethods(options?: {
    forceReload: boolean;
  }): Promise<ComputedRef<ShippingMethod[]>>;
  /**
   * List of available shipping methods
   */
  shippingMethods: ComputedRef<ShippingMethod[]>;
  /**
   * Fetches all available payment methods
   */
  getPaymentMethods(options?: {
    forceReload: boolean;
  }): Promise<ComputedRef<PaymentMethod[]>>;
  /**
   * List of available payment methods
   */
  paymentMethods: ComputedRef<PaymentMethod[]>;
  /**
   * Creates order based on the current cart
   */
  createOrder(params?: CreateOrderParams): Promise<Order>;
  /**
   * Shipping address for the current session
   */
  shippingAddress: ComputedRef<ShippingAddress | undefined>;
  /**
   * Billing address for the current session
   */
  billingAddress: ComputedRef<Partial<BillingAddress> | undefined>;
  /**
   * Selected shipping method for the current session
   * Sugar for {@link useSessionContext.selectedShippingMethod}
   */
  selectedShippingMethod: ComputedRef<ShippingMethod | null>;
  /**
   * Sets shipping method for the current session
   * Sugar for {@link useSessionContext.setShippingMethod}
   */
  setShippingMethod(shippingMethod: Partial<ShippingMethod>): Promise<void>;
  /**
   * Selected payment method for the current session
   * Sugar for {@link useSessionContext.selectedPaymentMethod}
   */
  selectedPaymentMethod: ComputedRef<PaymentMethod | null>;
  /**
   * Sets payment method for the current session
   * Sugar for {@link useSessionContext.setPaymentMethod}
   */
  setPaymentMethod(paymentMethod: Partial<PaymentMethod>): Promise<void>;
};

Properties

NameTypeDescription
shippingMethods
ComputedRef<Array<ShippingMethod>>
List of available shipping methods
paymentMethods
ComputedRef<Array<PaymentMethod>>
List of available payment methods
shippingAddress
ComputedRef<ShippingAddress | undefined>
Shipping address for the current session
billingAddress
ComputedRef<Partial<BillingAddress> | undefined>
Billing address for the current session
selectedShippingMethod
ComputedRef<ShippingMethod | null>
Selected shipping method for the current sessionSugar for {@link useSessionContext.selectedShippingMethod}
selectedPaymentMethod
ComputedRef<PaymentMethod | null>
Selected payment method for the current sessionSugar for {@link useSessionContext.selectedPaymentMethod}

Methods

NameTypeDescription
getShippingMethods
Promise<ComputedRef<Array<ShippingMethod>>>
Fetches all available shipping methods
getPaymentMethods
Promise<ComputedRef<Array<PaymentMethod>>>
Fetches all available payment methods
createOrder
Promise<Order>
Creates order based on the current cart
setShippingMethod
Promise<void>
Sets shipping method for the current sessionSugar for {@link useSessionContext.setShippingMethod}
setPaymentMethod
Promise<void>
Sets payment method for the current sessionSugar for {@link useSessionContext.setPaymentMethod}

Live example

useCheckout has loaded