/
Bulk Action Update - Order Cancel API

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?

  1. User/Client will select the mode of action, User/Client can have three options available

    1. Interactive

    2. Bulk

    3. Import

  2. Based upon above mode User/Client will select action to be performed there is one action in our case

    1. cancel

  3. Based on above to combinations mode+action user will send request to perform the cancellation action

  4. Based on incoming request we will check “mode”, after that we will perform following:

    1. If mode = interactive, get InteractiveActionHandler service from ActionHandlerFactory

    2. If mode = bulk, get BulkActionHandler service from ActionHandlerFactory

    3. If mode = import, get ImportActionHandler service from ActionHandlerFactory

  5. On the basis of incoming request , check the action_taken namedParameter, in our case which will be

    1. cancel

  6. On the basis of incoming request.

    1. InteractiveActionHandler

      1. Get the list of tracking IDs directly from the request as request.get("trackingIds").

    2. BulkActionHandler

    3. ImportActionHandler

      1. From request, get filePath of the CSV

        1. validate null check , uri regex check , file path should end with .csv

      2. using URL API of Java, read the first column(order item id) of the CSV file and save the value in a set

      3. while reading a single line of the file ,place the following validations:

        1. check content type of response header must be text/csv

        2. check number of columns match the import template column count

        3. check for not nullable column values

        4. number of lines read must not exceed maximum limits of record

  7. 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)
  8. 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:"" }
  9. After preparing payload using above step call wms cancel API for each of the items of orderItemIDs e.g

    1. http://blackberrys.eshopbox.com/api/cancel-order
  10. After getting response from wms cancel API we will prepare response based on success status

    1. If status code is 200 then response will be

      { "status": 200, "message": "Order items have been marked as cancelled.", "success_count": 30 }
    2. 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 } }
    3. 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.

 

Add label