From 6f6b1bb91c0aa35477c81a6f88486fa8c9df8ef6 Mon Sep 17 00:00:00 2001 From: soutofernando Date: Fri, 20 Dec 2024 15:25:31 -0300 Subject: [PATCH] fix: cancel order --- vtex/actions/orders/cancel.ts | 4 +- vtex/utils/client.ts | 8 -- vtex/utils/openapi/vcs.openapi.gen.ts | 64 +++++++++++++++ vtex/utils/openapi/vcs.openapi.json | 107 ++++++++++++++++++++++++++ vtex/utils/types.ts | 6 +- 5 files changed, 176 insertions(+), 13 deletions(-) diff --git a/vtex/actions/orders/cancel.ts b/vtex/actions/orders/cancel.ts index 78401327b..ed32f2e3d 100644 --- a/vtex/actions/orders/cancel.ts +++ b/vtex/actions/orders/cancel.ts @@ -13,7 +13,7 @@ async function action( req: Request, ctx: AppContext, ): Promise { - const { vcsDeprecated } = ctx; + const { vcs } = ctx; const { cookie, payload } = parseCookie(req.headers, ctx.account); if (!payload?.sub || !payload?.userId) { @@ -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 }, { diff --git a/vtex/utils/client.ts b/vtex/utils/client.ts index afe62a9ba..b66360953 100644 --- a/vtex/utils/client.ts +++ b/vtex/utils/client.ts @@ -1,7 +1,6 @@ import { Userorderslist } from "./openapi/vcs.openapi.gen.ts"; import { Brand, - CanceledOrder, Category, CreateNewDocument, FacetSearchResult, @@ -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 { diff --git a/vtex/utils/openapi/vcs.openapi.gen.ts b/vtex/utils/openapi/vcs.openapi.gen.ts index 35a757449..aa648d848 100644 --- a/vtex/utils/openapi/vcs.openapi.gen.ts +++ b/vtex/utils/openapi/vcs.openapi.gen.ts @@ -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. * diff --git a/vtex/utils/openapi/vcs.openapi.json b/vtex/utils/openapi/vcs.openapi.json index 88fb11cf5..bda53623c 100644 --- a/vtex/utils/openapi/vcs.openapi.json +++ b/vtex/utils/openapi/vcs.openapi.json @@ -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": [ diff --git a/vtex/utils/types.ts b/vtex/utils/types.ts index 84f2f7b22..cca789af1 100644 --- a/vtex/utils/types.ts +++ b/vtex/utils/types.ts @@ -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 {