Skip to content

Commit

Permalink
fix: cancel order
Browse files Browse the repository at this point in the history
  • Loading branch information
soutofernando authored and vitoUwu committed Jan 9, 2025
1 parent cf0e317 commit 901b2c1
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 13 deletions.
4 changes: 2 additions & 2 deletions vtex/actions/orders/cancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function action(
req: Request,
ctx: AppContext,
): Promise<CanceledOrder | null> {
const { vcsDeprecated } = ctx;
const { vcs } = ctx;
const { cookie, payload } = parseCookie(req.headers, ctx.account);

if (!payload?.sub || !payload?.userId) {
Expand All @@ -22,7 +22,7 @@ async function action(

const { orderId, reason, requestedByUser } = props;

const response = await vcsDeprecated
const response = await vcs
["POST /api/oms/pvt/orders/:orderId/cancel"](
{ orderId },
{
Expand Down
8 changes: 0 additions & 8 deletions vtex/utils/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Userorderslist } from "./openapi/vcs.openapi.gen.ts";
import {
Brand,
CanceledOrder,
Category,
CreateNewDocument,
FacetSearchResult,
Expand Down Expand Up @@ -257,13 +256,6 @@ export interface VTEXCommerceStable {
"GET /api/oms/user/orders/:orderId": {
response: OrderItem;
};
"POST /api/oms/pvt/orders/:orderId/cancel": {
response: CanceledOrder;
body: {
reason: string;
requestedByUser: boolean;
};
};
}

export interface SP {
Expand Down
64 changes: 64 additions & 0 deletions vtex/utils/openapi/vcs.openapi.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17104,6 +17104,70 @@ ascending?: boolean
}
}
}
/**
* Cancels an order using its identification code (`orderId`). A common scenario is when the seller has a problem fulfilling the order and requests the marketplace to cancel it.
*
* ## Orders that cannot be canceled
*
* The following situations do not allow order cancellation:
*
* - **Partial invoices:** [Partially invoiced](https://help.vtex.com/en/tracks/orders--2xkTisx4SXOWXQel8Jg8sa/q9GPspTb9cHlMeAZfdEUe) orders cannot be canceled. However, the customer can [change the order](https://developers.vtex.com/docs/guides/change-order) to replace or remove items from it.
*
* - **Invoiced status:** Orders with `invoiced` [status](https://help.vtex.com/en/tutorial/order-flow-and-status--tutorials_196) cannot be canceled. If the order has already been invoiced, you can use the [Order invoice notification](https://developers.vtex.com/docs/api-reference/orders-api#post-/api/oms/pvt/orders/-orderId-/invoice) endpoint to generate a return invoice.
*
* - **Incomplete orders:** [Incomplete orders](https://help.vtex.com/en/tutorial/how-incomplete-orders-work--tutorials_294) cannot be canceled.
*
* ## Declining order cancelation
*
* The order flow has a cancellation window (grace period) in which the customer can automatically cancel the order. Except for that period, the seller can [decline an order cancellation request](https://help.vtex.com/en/tutorial/declining-order-cancelation--F2n0h1TeQ5td540Gjyff4), regardless of whether the customer or the marketplace initiated it.
*
* For more information, see [Order canceling improvements](https://developers.vtex.com/docs/guides/order-canceling-improvements).
*
* ## Permissions
*
* Any user or [application key](https://developers.vtex.com/docs/guides/api-authentication-using-application-keys) must have at least one of the appropriate [License Manager resources](https://help.vtex.com/en/tutorial/license-manager-resources--3q6ztrC8YynQf6rdc6euk3) to be able to successfully run this request. Otherwise they will receive a status code `403` error. These are the applicable resources for this endpoint:
*
* | **Product** | **Category** | **Resource** |
* | --------------- | ----------------- | ----------------- |
* | OMS | OMS access | **Cancel order** |
*
* You can [create a custom role](https://help.vtex.com/en/tutorial/roles--7HKK5Uau2H6wxE1rH5oRbc#creating-a-role) with that resource or use one of the following [predefined roles](https://help.vtex.com/en/tutorial/predefined-roles--jGDurZKJHvHJS13LnO7Dy):
*
* | **Role** | **Resource** |
* | --------------- | ----------------- |
* | OMS - Full access | Cancel order |
* | IntegrationProfile - Fulfillment Oms | Cancel order |
*
* >❗ Assigning a [predefined role](https://help.vtex.com/en/tutorial/predefined-roles--jGDurZKJHvHJS13LnO7Dy) to users or application keys usually grants permission to multiple [License Manager resources](https://help.vtex.com/en/tutorial/license-manager-resources--3q6ztrC8YynQf6rdc6euk3). If some of these permissions are not necessary, consider creating a custom role instead. For more information regarding security, see [Best practices for using application keys](https://help.vtex.com/en/tutorial/best-practices-application-keys--7b6nD1VMHa49aI5brlOvJm).
*
* To learn more about machine authentication at VTEX, see [Authentication overview](https://developers.vtex.com/docs/guides/authentication).
*/
"POST /api/oms/pvt/orders/:orderId/cancel": {
body: {
/**
* Reason for cancelling the order.
*/
reason?: string
/**
* If requested by the user
*/
requestedByUser?: boolean
}
response: {
/**
* Date and time when the notification was received.
*/
date?: string
/**
* Identification of the order in the seller.
*/
orderId?: string
/**
* Protocol code generated by the update. It may be `null`.
*/
receipt?: string
}
}
/**
* Retrieves information on pickup points close to a given location determined by geocoordinates or postal code.
*
Expand Down
107 changes: 107 additions & 0 deletions vtex/utils/openapi/vcs.openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -34061,6 +34061,113 @@
"deprecated": false
}
},
"/api/oms/pvt/orders/{orderId}/cancel": {
"post": {
"tags": [
"Orders"
],
"summary": "Cancel order",
"description": "Cancels an order using its identification code (`orderId`). A common scenario is when the seller has a problem fulfilling the order and requests the marketplace to cancel it. \r\n\r\n## Orders that cannot be canceled \r\n\r\nThe following situations do not allow order cancellation: \r\n\r\n- **Partial invoices:** [Partially invoiced](https://help.vtex.com/en/tracks/orders--2xkTisx4SXOWXQel8Jg8sa/q9GPspTb9cHlMeAZfdEUe) orders cannot be canceled. However, the customer can [change the order](https://developers.vtex.com/docs/guides/change-order) to replace or remove items from it. \r\n\r\n- **Invoiced status:** Orders with `invoiced` [status](https://help.vtex.com/en/tutorial/order-flow-and-status--tutorials_196) cannot be canceled. If the order has already been invoiced, you can use the [Order invoice notification](https://developers.vtex.com/docs/api-reference/orders-api#post-/api/oms/pvt/orders/-orderId-/invoice) endpoint to generate a return invoice. \r\n\r\n- **Incomplete orders:** [Incomplete orders](https://help.vtex.com/en/tutorial/how-incomplete-orders-work--tutorials_294) cannot be canceled. \r\n\r\n## Declining order cancelation \r\n\r\nThe order flow has a cancellation window (grace period) in which the customer can automatically cancel the order. Except for that period, the seller can [decline an order cancellation request](https://help.vtex.com/en/tutorial/declining-order-cancelation--F2n0h1TeQ5td540Gjyff4), regardless of whether the customer or the marketplace initiated it. \r\n\r\nFor more information, see [Order canceling improvements](https://developers.vtex.com/docs/guides/order-canceling-improvements). \r\n\r\n## Permissions\r\n\r\nAny user or [application key](https://developers.vtex.com/docs/guides/api-authentication-using-application-keys) must have at least one of the appropriate [License Manager resources](https://help.vtex.com/en/tutorial/license-manager-resources--3q6ztrC8YynQf6rdc6euk3) to be able to successfully run this request. Otherwise they will receive a status code `403` error. These are the applicable resources for this endpoint:\r\n\r\n| **Product** | **Category** | **Resource** |\r\n| --------------- | ----------------- | ----------------- |\r\n| OMS | OMS access | **Cancel order** | \r\n\r\nYou can [create a custom role](https://help.vtex.com/en/tutorial/roles--7HKK5Uau2H6wxE1rH5oRbc#creating-a-role) with that resource or use one of the following [predefined roles](https://help.vtex.com/en/tutorial/predefined-roles--jGDurZKJHvHJS13LnO7Dy):\r\n\r\n| **Role** | **Resource** | \r\n| --------------- | ----------------- | \r\n| OMS - Full access | Cancel order |\r\n| IntegrationProfile - Fulfillment Oms | Cancel order |\r\n\r\n>❗ Assigning a [predefined role](https://help.vtex.com/en/tutorial/predefined-roles--jGDurZKJHvHJS13LnO7Dy) to users or application keys usually grants permission to multiple [License Manager resources](https://help.vtex.com/en/tutorial/license-manager-resources--3q6ztrC8YynQf6rdc6euk3). If some of these permissions are not necessary, consider creating a custom role instead. For more information regarding security, see [Best practices for using application keys](https://help.vtex.com/en/tutorial/best-practices-application-keys--7b6nD1VMHa49aI5brlOvJm). \r\n\r\nTo learn more about machine authentication at VTEX, see [Authentication overview](https://developers.vtex.com/docs/guides/authentication).",
"operationId": "CancelOrder",
"parameters": [
{
"name": "Accept",
"in": "header",
"description": "HTTP Client Negotiation _Accept_ Header. Indicates the types of responses the client can understand.",
"required": true,
"style": "simple",
"schema": {
"type": "string",
"default": "application/json"
}
},
{
"name": "Content-Type",
"in": "header",
"description": "Describes the type of the content being sent.",
"required": true,
"style": "simple",
"schema": {
"type": "string",
"default": "application/json"
}
},
{
"name": "orderId",
"in": "path",
"description": "ID that identifies the order in the seller.",
"example": "1172452900788-01",
"required": true,
"style": "simple",
"schema": {
"type": "string",
"example": "1172452900788-01"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"description": "Reason for cancelling the order.",
"example": "Unexpected stock shortage"
},
"requestedByUser": {
"type": "boolean",
"description": "If requested by the user",
"example": "User canceled the order "
}
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"date": {
"type": "string",
"description": "Date and time when the notification was received."
},
"orderId": {
"type": "string",
"description": "Identification of the order in the seller."
},
"receipt": {
"type": "string",
"description": "Protocol code generated by the update. It may be `null`."
}
}
},
"example": {
"date": "2024-02-07T15:22:56.7612218-02:00",
"orderId": "123543123",
"receipt": "38e0e47da2934847b489216d208cfd91"
}
}
}
},
"429": {
"description": "Too many requests."
},
"403": {
"description": "The credentials are not enabled to access the service."
},
"404": {
"description": "Value not found."
}
}
}
},
"/api/checkout/pub/pickup-points": {
"get": {
"tags": [
Expand Down
6 changes: 3 additions & 3 deletions vtex/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1470,9 +1470,9 @@ export interface OrderItem {
}

export interface CanceledOrder {
date: string;
orderId: string;
receipt: string | null;
date?: string;
orderId?: string;
receipt?: string | null;
}

interface Marketplace {
Expand Down

0 comments on commit 901b2c1

Please sign in to comment.