Bulk Action Update - Order Cancel API
What is the purpose of this article?
This article contains step-wise logic and flow of Bulk action API with regards to Order Cancel.
What is the approach to achieving this task?
Given below is the workflow diagram of bulk action updates for Order Cancel
Sequence diagram.
What are the steps to achieve the above task?
User/Client will select the mode of action, User/Client can have three options available
Interactive
Bulk
Import
Based upon above mode User/Client will select action to be performed there is one action in our case
cancel
Based on above to combinations mode+action user will send request to perform the cancellation action
Based on incoming request we will check “mode”, after that we will perform following:
If mode = interactive, get InteractiveActionHandler service from ActionHandlerFactory
If mode = bulk, get BulkActionHandler service from ActionHandlerFactory
If mode = import, get ImportActionHandler service from ActionHandlerFactory
On the basis of incoming request , check the action_taken namedParameter, in our case which will be
cancel
On the basis of incoming request.
InteractiveActionHandler
Get the list of tracking IDs directly from the request as request.get("trackingIds").
BulkActionHandler
ImportActionHandler
From request, get filePath of the CSV
validate null check , uri regex check , file path should end with .csv
using URL API of Java, read the first column(order item id) of the CSV file and save the value in a set
while reading a single line of the file ,place the following validations:
check content type of response header must be text/csv
check number of columns match the import template column count
check for not nullable column values
number of lines read must not exceed maximum limits of record
pass all the orderItemIDs in the wms sql query to fetch the following data
SELECT channels.externalChannelID, orders.customerOrderNumber, orders.isCOD, order_items.lineItemSequenceNumber, order_items.orderItemID,order_items.id AS orderItemId_PK FROM order_items LEFT JOIN orders ON order_items.order_id = orders.id LEFT JOIN channels ON orders.channel_id = channels.id WHERE order_items.id IN (OrderItemIDSet)
After getting result from above query prepare map of payload to pass into wms cancel API:
{ "orderItemIDs": [ { "externalChannelID": "", "customerOrderNumber": "", "notifycustomer": "", "items": { "lineItemSequenceNumber": "", "orderItemID": "", "itemID": "", "quantity": "", "productName": "", "remark": "", "additionalInfo": {} } } ], "headers":"auth", "accountSlug:"" }
After preparing payload using above step call wms cancel API for each of the items of orderItemIDs e.g
http://blackberrys.eshopbox.com/api/cancel-order
After getting response from wms cancel API we will prepare response based on success status
If status code is 200 then response will be
{ "status": 200, "message": "Order items have been marked as cancelled.", "success_count": 30 }
If status code is 207 the response will be
{ "status": 207, "message": "Order items have been marked as cancelled.", "success_count": 20, "except": { "pre_marked_cancel": 10, "exceptional_cases": 6, "packed": 1 } }
If status code is 417 the response will be
{ "status": 417, "message": "Unable to cancel items.", "except": { "pre_marked_cancel": 10, "exceptional_cases": 6, "packed": 1 } }
Code For Sequence Diagram.