updateOrder
Method to change an order's status and/or assign custom attributes to it.
This method communicates with the updateOrder endpoint of the Vue Storefront API Middleware. In turn, it receives data from the Update order endpoints exposed by SCAPI / OCAPI depending on the middleware configuration.
If the order status is being set to 'new' or 'open', this will trigger an order place flow.
If there is an existing payment instrument in the order, and it is not a card (does not have the paymentCard field), it will be patched with its own body, in order to trigger the dw.order.payment.authorize hook.
If there is an existing payment instrument in the order, and it is a card (has the paymentCard field), it will be deleted and re-added with the same body, in order to trigger the dw.order.payment.authorizeCreditCard hook. It cannot just be patched like non-card payments, because if the card has already been added to the basket, it is considered permanently masked and such operations fail.
If there is no existing payment instrument, a new one must be provided in the request parameters, following the same rules as the addPaymentInstrumentToBasket method.
Further documentation is provided in the API Explorer
Multiple payment instruments are currently not supported.
Signature
export declare function updateOrder(
props: OrderUpdateParams
): Promise<import("commerce-sdk/dist/checkout/checkout").ShopperOrders.Order>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
props | Required | OrderUpdateParams | Parameter object which can be used with this method. Refer to its type definition to learn about possible properties. |
Returns
Returns the updated order.
Referenced Types
OrderUpdateParamsShopperOrders.Order
Examples
Failing an order by orderNo.
import { sdk } from '~/sdk.config.ts';
const order = await sdk.commerce.updateOrder({
status: 'failed',
order: {
orderNo: '123456',
},
});Updating the custom attribute of an order by orderNo.
import { sdk } from '~/sdk.config.ts';
const order = await sdk.commerce.updateOrder({
c_firstAttr: 'attrValue',
order: {
orderNo: '123456',
},
});Placing an order with an existing payment instrument by orderNo.
import { sdk } from '~/sdk.config.ts';
const order = await sdk.commerce.updateOrder({
status: 'new',
order: {
orderNo: '123456',
},
});Placing an order with a new payment instrument by orderNo.
import { sdk } from '~/sdk.config.ts';
const order = await sdk.commerce.updateOrder({
status: 'new',
order: {
orderNo: '123456',
},
paymentInstrument: {
amount: 100,
paymentMethodId: 'CUSTOM_PAYMENT',
},
});Placing an order with a new payment card by orderNo.
import { sdk } from '~/sdk.config.ts';
const order = await sdk.commerce.updateOrder({
status: 'new',
order: {
orderNo: '123456',
},
paymentInstrument: {
amount: 100,
paymentMethodId: 'CREDIT_CARD',
paymentCard: {
cardType: 'Visa',
creditCardToken: 'creditCardToken',
expirationMonth: 3,
expirationYear: 2030,
holder: 'Test1 User1',
maskedNumber: '************1111',
numberLastDigits: '1111',
},
},
});