Nykaa: Cancel Order Flow
Step 1: At first, we will fetch all the connections with their respective channels on the basis of the integration type of the Nykaa app. To fetch the connections based on the automation step’s stepId, we will be using the following query:
SELECT ie_app_automation_steps_config.connectionId,
ie_app_automation_steps_config.latestSyncTimeStamp, ie_appinstall_connection.accessToken
FROM ie_app_automation_steps_config
LEFT JOIN ie_appinstall_connection ON ie_app_automation_steps_config.connectionId=ie_appinstall_connection.id
WHERE ie_app_automation_steps_config.appAutomationStepId=?
AND ie_app_automation_steps_config.isActive='1'
AND ie_appinstall_connection.accessToken IS NOT NULL
AND ie_appinstall_connection.isActive = 'active'
Step 2: Secondly, we will iterate over the connection id and fetch all the channel related data corresponding to the connection id using the following query:
SELECT channels.connectionId,channels.externalChannelId ,external_wms_channels.locationId,
warehouses.externalWarehouseId,accounts.account_slug,channels.integration_model_id ,
channels.integrationType AS integrationType
FROM channels
LEFT JOIN external_wms_channels ON channels.id= external_wms_channels.channel_id
LEFT JOIN warehouses ON warehouses.id = external_wms_channels.warehouse_id
LEFT JOIN accounts ON channels.account_id = accounts.id
WHERE channels.connectionId IN (?)
Now, we will prepare an object as shown below from the data received by executing the above query and send it further in the task queue.
Channel connection map object:
{
"channelData": {
"integrationType": "17",
"externalChannelId": " ",
"accountSlug": " ",
"connectionId": " ",
"location": {
"Test": "Warehouse"
},
"workspaceToken": " "
"accessToken": " ",
"latestSyncTimeStamp": " ",
"isActive": "active",
"refreshToken": " ",
"inputFields": {
"tenant": "eshopbox",
"username": "ajay@eshopbox.com",
"password": "eshop@123"
}
}
}
The access token is generated needs to be stored in Cache Memory in the specified format given below:
{
"connectionAccessToken_{{connectionId}}":"{{ACCESS TOKEN}}"
}
Step 3: We will the hit the get order list API of Nykaa to pull the cancelled or partially cancelled orders. While hitting the API, we also require to send a request body consisting of these following filters: updateDate, filterStatusList, sellerId, pageNumber and limit.
Note: In filterStatusList we need to send 5,8 as mandatory status in every request. 5 is for confirmed and 8 is for cancelled.
Sample API:
https://xxxxx/RestWS/api/sellerPanel/v3/orderList
Sample Request Body:
{
"updateDate": "30/07/2020 17:55:09",
"filterStatusList": "5,8,15,25,10,18",
"sellerId": "mwhc2",
"pageNumber": "1",
"limit": "200"
}
Sample Headers:
Authorization : {{API Key}}
facility : {{Seller ID}}
Step 4: We receive the following response from Nykaa as shown below :
{
"responseCode": 0,
"responseMessage": "Success",
"orderList": [
{
"orderNo": "59878966-1",
"orderStatus": "15",
"orderDate": "14/06/2019 16:53:44",
"orderLastUpdateDate": "03/06/2020 17:47:07",
"onHold": "0",
"sellerId": "TEST4"
},
{
"orderNo": "53210664-1",
"orderStatus": "15",
"orderDate": "14/06/2019 16:53:44",
"orderLastUpdateDate": "04/06/2020 16:16:50",
"onHold": "0",
"sellerId": "TEST4"
},
{
"orderNo": "34033344-1",
"orderStatus": "15",
"orderDate": "14/06/2019 16:53:44",
"orderLastUpdateDate": "09/06/2020 13:29:29",
"onHold": "0",
"sellerId": "TEST4"
}
]
}
Step 5: We divide the list of orders obtained above, in the response, into a pack of 20 and send them further in a task queue with the channelData map.
{
"channelData": {
"integrationType": "17",
"externalChannelId": "",
"accountSlug": "",
"connectionId": "",
"location": {
"Warehouse": "Warehouse"
},
"workspaceToken": " ",
"accessToken": "",
"isActive": "active",
"refreshToken": " ",
"inputFields": "{\"tenant\":\"eshopbox\",\"username\":ajay@eshopbox.com,\"password\":\"eshop@123\"}",
"listOfOrders": [
{
"orderNo": "59878966-1",
"orderStatus": "15",
"orderDate": "14/06/2019 16:53:44",
"orderLastUpdateDate": "03/06/2020 17:47:07",
"onHold": "0", "sellerId": "TEST4"
},
{
"orderNo": "53210664-1",
"orderStatus": "15",
"orderDate": "14/06/2019 16:53:44",
"orderLastUpdateDate": "04/06/2020 16:16:50",
"onHold": "0", "sellerId": "TEST4"
},
{
"orderNo": "34033344-1",
"orderStatus": "15",
"orderDate": "14/06/2019 16:53:44",
"orderLastUpdateDate": "09/06/2020 13:29:29",
"onHold": "0", "sellerId": "TEST4"
}
]
}
Step 6: Now in the task queue listener, we will be preparing request body for each order by iterating over the order number and call the order fetch API from Nykaa.
API URL:
https://xxxxx/RestWS/api/sellerPanel/v3/orderFetch
Request body:
{"orderNo" : ["83724872-1"] }
Curl:
curl --location --request POST 'https://preprod.vineretail.com/RestWS/api/sellerPanel/v3/orderFetch' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'apiKey: NTFURVNUNH43OWUxZTY3MGY2YWE0MDUxYjQ3ZTE2ZWQxNjMyY2UzZGMyOTJhZWNkYTgyOTQ0ZDFhZWU4YTU0' \
--header 'Cookie: cfduid=d686824f48d566932427e0b40a10761a21600699771' \
--data-urlencode 'RequestBody={"orderNo" : ["83724872-1"] }'
Sample Headers:
Authorization : {{API Key}}
facility : {{Seller ID}}
Step 7: We will be receiving a response which is as follows:
{
"responseCode": 0,
"responseMessage": "Success",
"orders": [
{
"orderNo": "83724872-1",
"orderStatus": "5",
"orderDate": "14/06/2019 16:53:44",
"sla": null,
"customerName": "saswati p",
"paymentMethod": "1",
"orderAmount": "1479.00",
"orderCurrency": "INR",
"orderTaxAmount": "0.00",
"onHold": "0",
"shippingCharge": "200.00",
"discountAmount": "120.00",
"discCouponCode": null,
"storeCredit": "0.00",
"gvAmount": "0.00",
"codCharge": "0.00",
"address1": "flat D - 10, jrm pearl",
"address2": null,
"address3": null,
"phone": "0085980000",
"email": "pani@gmail.com",
"countryCode": "IND",
"state": "Haryana",
"city": "Humla",
"pinCode": "786007",
"billToName": "saswati p",
"bill_Address1": "flat D - 10, jrm pearl",
"bill_Address2": null,
"bill_Address3": null,
"bill_Phone": "0085980000",
"bill_Email": "pani@gmail.com",
"bill_CountryCode": "IND",
"bill_State": "Haryana",
"bill_City": "Humla",
"bill_ZipCode": "786007",
"cancelRemark": null,
"reasonForCancellation": null,
"priority": null,
"orderLastUpdateDate": "26/06/2019 17:22:13",
"masterOrderNo": "NYKL00003378",
"gstin": null,
"sellerId": "TEST4",
"orderItems": [
{
"lineNo": "1",
"deliveryMode": "1",
"skuCode": "TEST-55829-00006",
"skuName": "Test4 vendor SKU6",
"orderQty": "1",
"rejectedQty": null,
"cancelledQty": null,
"shippedQty": null,
"returnedQty": null,
"deliveredQty": null,
"lineAmount": "698.93",
"lineTaxAmount": "0.00",
"unitPrice": "699.00",
"mrp": "699.00",
"discountAmount": "100.00",
"shippingCharge": "99.93",
"codCharge": null,
"invoiceNo": null,
"transCode": "999904",
"transName": "NykaaSelf",
"awbNo": null,
"imeiNos": null,
"confirmDate": "26/06/2019 17:22:13",
"gvAmount": null,
"storeCredit": "0.00",
"lineStatus": "5",
"cst": null,
"vat": null
},
{
"lineNo": "2",
"deliveryMode": "1",
"skuCode": "TEST-55829-00005",
"skuName": "Test4 vendor SKU5",
"orderQty": "1",
"rejectedQty": null,
"cancelledQty": null,
"shippedQty": null,
"returnedQty": null,
"deliveredQty": null,
"lineAmount": "780.07",
"lineTaxAmount": "0.00",
"unitPrice": "700.00",
"mrp": "700.00",
"discountAmount": "20.00",
"shippingCharge": "100.07",
"codCharge": null,
"invoiceNo": null,
"transCode": "999904",
"transName": "NykaaSelf",
"awbNo": null,
"imeiNos": null,
"confirmDate": "26/06/2019 17:22:13",
"gvAmount": null,
"storeCredit": "0.00",
"lineStatus": "5",
"cst": null,
"vat": null
}
]
}
]
}
Step 8: We will be adding the order details in the channelData map in the following way:
{
"channelData": {
"integrationType": "17",
"externalChannelId": "",
"accountSlug": "",
"connectionId": "",
"location": {
"Warehouse": "Warehouse"
},
"workspaceToken": " ",
"accessToken": "",
"isActive": "active",
"refreshToken": " ",
"inputFields": "{\"tenant\":\"eshopbox\",\"username\":ajay@eshopbox.com,\"password\":\"eshop@123\"}",
"listOfOrders": [
{
"orderNo": "59878966-1",
"orderStatus": "15",
"orderDate": "14/06/2019 16:53:44",
"orderLastUpdateDate": "03/06/2020 17:47:07",
"onHold": "0", "sellerId": "TEST4"
},
{
"orderNo": "53210664-1",
"orderStatus": "15",
"orderDate": "14/06/2019 16:53:44",
"orderLastUpdateDate": "04/06/2020 16:16:50",
"onHold": "0", "sellerId": "TEST4"
},
{
"orderNo": "34033344-1",
"orderStatus": "15",
"orderDate": "14/06/2019 16:53:44",
"orderLastUpdateDate": "09/06/2020 13:29:29",
"onHold": "0", "sellerId": "TEST4"
}
],
"orderDetails":{
"responseCode": 0,
"responseMessage": "Success",
"orders": [
{
"orderNo": "83724872-1",
"orderStatus": "5",
"orderDate": "14/06/2019 16:53:44",
"sla": null,
"customerName": "saswati p",
"paymentMethod": "1",
"orderAmount": "1479.00",
"orderCurrency": "INR",
"orderTaxAmount": "0.00",
"onHold": "0",
"shippingCharge": "200.00",
"discountAmount": "120.00",
"discCouponCode": null,
"storeCredit": "0.00",
"gvAmount": "0.00",
"codCharge": "0.00",
"address1": "flat D - 10, jrm pearl",
"address2": null,
"address3": null,
"phone": "0085980000",
"email": "pani@gmail.com",
"countryCode": "IND",
"state": "Haryana",
"city": "Humla",
"pinCode": "786007",
"billToName": "saswati p",
"bill_Address1": "flat D - 10, jrm pearl",
"bill_Address2": null,
"bill_Address3": null,
"bill_Phone": "0085980000",
"bill_Email": "pani@gmail.com",
"bill_CountryCode": "IND",
"bill_State": "Haryana",
"bill_City": "Humla",
"bill_ZipCode": "786007",
"cancelRemark": null,
"reasonForCancellation": null,
"priority": null,
"orderLastUpdateDate": "26/06/2019 17:22:13",
"masterOrderNo": "NYKL00003378",
"gstin": null,
"sellerId": "TEST4",
"orderItems": [
{
"lineNo": "1",
"deliveryMode": "1",
"skuCode": "TEST-55829-00006",
"skuName": "Test4 vendor SKU6",
"orderQty": "1",
"rejectedQty": null,
"cancelledQty": null,
"shippedQty": null,
"returnedQty": null,
"deliveredQty": null,
"lineAmount": "698.93",
"lineTaxAmount": "0.00",
"unitPrice": "699.00",
"mrp": "699.00",
"discountAmount": "100.00",
"shippingCharge": "99.93",
"codCharge": null,
"invoiceNo": null,
"transCode": "999904",
"transName": "NykaaSelf",
"awbNo": null,
"imeiNos": null,
"confirmDate": "26/06/2019 17:22:13",
"gvAmount": null,
"storeCredit": "0.00",
"lineStatus": "5",
"cst": null,
"vat": null
},
{
"lineNo": "2",
"deliveryMode": "1",
"skuCode": "TEST-55829-00005",
"skuName": "Test4 vendor SKU5",
"orderQty": "1",
"rejectedQty": null,
"cancelledQty": null,
"shippedQty": null,
"returnedQty": null,
"deliveredQty": null,
"lineAmount": "780.07",
"lineTaxAmount": "0.00",
"unitPrice": "700.00",
"mrp": "700.00",
"discountAmount": "20.00",
"shippingCharge": "100.07",
"codCharge": null,
"invoiceNo": null,
"transCode": "999904",
"transName": "NykaaSelf",
"awbNo": null,
"imeiNos": null,
"confirmDate": "26/06/2019 17:22:13",
"gvAmount": null,
"storeCredit": "0.00",
"lineStatus": "5",
"cst": null,
"vat": null
}
]
}
]
}
Step 9: We will push the above channel Data Map onto the pub/sub topic: nykaa_cancel_order_data.
Step 10: We will prepare the request body for create order API in the pub/sub topic listener.
Mapping of keys in create order API and keys in the channel data map is as follows:
No. | Keys in create order API | Keys in the channel data map or values set |
---|---|---|
1. | externalChannelID |
|
2. | customerOrderNumber |
|
3. | shipMethod |
|
4. | orderDate |
|
5. | isCOD |
|
6. | paymentType |
|
7. | taxAmount |
|
8. | shipChargeAmount |
|
9. | subtotal |
|
10. | orderTotal |
|
11. | balanceDue |
|
12. | shippingAddress |
|
13. | shippingAddress.customerName |
|
14. | shippingAddress.addressLine1 |
|
15. | shippingAddress.addressLine2 (optional) |
|
16. | shippingAddress.city |
|
17. | shippingAddress.state |
|
18. | shippingAddress.postalCode |
|
19. | shippingAddress.countryCode |
|
20. | shippingAddress.countryName |
|
21. | shippingAddress.contactPhone |
|
22. | shippingAddress.email |
|
23. | billingAddress |
|
24. | billingAddress.customerName |
|
25. | billingAddress.addressLine1 |
|
26. | billingAddress.addressLine2 (optional) |
|
27. | billingAddress.city |
|
28. | billingAddress.state |
|
29. | billingAddress.postalCode |
|
30. | billingAddress.countryCode |
|
31. | billingAddress.countryName |
|
32. | billingAddress.contactPhone |
|
33. | billingAddress.email |
|
34. | items |
|
34. | items.lineItemSequenceNumber |
|
35. | items.itemID |
|
36. | items.orderItemID |
|
37. | items.productName |
|
38. | items.customerPrice |
|
39. | items.discount |
|
40. | items.productImageUrl |
|
41. | items.productUrl |
|
42. | items.quantity |
|
43. | items.externalWarehouseID |
|
44. | vendorOrderNumber |
|
45. | thirdPartyShipping(optional) | 1 |
46. | reason |
|
47. | remark |
|
Step 11: WMS cancel API URL for cancelling orders in Eshopbox is as follows:
https://wms.eshopbox.com/api/cancel-order
Sample request body:
{
"externalChannelID":"",
"customerOrderNumber":"83724872-1",
"reason":"Cancelled by Admin",
"cancellationTime": "",
"items":
[
{
"lineItemSequenceNumber": "1",
"itemID": "TEST-55829-00006",
"quantity": 1,
"productName": "st4 vendor SKU5",
"remark" :"default"
}
]
}
Sample Header:
Authorization : Bearer token