Skip to content
On this page

useOrderDetails ​

Definition ​

Composable for managing an existing order.

Basic usage ​

ts
const { 
 order,
 status,
 statusTechnicalName,
 total,
 subtotal,
 shippingCosts,
 shippingAddress,
 billingAddress,
 personalDetails,
 paymentUrl,
 shippingMethod,
 paymentMethod,
 getMediaFile,
 getDocumentFile,
 hasDocuments,
 documents,
 paymentChangeable,
 loadOrderDetails,
 handlePayment,
 cancel,
 changePaymentMethod,
 getPaymentMethods 
} = useOrderDetails(orderId, associations);

Signature ​

ts
export function useOrderDetails(
  orderId: string,
  associations?: Schemas["Criteria"]["associations"],
): UseOrderDetailsReturn 

Parameters ​

NameTypeDescription
orderId
string
associations

Return type ​

See UseOrderDetailsReturn
ts
export type UseOrderDetailsReturn = {
  /**
   * {@link Schemas['Order']} object
   */
  order: ComputedRef<Schemas["Order"] | undefined | null>;
  /**
   * Order status (e.g. 'Open', 'Cancelled')
   */
  status: ComputedRef<string | undefined>;
  /**
   * Order status technical name (e.g. 'open', 'cancelled')
   */
  statusTechnicalName: ComputedRef<string | undefined>;
  /**
   * Order total price
   */
  total: ComputedRef<number | undefined>;
  /**
   * Order subtotal price for all items
   */
  subtotal: ComputedRef<number | undefined>;
  /**
   * Order shipping costs
   */
  shippingCosts: ComputedRef<number | undefined>;
  /**
   * Shipping address
   */
  shippingAddress: ComputedRef<Schemas["OrderAddress"] | undefined>;
  /**
   * Billing address
   */
  billingAddress: ComputedRef<Schemas["OrderAddress"] | undefined>;
  /**
   * Basic personal details
   */
  personalDetails: ComputedRef<{
    email: string | undefined;
    firstName: string | undefined;
    lastName: string | undefined;
  }>;
  /**
   * Payment URL for external payment methods (e.g. async payment in external payment gateway)
   */
  paymentUrl: Ref<null | string>;
  /**
   * Selected shipping method
   */
  shippingMethod: ComputedRef<Schemas["ShippingMethod"] | undefined | null>;
  /**
   * Selected payment method
   */
  paymentMethod: ComputedRef<Schemas["PaymentMethod"] | undefined | null>;
  /**
   * Get order object including additional associations.
   * useDefaults describes what order object should look like.
   */
  loadOrderDetails(): Promise<void>;
  /**
   * Handle payment for existing error.
   *
   * Pass custom success and error URLs (optionally).
   */
  handlePayment(
    successUrl?: string,
    errorUrl?: string,
    paymentDetails?: unknown,
  ): void;
  /**
   * Cancel an order.
   *
   * Action cannot be reverted.
   */
  cancel(): Promise<void>;
  /**
   * Changes the payment method for current cart.
   * @param paymentMethodId - ID of the payment method to be set
   * @returns
   */
  changePaymentMethod(paymentMethodId: string): Promise<void>;
  /**
   * Get media content
   *
   * @param {string} downloadId
   * @returns {Blob}
   */
  getMediaFile: (downloadId: string) => Promise<Blob>;
  /**
   * Get order documents
   * @param {string} documentId
   * @param {string} deepLinkCode
   * @returns
   */
  getDocumentFile: (
    documentId: string,
    deepLinkCode: string,
  ) => Promise<Schemas["Document"]>;
  /**
   * Check if order has documents
   */
  hasDocuments: ComputedRef<boolean>;
  /**
   * Get order documents
   */
  documents: ComputedRef<Schemas["Document"][]>;
  /**
   * Fetches all available payment methods
   */
  getPaymentMethods(): Promise<Schemas["PaymentMethod"][]>;

  paymentChangeable: ComputedRef<boolean>;
};

Properties ​

NameTypeDescription
order
ComputedRef< | undefined | null>
{@link Schemas['Order']} object
status
ComputedRef<string | undefined>
Order status (e.g. 'Open', 'Cancelled')
statusTechnicalName
ComputedRef<string | undefined>
Order status technical name (e.g. 'open', 'cancelled')
total
ComputedRef<number | undefined>
Order total price
subtotal
ComputedRef<number | undefined>
Order subtotal price for all items
shippingCosts
ComputedRef<number | undefined>
Order shipping costs
shippingAddress
ComputedRef< | undefined>
Shipping address
billingAddress
ComputedRef< | undefined>
Billing address
personalDetails
ComputedRef<{
    email: string | undefined;
    firstName: string | undefined;
    lastName: string | undefined;
  }>
Basic personal details
paymentUrl
Ref< | string>
Payment URL for external payment methods (e.g. async payment in external payment gateway)
shippingMethod
ComputedRef< | undefined | null>
Selected shipping method
paymentMethod
ComputedRef< | undefined | null>
Selected payment method
getMediaFile
(downloadId: string) => Promise<Blob>
Get media content
getDocumentFile
(
    documentId: string,
    deepLinkCode: string,
  ) => Promise<Schemas["Document"]>
Get order documents
hasDocuments
ComputedRef<boolean>
Check if order has documents
documents
ComputedRef<Array<>>
Get order documents
paymentChangeable
ComputedRef<boolean>

Methods ​

NameTypeDescription
loadOrderDetails
Promise<void>
Get order object including additional associations.useDefaults describes what order object should look like.
handlePayment
void
Handle payment for existing error.Pass custom success and error URLs (optionally).
cancel
Promise<void>
Cancel an order.Action cannot be reverted.
changePaymentMethod
Promise<void>
Changes the payment method for current cart.
getPaymentMethods
Promise<Array<>>
Fetches all available payment methods
useOrderDetails has loaded