cancelOrder
Cancels partial payments.
It communicates with the cancelOrder endpoint of the Vue Storefront API Middleware. In turn, it calls the POST /orders/cancel Adyen endpoint directly and returns received response.
Signature
export declare function cancelOrder(
props: CancelOrderParams,
options?: MethodOptions
): Promise<import("@adyen/api-library/lib/src/typings/checkout/cancelOrderResponse").CancelOrderResponse>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
props | Required | CancelOrderParams | Parameter object which can be used with this method. Refer to its type definition to learn about possible properties. |
options | Optional | MethodOptions | Options that can be passed to additionally configure the request or customize the logic in a plugin. |
Returns
Returns Promise<CancelOrderResponse>
Referenced Types
CancelOrderParams- MethodOptions
CancelOrderResponse
Examples
Cancels partial payments. Cancellation of an order results in an automatic rollback of all payments made in the order, either by canceling or refunding the payment, depending on the type of payment method. For full context, check the Alokai's documentation.
import { sdk } from '~/sdk.config.ts';
function mapPaymentMethodsResponse(getPaymentMethodsResponse: GetPaymentMethodsResponse) {
return {
paymentMethods: getPaymentMethodsResponse.paymentMethods,
...(getPaymentMethodsResponse.storedPaymentMethods
? {
storedPaymentMethods: getPaymentMethodsResponse.storedPaymentMethods,
}
: {}),
};
}
function createOnOrderCancel(checkout: { update: Function }) {
return async function onOrderCancel(order: CancelOrderParams) {
await sdk.adyen.cancelOrder(order);
getPaymentMethodsResponse = await sdk.adyen.getPaymentMethods();
checkout.update({
paymentMethodsResponse: mapPaymentMethodsResponse(getPaymentMethodsResponse),
amount: {
value: getPaymentMethodsResponse.payment.amountPlanned.centAmount,
currency: getPaymentMethodsResponse.payment.amountPlanned.currencyCode,
},
order: undefined,
});
};
}
// ... Inside adyenConfiguration.giftcard and dropinConfiguration properties passed in object to the mountPaymentElement SDK method call
async onOrderCancel(order) {
const onOrderCancel = createOnOrderCancel(checkout);
await onOrderCancel(order);
},
// ...