Cancel Order Flow
Sequence Diagram
Architecture
Step 1. Listen to PubSub for the CancelOrder event and get QueueData from it.
QueueData:
{
"queueData": {
"channelData": {
"externalChannelId": "CH5811",
"accountSlug": "montecarlo",
"connectionId": 78,
"location": {
"58291847336": "MJPAT_109",
"58291912872": "Warehouse"
},
"cancellationTime": "24-06-2022 12:21:07",
"wmsAccessToken": "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",
"tataCliqAccessToken": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Ik1UaERRamxDUlRJelJVUTRRVU0wUVRJNU1FSkVOVGszUVVFeU5qVXdSa1JDTmpBeU16WTROQSJ9.eyJodHRwczovL2FwcERhdGEiOnsiYXBwQ2xpZW50SWQiOiJjN2U1MDU4NGRhMDM4MmFlY2RmMWEzMzQ1OTFmZmQzOCJ9LCJodHRwczovL2FjY291bnRTbHVnIjoibW9udGVjYXJsbyIsImh0dHBzOi8vdXNlckRldGFpbHMiOnsiaWQiOjgwOCwidXNlclR5cGUiOiJkZWZhdWx0IiwiZW1haWwiOiJhcHB1c2VyMjFAZXNob3Bib3guY29tIn0sImh0dHBzOi8vYWNjb3VudHMiOlsibW9udGVjYXJsbyJdLCJodHRwczovL3dhcmVob3VzZXMiOltdLCJodHRwczovL3BhcnRuZXJzIjpbXSwiaXNzIjoiaHR0cHM6Ly9lc2hvcGJveC5hdXRoMC5jb20vIiwic3ViIjoiYXV0aDB8NWZlNDdkZjFhNGZhNmMwMDZmMTBjN2I2IiwiYXVkIjoiaHR0cHM6Ly93bXMubXllc2hvcGJveC5jb20iLCJpYXQiOjE2MDkxNTkxNjYsImV4cCI6MTYxMTc1MTE2NiwiYXpwIjoiUXpWTzdmSGsySFl4Mlk1YjNXRG9pRHVHZTR2Q3dqSFAiLCJzY29wZSI6InJlYWQ6b3JkZXJzIG9mZmxpbmVfYWNjZXNzIiwiZ3R5IjoicGFzc3dvcmQifQ.WIdaENzdkYY90VRv-9AEGwreD66tvGaOBug-9G5erhDvboihXpRevDFe1gZTfJdA-HYWOFadw8bqjoM8ZtUv0pJdOI2QA-rKRhfAAaZOdfZc9Tn3DhybZHT4Pmltthz4Cgz-T516F0CTj0VhcR-T-FGg6-qb1xtPB83lflLAa-Lrj7T3FRqA9yp2r9MLCEkBCzqlrKUpCvdeA5DFaCAb-J8gvPsf9rs9pu6lf2Y_1P1fNETZUk2wZ6tGAt0gQnga6zCkoYZ_Su9FseuRx6rq-1IHeSvvbWUcNkvkZN2X91eAqjSNzK7WtCs0ZATpR9m08bFuFO4XascGfptJnfxb5Q"
},
"orderStatus": {
"orderNo": "221-011-669986",
"transactionsStatus": [
{
"TransactionID": "124015504167",
"OMSStatusCode": "019",
"RejectionReasonCode": "",
"ReturnRequestID": "",
"CreditNoteNumber": ""
}
]
}
}
}
Step 2. Check if the order is present in the Database and get itemID and orderItemID for each item using the following SQL query.
SELECT
orders.customerOrderNumber AS customerOrderNumber,
order_items.lineItemSequenceNumber AS lineItemSequenceNumber,
order_items.itemID AS itemID,
order_items.orderItemID AS orderItemID
FROM
orders
LEFT JOIN
channels
ON orders.channel_id = channels.id
LEFT JOIN
order_items
ON orders.id = order_items.order_id
WHERE
orders.vendorOrderNumber = {{orderStatus.orderNo}}
AND channels.externalChannelID = {{channelData.externalChannelId}}
AND order_items.lineItemSequenceNumber IN (
[ {{orderStatus.transactionStatus[].TransactionID}} ]
) ;
Step 3. Get WMS AccessToken from channel data in queue data, and prepare the WMS Cancel Order request body by mapping the following keys.
WMS Cancel Order Keys | TataCliq Cancel Order Keys |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Step 4. Call WMS CancelOrder API with AccessToken and request body.
WMS CancelOrder API
https://wms.eshopbox.com/api/cancel-order
Request Body
{
"externalChannelID":"{{channelData.externalChannelID}}",
"customerOrderNumber":"{{orderStatus[].orderNo}}",
"reason":"{{orderStatus[].transactionsStatus[0].RejectionReasonCode}}",
"cancellationTime": "{{channelData.cancellationTime}}",
"items":
[
{
"lineItemSequenceNumber": "{{orderStatus[].transactionsStatus[].TransactionID}}",
"orderItemID": "{{orderItemID}}",
"itemID": "{{itemID}}",
"quantity": "1",
"remark" :"{{orderStatus[].transactionsStatus[].RejectionReasonCode}}"
}
]
}
Response Body:
{
"WMSResponse": {
"result": {
"reason": "",
"vendorOrderNumber": "221-011-669986",
"externalChannelID": "CH5811",
"cancellationTime": "24-06-2022T12:21:07+05:30",
"customerOrderNumber": "4418764144834",
"is_cod": "0",
"items": [
{
"itemID": "40125733535938",
"quantity": 1,
"lineItemSequenceNumber": 124015504167,
"remark": "",
"lineItemTotal": 236,
"productName": "Z"
}
]
},
"status": "SUCCESS"
}
}