Skip to content

useOrderPayment ​

Definition ​

Composable for managing an existing order.

Basic usage ​

ts
const { 
 isAsynchronous,
 activeTransaction,
 state,
 paymentUrl,
 paymentMethod,
 handlePayment,
 changePaymentMethod 
} = useOrderPayment(order);

Signature ​

ts
export function useOrderPayment(
  order: ComputedRef<Schemas["Order"] | null | undefined>,
): UseOrderPaymentReturn 

Parameters ​

NameTypeDescription
order
ComputedRef< |  | undefined>

Return type ​

See UseOrderPaymentReturn
ts
export type UseOrderPaymentReturn = {
  /**
   * If the payment can be done after the order is placed
   */
  isAsynchronous: ComputedRef<boolean | undefined>;
  /**
   * Active payment transaction
   */
  activeTransaction: ComputedRef<Schemas["OrderTransaction"] | undefined>;
  /**
   * Payment status
   */
  state: ComputedRef<Schemas["StateMachineState"] | null | undefined>;
  paymentUrl: Ref<null | string>;
  /**
   * Payment method set for the order
   */
  paymentMethod: ComputedRef<Schemas["PaymentMethod"] | undefined | null>;

  /**
   * Invokes the payment process for the order in the backend
   */
  handlePayment(
    /**
     * URL to redirect after successful payment
     */
    successUrl?: string,
    /**
     * URL to redirect after failed payment
     */
    errorUrl?: string,
    /**
     * additional payment details to provide
     */
    paymentDetails?: unknown,
  ): Promise<void | unknown>;
  /**
   * Change a payment method for the order
   */
  changePaymentMethod(paymentMethodId: string): Promise<void>;
};

Properties ​

NameTypeDescription
isAsynchronous
ComputedRef<boolean | undefined>
If the payment can be done after the order is placed
activeTransaction
ComputedRef< | undefined>
Active payment transaction
state
ComputedRef< |  | undefined>
Payment status
paymentUrl
Ref< | string>
paymentMethod
ComputedRef< | undefined | null>
Payment method set for the order

Methods ​

NameTypeDescription
handlePayment
Promise<void | null>
Invokes the payment process for the order in the backend
changePaymentMethod
Promise<void>
Change a payment method for the order

Usage ​

vue
<script setup lang="ts">
// TODO: add example
</script>
useOrderPayment has loaded