Skip to content

Commit 6f6b1bb

Browse files
soutofernandovitoUwu
authored andcommitted
fix: cancel order
1 parent 0b546eb commit 6f6b1bb

File tree

5 files changed

+176
-13
lines changed

5 files changed

+176
-13
lines changed

vtex/actions/orders/cancel.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async function action(
1313
req: Request,
1414
ctx: AppContext,
1515
): Promise<CanceledOrder | null> {
16-
const { vcsDeprecated } = ctx;
16+
const { vcs } = ctx;
1717
const { cookie, payload } = parseCookie(req.headers, ctx.account);
1818

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

2323
const { orderId, reason, requestedByUser } = props;
2424

25-
const response = await vcsDeprecated
25+
const response = await vcs
2626
["POST /api/oms/pvt/orders/:orderId/cancel"](
2727
{ orderId },
2828
{

vtex/utils/client.ts

-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Userorderslist } from "./openapi/vcs.openapi.gen.ts";
22
import {
33
Brand,
4-
CanceledOrder,
54
Category,
65
CreateNewDocument,
76
FacetSearchResult,
@@ -257,13 +256,6 @@ export interface VTEXCommerceStable {
257256
"GET /api/oms/user/orders/:orderId": {
258257
response: OrderItem;
259258
};
260-
"POST /api/oms/pvt/orders/:orderId/cancel": {
261-
response: CanceledOrder;
262-
body: {
263-
reason: string;
264-
requestedByUser: boolean;
265-
};
266-
};
267259
}
268260

269261
export interface SP {

vtex/utils/openapi/vcs.openapi.gen.ts

+64
Original file line numberDiff line numberDiff line change
@@ -17104,6 +17104,70 @@ ascending?: boolean
1710417104
}
1710517105
}
1710617106
}
17107+
/**
17108+
* 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.
17109+
*
17110+
* ## Orders that cannot be canceled
17111+
*
17112+
* The following situations do not allow order cancellation:
17113+
*
17114+
* - **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.
17115+
*
17116+
* - **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.
17117+
*
17118+
* - **Incomplete orders:** [Incomplete orders](https://help.vtex.com/en/tutorial/how-incomplete-orders-work--tutorials_294) cannot be canceled.
17119+
*
17120+
* ## Declining order cancelation
17121+
*
17122+
* 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.
17123+
*
17124+
* For more information, see [Order canceling improvements](https://developers.vtex.com/docs/guides/order-canceling-improvements).
17125+
*
17126+
* ## Permissions
17127+
*
17128+
* 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:
17129+
*
17130+
* | **Product** | **Category** | **Resource** |
17131+
* | --------------- | ----------------- | ----------------- |
17132+
* | OMS | OMS access | **Cancel order** |
17133+
*
17134+
* 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):
17135+
*
17136+
* | **Role** | **Resource** |
17137+
* | --------------- | ----------------- |
17138+
* | OMS - Full access | Cancel order |
17139+
* | IntegrationProfile - Fulfillment Oms | Cancel order |
17140+
*
17141+
* >❗ 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).
17142+
*
17143+
* To learn more about machine authentication at VTEX, see [Authentication overview](https://developers.vtex.com/docs/guides/authentication).
17144+
*/
17145+
"POST /api/oms/pvt/orders/:orderId/cancel": {
17146+
body: {
17147+
/**
17148+
* Reason for cancelling the order.
17149+
*/
17150+
reason?: string
17151+
/**
17152+
* If requested by the user
17153+
*/
17154+
requestedByUser?: boolean
17155+
}
17156+
response: {
17157+
/**
17158+
* Date and time when the notification was received.
17159+
*/
17160+
date?: string
17161+
/**
17162+
* Identification of the order in the seller.
17163+
*/
17164+
orderId?: string
17165+
/**
17166+
* Protocol code generated by the update. It may be `null`.
17167+
*/
17168+
receipt?: string
17169+
}
17170+
}
1710717171
/**
1710817172
* Retrieves information on pickup points close to a given location determined by geocoordinates or postal code.
1710917173
*

vtex/utils/openapi/vcs.openapi.json

+107
Original file line numberDiff line numberDiff line change
@@ -34061,6 +34061,113 @@
3406134061
"deprecated": false
3406234062
}
3406334063
},
34064+
"/api/oms/pvt/orders/{orderId}/cancel": {
34065+
"post": {
34066+
"tags": [
34067+
"Orders"
34068+
],
34069+
"summary": "Cancel order",
34070+
"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).",
34071+
"operationId": "CancelOrder",
34072+
"parameters": [
34073+
{
34074+
"name": "Accept",
34075+
"in": "header",
34076+
"description": "HTTP Client Negotiation _Accept_ Header. Indicates the types of responses the client can understand.",
34077+
"required": true,
34078+
"style": "simple",
34079+
"schema": {
34080+
"type": "string",
34081+
"default": "application/json"
34082+
}
34083+
},
34084+
{
34085+
"name": "Content-Type",
34086+
"in": "header",
34087+
"description": "Describes the type of the content being sent.",
34088+
"required": true,
34089+
"style": "simple",
34090+
"schema": {
34091+
"type": "string",
34092+
"default": "application/json"
34093+
}
34094+
},
34095+
{
34096+
"name": "orderId",
34097+
"in": "path",
34098+
"description": "ID that identifies the order in the seller.",
34099+
"example": "1172452900788-01",
34100+
"required": true,
34101+
"style": "simple",
34102+
"schema": {
34103+
"type": "string",
34104+
"example": "1172452900788-01"
34105+
}
34106+
}
34107+
],
34108+
"requestBody": {
34109+
"content": {
34110+
"application/json": {
34111+
"schema": {
34112+
"type": "object",
34113+
"properties": {
34114+
"reason": {
34115+
"type": "string",
34116+
"description": "Reason for cancelling the order.",
34117+
"example": "Unexpected stock shortage"
34118+
},
34119+
"requestedByUser": {
34120+
"type": "boolean",
34121+
"description": "If requested by the user",
34122+
"example": "User canceled the order "
34123+
}
34124+
}
34125+
}
34126+
}
34127+
}
34128+
},
34129+
"responses": {
34130+
"200": {
34131+
"description": "OK",
34132+
"content": {
34133+
"application/json": {
34134+
"schema": {
34135+
"type": "object",
34136+
"properties": {
34137+
"date": {
34138+
"type": "string",
34139+
"description": "Date and time when the notification was received."
34140+
},
34141+
"orderId": {
34142+
"type": "string",
34143+
"description": "Identification of the order in the seller."
34144+
},
34145+
"receipt": {
34146+
"type": "string",
34147+
"description": "Protocol code generated by the update. It may be `null`."
34148+
}
34149+
}
34150+
},
34151+
"example": {
34152+
"date": "2024-02-07T15:22:56.7612218-02:00",
34153+
"orderId": "123543123",
34154+
"receipt": "38e0e47da2934847b489216d208cfd91"
34155+
}
34156+
}
34157+
}
34158+
},
34159+
"429": {
34160+
"description": "Too many requests."
34161+
},
34162+
"403": {
34163+
"description": "The credentials are not enabled to access the service."
34164+
},
34165+
"404": {
34166+
"description": "Value not found."
34167+
}
34168+
}
34169+
}
34170+
},
3406434171
"/api/checkout/pub/pickup-points": {
3406534172
"get": {
3406634173
"tags": [

vtex/utils/types.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1470,9 +1470,9 @@ export interface OrderItem {
14701470
}
14711471

14721472
export interface CanceledOrder {
1473-
date: string;
1474-
orderId: string;
1475-
receipt: string | null;
1473+
date?: string;
1474+
orderId?: string;
1475+
receipt?: string | null;
14761476
}
14771477

14781478
interface Marketplace {

0 commit comments

Comments
 (0)