Amazon Return Complete Flow
High Level Diagram:
AMAZON RETURN CREATE TO CREATE FLOW
A. Webhook based Implementation(Existing Flow)
AMAZON DEFAULT SERVICE
Step 1: Receive return Event From Amazon via webhook ( Repo : esb-amzprime-webhook-service, Endpoint : esb/v1/eventbridge/event
)
Note: We can recieved “Created” status on 3 types of "detail-type"
1. "detail-type": "Returns.Created"
2. "detail-type": "Returns.Updated"
3. "detail-type": "Returns.Replanned"
{
"version": "0",
"id": "42683ee9-01f3-5812-8803-4069f066dc05",
"detail-type": "Returns.Created",
"source": "com.amazon.yojaka.orders",
"account": "096882763573",
"time": "2023-08-06T01:18:29Z",
"region": "eu-west-1",
"resources": [],
"detail": {
"returnId": "55b0bbd3-6b9f-4b27-85d5-b625d460d6eb",
"returnLocationId": "899e2072-e5d7-4bb8-8ad6-4d04214d25b3",
"merchantId": "A3VDH5TGHO7F3K"
}
}
or
{
"version": "0",
"id": "94f59c5a-ba2f-aa3f-0098-40d4a96c40d6",
"detail-type": "Returns.Updated",
"source": "com.amazon.yojaka.orders",
"account": "096882763573",
"time": "2023-08-06T01:18:29Z",
"region": "eu-west-1",
"resources": [],
"detail": {
"returnId": "55b0bbd3-6b9f-4b27-85d5-b625d460d6eb",
"returnLocationId": "899e2072-e5d7-4bb8-8ad6-4d04214d25b3",
"metadata": {
"returnStatus": "CREATED"
},
"merchantId": "A3VDH5TGHO7F3K"
}
}
Or
{
"version": "0",
"id": "fd31ac8d-ce6b-fe0a-8dd1-463218c7fc77",
"detail-type": "Returns.Replanned",
"source": "com.amazon.yojaka.orders",
"account": "096882763573",
"time": "2024-05-02T12:32:12Z",
"region": "eu-west-1",
"resources": [],
"detail": {
"returnId": "1314f2a7-4f18-4e60-b93c-8c076aadbe60",
"returnLocationId": "9b87bb23-be2d-42c1-83c6-9c4a5764bcfc",
"returnTrackingInfo": {
"reverseLegTrackingId": "626956580528",
"carrierName": "ATS"
},
"merchantId": "A1UJIXOLA4048F"
}
}
after receieved the event we push the single data to taskQueue
Step 2 : Event push to endpoint ( listen/orderevent/return/create
,
Repo : esb-amzprime-webhook-service) to fetch all the details related to above "returnId"
.
1. Now we need to extract the following keys from the Return Event:
MerchantId: To extract all the Active Connections using the below Query:
SELECT id FROM ie_appinstall_connection WHERE inputFields LIKE '%"merchantId":"AAFR4ZPY4GS0"%' AND refreshToken IS NOT NULL AND accessToken IS NOT NULL
Now pull ChannelData by Using ConnectionId with the following Query:
SELECT channels.integrationType AS integrationType, accounts.account_slug AS accountSlug,
channels.connectionId AS connectionId, channels.externalChannelId AS externalChannelId,
external_wms_channels.locationId AS locationId,
warehouses.externalWarehouseId AS externalWareHouseId 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 =:connectionId GROUP BY external_wms_channels.locationId ORDER BY external_wms_channels.id ASC
Along with the ChannelData, we will also need accessToken, refresh token, and isActive flag. So we will use the following Query:
SELECT accessToken, inputFields, refreshToken,
isActive FROM ie_appinstall_connection WHERE id = :connectionId
So, now our connection_ChannelData will look like below:
Cache key: “connection_channeldata_{{connectionId}}"
{
"channelData": {
"integrationType": "8",
"storeSlug": "",
"externalChannelId": "CH1200",
"accountSlug": "eshop",
"connectionId": "361",
"location": {
"804cde7b-bd2f-4a3e-923c-386715089fa1": "MJPAT_109",
"8fc83148-5b97-49cf-b724-7c46d50946aa": "ESBBLR_111",
"d1391379-8283-4335-a43c-0a2eb2fe2d21": "ESBMUM_112"
},
"accessToken": "Atza|IwEBIBmnRqef-YkpJOZ_b0ov2wWiCgrazw-N1iXQM0a46K7K5gl4D30Mb-LGVPR_dXQ74Os0mAFlWp8yLgqW9TEsFVsmsIhk3uFF_N4LK1mfWTv45LpgxmVHV4HhpAGuzNc8qClptpUMP-cuc_0xwfMK_K83jFNE0zaIpVL4QdeYcBj_G3qusKp70hXi71_6Sa5E7Khz6CH7Agx-Ur5FUQUbr2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etcZ2PW5fHYqQMLwh75OpnsGtsAekKcaOVcqVvSF1WfDNYDtV4H9lfKe0IzNFDQ8WQ18DSjvwvWWDSxQxSG9BTVa8d3NPKnEyTAhH9yeZTe6FCBk9T_8fwzbTaehZ_wvUFfYooQLMUCTUalQxjjOLiCiIZ4GDwF8ogOCMbLF0bA"
}
}
Now we will check whether the Return created belongs to the Location we have mapped or not. To do this, we need to compare the LocationId from the Return Event to the LocationId given in the connection_ChannelData. If matches then proceed further.
Step 3 : Now fetch Return Event Details using Return ID :
https://api.prod.dub.yojaka.xp.sellers.a2z.com/v1/returns/55b0bbd3-6b9f-4b27-85d5-b625d460d6eb
Response: FBA ORDER
{
"creationTimestamp": 1691284707131,
"fulfillmentLocationId": "899e2072-e5d7-4bb8-8ad6-4d04214d25b3",
"id": "55b0bbd3-6b9f-4b27-85d5-b625d460d6eb",
"lastUpdatedTimestamp": 1691284708094,
"merchantSku": "Premium-Broken-Walnut-200g",
"numberOfUnits": 1,
"returnLocationId": "899e2072-e5d7-4bb8-8ad6-4d04214d25b3",
"returnMarketplaceChannelDetails": {
"channelSku": "Premium-Broken-Walnut-200g",
"customerOrderId": "404-6663958-8829169",
"marketplaceChannel": {
"channelName": "FBA",
"marketplaceName": "AMAZON_IN"
},
"merchantId": "A3VDH5TGHO7F3K",
"returnLocationId": "XGMS",
"shipmentId": "UCqSPFYHM"
},
"returnMetadata": {
"fulfillmentOrderId": "e77bf445-bc1e-4de5-9eb2-d228b56b23e0",
"invoiceInfo": {
},
"returnReason": "REJECT",
"rmaId": ""
},
"returnShippingInfo": {
"forwardTrackingInfo": {
"carrierName": "ATS",
"trackingId": "326533604738"
},
"reverseTrackingInfo": {
"carrierName": "ATS",
"trackingId": "326533604738"
}
},
"returnStatus": "CREATED",
"returnType": "REJECT"
}
OR
{
"id": "55b0bbd3-6b9f-4b27-85d5-b625d460d6eb",
"returnLocationId": "899e2072-e5d7-4bb8-8ad6-4d04214d25b3",
"merchantSku": "Premium-Broken-Walnut-200g",
"numberOfUnits": "1",
"fulfillmentLocationId": "899e2072-e5d7-4bb8-8ad6-4d04214d25b3",
"returnType": "REJECT",
"returnStatus": "IN_TRANSIT",
"creationTimestamp": 1691284707131,
"lastUpdatedTimestamp": 1691397659864,
"returnMetadata": {
"returnReason": "REJECT",
"fulfillmentOrderId": "e77bf445-bc1e-4de5-9eb2-d228b56b23e0",
"rmaId": "",
"invoiceInfo": {
"invoiceId": "XGMS-8058"
}
},
"returnShippingInfo": {
"forwardTrackingInfo": {
"trackingId": "326533604738",
"carrierName": "ATS"
},
"reverseTrackingInfo": {
"trackingId": "626024994448",
"carrierName": "ATS"
}
},
"returnMarketplaceChannelDetails": {
"marketplaceChannel": {
"marketplaceName": "AMAZON_IN",
"channelName": "FBA"
},
"merchantId": "A3VDH5TGHO7F3K",
"shipmentId": "UCqSPFYHM",
"customerOrderId": "404-6663958-8829169",
"returnLocationId": "XGMS",
"channelSku": "Premium-Broken-Walnut-200g"
},
"returnedWithOTP": false,
"replanned": true,
"replacement": false,
"exchange": false,
"previousTrackingInfo": [
{
"trackingId": "326533604738",
"carrierName": "ATS"
}
]
}
Response: MFN ORDER
{
"creationTimestamp": 1691284707131,
"fulfillmentLocationId": "899e2072-e5d7-4bb8-8ad6-4d04214d25b3",
"id": "55b0bbd3-6b9f-4b27-85d5-b625d460d6eb",
"lastUpdatedTimestamp": 1691284708094,
"merchantSku": "Premium-Broken-Walnut-200g",
"numberOfUnits": 1,
"returnLocationId": "899e2072-e5d7-4bb8-8ad6-4d04214d25b3",
"returnMarketplaceChannelDetails": {
"channelSku": "Premium-Broken-Walnut-200g",
"customerOrderId": "404-6663958-8829169",
"marketplaceChannel": {
"marketplaceName": "AMAZON_IN",
"channelName": "MFN"
},
"merchantId": "A3VDH5TGHO7F3K",
"returnLocationId": "XGMS",
"shipmentId": "UCqSPFYHM"
},
"returnMetadata": {
"fulfillmentOrderId": "e77bf445-bc1e-4de5-9eb2-d228b56b23e0",
"invoiceInfo": {
},
"returnReason": "REJECT",
"rmaId": ""
},
"returnShippingInfo": {
"forwardTrackingInfo": {
"carrierName": "ATS",
"trackingId": "326533604738"
},
"reverseTrackingInfo": {
"carrierName": "ATS",
"trackingId": "326533604738"
}
},
"returnStatus": "CREATED",
"returnType": "REJECT"
}
Step 4 : Once the Detailed Return Response is retrieved, Prepare QueueData which will be sent to Amzprime-Order Service for Transformation. It will look like this as given below ( Step 1 : AMAZON DEFAULT SERVICE )
Important check : make sure event contains “reverseTrackingInfo
" exists and the map must be non-empty then push the event to Middle Layer, Otherwise simply Ignore the flow.(To avoid un-neccessary Query Calling, and Null Pointer exception)
AMAZON TRANSFORMATION LAYER SERVICE : Repo = esb-amzprime-order-service
Step 5: In the middle layer we receive QueData from Pubsub looks like below map:
{
"queueData": {
"channelData": {
"integrationType": "8",
"storeSlug": "",
"externalChannelId": "CH1200",
"accountSlug": "eshop",
"connectionId": "361",
"location": {
"804cde7b-bd2f-4a3e-923c-386715089fa1": "OZiva_DL",
"8fc83148-5b97-49cf-b724-7c46d50946aa": "Bangalore_FC",
"3f5f6b03-a3fe-4319-a504-18083b87a5d8": "Kolkata_FC",
"d1391379-8283-4335-a43c-0a2eb2fe2d21": "Eshopbox_Mumbai"
},
"accessToken": "Atza|IwEBIPr3r0ZeuHDcc5hnfvfkPMKZwXVino5qbnqKVDqfP_t4NqK7-Mm5N0smlWJjheB-Q1BWUuBn1dPYY7lyqkG-y6MTgU28ySc-KHJPIwmnS-g-omDyXB-QBjPwd153EKAZ36udZ71BcYKA3TlJ2tzoUvhjr_S4bmYY7rxi234vCNLvD4X20tbXw7TWRPGjy8139Zk1rF3LbAKHZfSdlWQKcxIg1bL6duIHOJOQKnpRcLjYXK3QWAlvKco1quN54Ml4kgr721MdDxASRLbMd3o2OnlsgguZGeY4rmMnkmJrBzHghO5ZnPVG3ym2pHtZKDc6PLAt2SZ3h_1KvMuhECYmTUaKY1oliG0fOpXPMKN7sLgERThs34ZmgH5Ssw6oy1-7BpmSz8h-IzacxGl9tx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GgjM4cDJazI1H06OcFVeHn3c3dW8cWu6ha1C-7cCoRB53L5vsXSOjkd1b3b8ROSbxlw"
},
"orderDetail": {
"creationTimestamp": 1.673934731735E12,
"fulfillmentLocationId": "d1391379-8283-4335-a43c-0a2eb2fe2d21",
"id": "cba2347d-f795-45be-91f5-4fb9dcfe761e",
"lastUpdatedTimestamp": 1.673934732563E12,
"merchantSku": "42MLC3GY0HB",
"numberOfUnits": 1.0,
"returnLocationId": "d1391379-8283-4335-a43c-0a2eb2fe2d21",
"returnMarketplaceChannelDetails": {
"channelSku": "42MLC3GY0HB",
"customerOrderId": "406-0266493-6139564",
"marketplaceChannel": {
"channelName": "FBA",
"marketplaceName": "AMAZON_IN"
},
"merchantId": "A2L90Y54FJK6W9",
"returnLocationId": "XWRA",
"shipmentId": "U67ybTLPv"
},
"returnMetadata": {
"fulfillmentOrderId": "eb58b6c8-2fc8-4107-9ac4-2ae45af64e6f",
"invoiceInfo": {},
"returnReason": "Defective/Does not work properly",
"rmaId": "DG0ByZpsRRMA"
},
"returnShippingInfo": {
"forwardTrackingInfo": {
"carrierName": "ATS",
"trackingId": "321534361376"
},
"reverseTrackingInfo": {
"carrierName": "ATSIN",
"trackingId": "625435090930"
}
},
"returnStatus": "CREATED",
"returnType": "CUSTOMER"
}
}
}
Step 6: Fetch fulfillmentOrderId
: CustomerOrderNumber, externalChannelID, marchantId : itemId
and Check in Eshopbox if return created or not using externalChannelID, CustomerOrderNumber, itemId:
SELECT
return_shipments.customerReturnNumber,
return_shipments.trackingID,
orders.customerOrderNumber,
orders.vendorOrderNumber,
order_items.lineItemSequenceNumber,
order_items.returnFlag,
order_items.return_shipment_id
FROM
return_shipments
LEFT JOIN
order_items
ON order_items.return_shipment_id = return_shipments.id
LEFT JOIN
orders
ON orders.id = order_items.order_id
LEFT JOIN
channels
ON channels.id = orders.channel_id
WHERE
channels.externalChannelID = 'CH2220' // externalchannel_id
AND orders.customerOrderNumber = 16745640561971932722 // fulfillmentOrderId
AND order_items.itemID IN //merchantSku
(
647775
)
Now we will make grouping of return flow according to return details received from DB with the returnDetails received from Amazon
Note :
Event.TrackingId = queueData.orderDetail.returnShippingInfo.ReverseTrackingInfo.trackingId
DB.TrackingId = return_shipments.trackingID (from Query)
Event.returnId = queueData.orderDetail.id
DB.returnId = return_shipments.customerReturnNumber(FromQuery)
Previous.TrcakingId = queueData.orderDetail.previousTrackingInfo.trackingId
Step 7:
Case 1: when returnFlag == 0, and empty DB.TrackingId and empty DB.returnId received from DB means return not created before.
Approach : we need to create the return. There are 2 types of return objects, sent by amazon:
returnType = “CUSTOMER”
returnType = “
REJECT
”
For both the return type, we call the same API to create a return in WMS mentioned below :
Method: POST
https://return-dot-eshopbox-client-portal-prod.el.r.appspot.com/_ah/api/esb/v2/return
Transformation of the Amazon Customer Return Event into Eshopbox Return Order API is as per the following mapping:
Eshopbox Return Order Keys (ReturnNewDto) | Amazon Return Order Keys |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
| {{From DB}} |
|
|
|
|
|
|
|
|
| true |
WMS REQUEST BODY AFTER TRANSFORMATION:
{
"trackingID": "REV-TRAC-12321",
"channel": {
"externalChannelId": "CH2194"
},
"returnType": "FDR",
"orderItems": [
{
"orderID": "dc41883e-1f56-44a3-9bf8-ebf894bf019e",
"sku": "T4R1X3H9K4B",
"quantity": 1,
"returnReason": "jdtRCLqO1C"
}
],
"shippingProvider": "TestCarrier",
"customerReturnNumber": "4d1f3887-c980-4194-a14b-699c09b8d3d1",
"statusAsPerChannel": "CREATED",
"isCreateApplicable": true
}
Case 2 : when returnFlag == 1, DB.returnId == Event.ReturnId, DB.trackingId != Event.TrackingId, means tracking Id needs to be updated.
Approach : simply call Update tracking API call ( will make a check of Previous.TrcakingId == DB.trackingId) then Event.TrackingId Id associated with Given returnId.
Method PUT
https://return-dot-eshopbox-client-portal-prod.el.r.appspot.com/_ah/api/esb/v2/updateReturn/{{customerReturnNumber}}
Request Body:
{
"courierName": "ATS",
"customerReturnNumber": "55b0bbd3-6b9f-4b27-85d5-b625d460d6eb",
"type": "courier_return",
"customerOrderNumber": "e77bf445-bc1e-4de5-9eb2-d228b56b23e0",
"remarks": "REJECT",
"status": "created",
"trackingID": "626024994448" //new Tracking Id from Event
}
Case 3 : when returnFlag == 1, DB.returnId != Event.ReturnId, means new returnId arrives for a return item.
Step 1:
Case 3.1: If( event.trackingId != DB.trackingIds) then → Upadate the new TrackingId to existing created return
Case 3.2: If (event.trackingId == DB.trackingIds) means tracking Id same-> Simply ignore tha case as our main concern is into trackingId
Case 4 : when returnFlag == 1 and DB.returnId == Event.ReturnId and event.trackingId == DB.trackingIds -> Simply ignore the case, Don't call any return API.
RETURN UPDATE FLOW
AMAZON DEFAULT SERVICE
Step 1: Receive return Event From Amazon via webhook ( Repo : esb-amzprime-webhook-service, Endpoint : esb/v1/eventbridge/event
)
{
"version": "0",
"id": "94f59c5a-ba2f-aa3f-0098-40d4a96c40d6",
"detail-type": "Returns.Updated",
"source": "com.amazon.yojaka.orders",
"account": "096882763573",
"time": "2023-08-06T01:18:29Z",
"region": "eu-west-1",
"resources": [],
"detail": {
"returnId": "55b0bbd3-6b9f-4b27-85d5-b625d460d6eb",
"returnLocationId": "899e2072-e5d7-4bb8-8ad6-4d04214d25b3",
"metadata": {
"returnStatus": "CREATED"
},
"merchantId": "A3VDH5TGHO7F3K"
}
}
Note : Here "detail-type": "Returns.Updated" thats the key to identify is it for return create or return Update.
Step 2 : Event push to endpoint ( listen/orderevent/return/update
, Repo : esb-amzprime-webhook-service) to fetch all the details related to above "returnId"
.
Now we need to extract the following keys from the Return Event:
MerchantId: To extract all the Active Connections using the below Query:
SELECT id FROM ie_appinstall_connection WHERE inputFields LIKE '%"merchantId":"AAFR4ZPY4GS0"%' AND refreshToken IS NOT NULL AND accessToken IS NOT NULL
Now pull ChannelData by Using ConnectionId with the following Query:
SELECT channels.integrationType AS integrationType, accounts.account_slug AS accountSlug, channels.connectionId AS connectionId, channels.externalChannelId AS externalChannelId, external_wms_channels.locationId AS locationId, warehouses.externalWarehouseId AS externalWareHouseId 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 =:connectionId GROUP BY external_wms_channels.locationId ORDER BY external_wms_channels.id ASC
Along with the ChannelData, we will also need accessToken, refresh token, and isActive flag. So we will use the following Query:
SELECT accessToken, inputFields, refreshToken,
isActive FROM ie_appinstall_connection WHERE id = :connectionId
So, now our connection_ChannelData will look like below:
Cache key: “connection_channeldata_{{connectionId}}"
{
"channelData": {
"integrationType": "8",
"storeSlug": "",
"externalChannelId": "CH1200",
"accountSlug": "eshop",
"connectionId": "361",
"location": {
"804cde7b-bd2f-4a3e-923c-386715089fa1": "MJPAT_109",
"8fc83148-5b97-49cf-b724-7c46d50946aa": "ESBBLR_111",
"d1391379-8283-4335-a43c-0a2eb2fe2d21": "ESBMUM_112"
},
"accessToken": "Atza|IwEBIBmnRqef-YkpJOZ_b0ov2wWiCgrazw-N1iXQM0a46K7K5gl4D30Mb-LGVPR_dXQ74Os0mAFlWp8yLgqW9TEsFVsmsIhk3uFF_N4LK1mfWTv45LpgxmVHV4HhpAGuzNc8qClptpUMP-cuc_0xwfMK_K83jFNE0zaIpVL4QdeYcBj_G3qusKp70hXi71_6Sa5E7Khz6CH7Agx-Ur5FUQUbr2ehs-PcPlg9JPIB2fLa_lQ10bn-AWsSSqNYzJVNlrgErCqWtIxXB2Qm5Zwg2LfOIP4U1JSF2hR_OUfsBE5vRAZxVDmU8FosRWv2pHPzRJfpy8IsJChMdsegKrkzzcaoFhiZZWW2AgC1bqjC-czIozy1v3dVXWhjFFYaq7sw_gL95sr_zsPZlajR-GItSn-SqgTQcAfDlbANoGVGF1n518wDmQ",
"isActive": "active",
"refreshToken": "Atzr|IwEBIABZGnCN-010dECu9Qj3YW9B93ZO5IL2bKJIjEIRbmIYyJPYRb4_-wEoblKGt8DzaFTp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NDQ4MzEsImV4cCI6MTYzNDYzNjgzMSwiYXpwIjoiUXpWTzdmSGsySFl4Mlk1YjNXRG9pRHVHZTR2Q3dqSFAiLCJzY29wZSI6InJlYWQ6cHJvZHVjdHMgcmVhZDppbnZlbnRvcnkgcmVhZDpwcm9kdWN0X2xpc3RpbmdzIHdyaXRlOnByb2R1Y3RfbGlzdGluZ3MgcmVhZDpvcmRlcnMgd3JpdGU6b3JkZXJzIHJlYWQ6cmV0dXJucyB3cml0ZTpyZXR1cm5zIHJlYWQ6cGF5YWJsZXMgd3JpdGU6cGF5b3V0cyB3cml0ZTp0cmFuc2FjdGlvbl9ydWxlcyByZWFkOmN1c3RvbV9maWVsZHMgd3JpdGU6Y3VzdG9tX2ZpZWxkcyByZWFkOmxvY2F0aW9ucyB3cml0ZTpsb2NhdGlvbnMgcmVhZDpwb3J0YWwgd3JpdGU6cG9ydGFsIHJlYWQ6d29ya3NwYWNlIHJlYWQ6c2FsZXNfY2hhbm5lbCByZWFkOmZ1bGZpbGxtZW50X2NlbnRlciIsImd0eSI6InBahc3N3b3JkIn0.CqjOddltmRN_aZqNZAdKMCk7X5xJsG4j71pBAvFtbKg5uW8p-uuWLJyQ87dZgjM_9xq0mi3BxTHO2IYbNDX6xiD9F8H4Y9uCVUW7gmSOdfLcFzeNgLggiUo8hHi_pJK1HgZRspxA76ld0w97xNQAYbZpyl3cc-wdgIyrUO-kpoYetcZ2PW5fHYqQMLwh75OpnsGtsAekKcaOVcqVvSF1WfDNYDtV4H9lfKe0IzNFDQ8WQ18DSjvwvWWDSxQxSG9BTVa8d3NPKnEyTAhH9yeZTe6FCBk9T_8fwzbTaehZ_wvUFfYooQLMUCTUalQxjjOLiCiIZ4GDwF8ogOCMbLF0bA"
}
}
Now we will check whether the Return created belongs to the Location we have mapped or not. To do this, we need to compare the LocationId from the Return Event to the LocationId given in the connection_ChannelData. If matches then proceed further.
Step 3 : Now fetch Return Event Details using Return ID :
https://api.prod.dub.yojaka.xp.sellers.a2z.com/v1/returns/55b0bbd3-6b9f-4b27-85d5-b625d460d6eb
Response:
{
"id": "55b0bbd3-6b9f-4b27-85d5-b625d460d6eb",
"returnLocationId": "899e2072-e5d7-4bb8-8ad6-4d04214d25b3",
"merchantSku": "Premium-Broken-Walnut-200g",
"numberOfUnits": "1",
"fulfillmentLocationId": "899e2072-e5d7-4bb8-8ad6-4d04214d25b3",
"returnType": "REJECT",
"returnStatus": "IN_TRANSIT",
"creationTimestamp": 1691284707131,
"lastUpdatedTimestamp": 1691397659864,
"returnMetadata": {
"returnReason": "REJECT",
"fulfillmentOrderId": "e77bf445-bc1e-4de5-9eb2-d228b56b23e0",
"rmaId": "",
"invoiceInfo": {
"invoiceId": "XGMS-8058"
}
},
"returnShippingInfo": {
"forwardTrackingInfo": {
"trackingId": "326533604738",
"carrierName": "ATS"
},
"reverseTrackingInfo": {
"trackingId": "626024994448",
"carrierName": "ATS"
}
},
"returnMarketplaceChannelDetails": {
"marketplaceChannel": {
"marketplaceName": "AMAZON_IN",
"channelName": "FBA"
},
"merchantId": "A3VDH5TGHO7F3K",
"shipmentId": "UCqSPFYHM",
"customerOrderId": "404-6663958-8829169",
"returnLocationId": "XGMS",
"channelSku": "Premium-Broken-Walnut-200g"
},
"returnedWithOTP": false,
"replanned": true,
"replacement": false,
"exchange": false,
"previousTrackingInfo": [
{
"trackingId": "326533604738",
"carrierName": "ATS"
}
]
}
Note: Here a new filed "previousTrackingInfo" has been generated, It will help us in Updating new trackingId
based on Previous trackingId
Step 4 : Once the Detailed Return Response is retrieved, Prepare QueueData which will be sent to Amzprime-Order Service for Transformation. It will look like this as given below ( Step 1 : AMAZON TRANSFORMATION LAYER SERVICE : Repo = esb-amzprime-order-service)
Important check : make sure event contains “reverseTrackingInfo
" exists and the map must be non-empty then push the event to Middle Layer, Otherwise simply Ignore the flow.(To avoid un-neccessary Query Calling, and Null Pointer exception)
AMAZON RETURN UPDATE TRANSFORMATION LAYER SERVICE : Repo = esb-amzprime-order-service
ENDPOINT : _ah/api/esb/v2/return/update
Step 5: In the middle layer we receive QueData from Pubsub looks like below map:
{
"queueData": {
"channelData": {
"integrationType": "8",
"storeSlug": "",
"externalChannelId": "CH1200",
"accountSlug": "eshop",
"connectionId": "361",
"location": {
"804cde7b-bd2f-4a3e-923c-386715089fa1": "OZiva_DL",
"8fc83148-5b97-49cf-b724-7c46d50946aa": "Bangalore_FC",
"3f5f6b03-a3fe-4319-a504-18083b87a5d8": "Kolkata_FC",
"d1391379-8283-4335-a43c-0a2eb2fe2d21": "Eshopbox_Mumbai"
},
"accessToken": "Atza|IwEBIPr3r0ZeuHDcc5hnfvfkPMKZwXVino5qbnqKVDqfP_t4NqK7-Mm5N0smlWJjheB-Q1BWUuBn1dPYY7lyqkG-y6MTgU28ySc-KHJPIwmnS-g-omDyXB-QBjPwd153EKAZ36udZ71BcYKA3TlJ2tzoUvhjr_S4bmYY7rxi234vCNLvD4X20tbXw7TWRPGjy8139Zk1rF3LbAKHZfSdlWQKcxIg1bL6duIHOJOQKnpRcLjYXK3QWAlvKco1quN54Ml4kgr721MdDxASRLbMd3o2OnlsgguZGeY4rmMnkmJrBzHghO5ZnPVG3ym2pHtZKDc6PLAt2SZ3h_1KvMuhECYmTUaKY1oliG0fOpXPMKN7sLgERThs34ZmgH5Ssw6oy1-7BpmSz8h-IzacxGl9txmygyXLwC7zh_3Whpa4y8173WlqlPSvwtwW02n_7_uqU34CnD8ZEofFCbcNixa5oj1kG4GT",
"isActive": "active",
"refreshToken": "Atzr|IwEBID0gzqmFd6UNdlbgliNXEXS_Ci0sRkpeMZd6WzwLD7na3J6ok0t1-h3oqp5VyqIoF7drcsKG81MvRKcicDYbdPle8wA8Uu1hHs7di-fBX4iOfitbWSBGKbkFJy8xAbgEmszrA9nsRNDF3F5rAj-APhfdgjmtSZiPBl3hvwKab2n6sn9uEcU71F7k4hJbwj7WX7R_JkNFZ25qXqWPkmT_N5U7OhqA8OA5LQONKE67Sa817Q1GBQvc_r_vPMeYB8dkjgEPMn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cmVhZDpwcm9kdWN0X2xpc3RpbmdzIHdyaXRlOnByb2R1Y3RfbGlzdGluZ3MgcmVhZDpvcmRlcnMgd3JpdGU6b3JkZXJzIHJlYWQ6cmV0dXJucyB3cml0ZTpyZXR1cm5zIHJlYWQ6cGF5YWJsZXMgd3JpdGU6cGF5b3V0cyB3cml0ZTp0cmFuc2FjdGlvbl9ydWxlcyByZWFkOmN1c3RvbV9maWVsZHMgd3JpdGU6Y3VzdG9tX2ZpZWxkcyByZWFkOmxvY2F0aW9ucyB3cml0ZTpsb2NhdGlvbnMgcmVhZDpwb3J0YWwgd3JpdGU6cG9ydGFsIHJlYWQ6d29ya3NwYWNlIHJlYWQ6c2FsZXNfY2hhbm5lbCByZWFkOmZ1bGZpbGxtZW50X2NlbnRlciIsImd0eSI6InBhc3N3b3JkIn0.Y1DX81ttuT-O4h1lGqkloDhIqD3nAAb90a8jTzhNpFgEa2E7Si4Qfd_mw6a5kkQGQxZQkJ0LQdOmORjeFtebMI1lHo_TGb7UUDM3f53f3h1hKEyCMTHIVmZSP8YuwSy_EPNhknftNSKl82HJULoheKn3tJFC9frLgWR334laTvPH7mz-R-FG1zuF8Mwaf8wmIjZlXmYSOTgKR1VqddTe2qNCp8koSfeN0Y7STlMBG2khunBCdrDYjcD05YQTC2T3g80bg_r1jnj9KnyAGtCGgjM4cDJazI1H06OcFVeHn3c3dW8cWu6ha1C-7cCoRB53L5vsXSOjkd1b3b8ROSbxlw"
},
"orderDetail": {
"creationTimestamp": 1.673934731735E12,
"fulfillmentLocationId": "d1391379-8283-4335-a43c-0a2eb2fe2d21",
"id": "cba2347d-f795-45be-91f5-4fb9dcfe761e",
"lastUpdatedTimestamp": 1.673934732563E12,
"merchantSku": "42MLC3GY0HB",
"numberOfUnits": 1.0,
"returnLocationId": "d1391379-8283-4335-a43c-0a2eb2fe2d21",
"returnMarketplaceChannelDetails": {
"channelSku": "42MLC3GY0HB",
"customerOrderId": "406-0266493-6139564",
"marketplaceChannel": {
"channelName": "FBA",
"marketplaceName": "AMAZON_IN"
},
"merchantId": "A2L90Y54FJK6W9",
"returnLocationId": "XWRA",
"shipmentId": "U67ybTLPv"
},
"returnMetadata": {
"fulfillmentOrderId": "eb58b6c8-2fc8-4107-9ac4-2ae45af64e6f",
"invoiceInfo": {},
"returnReason": "Defective/Does not work properly",
"rmaId": "DG0ByZpsRRMA"
},
"returnShippingInfo": {
"forwardTrackingInfo": {
"carrierName": "ATS",
"trackingId": "321534361376"
},
"reverseTrackingInfo": {
"carrierName": "ATSIN",
"trackingId": "625435090930"
}
},
"returnStatus": "IN_TRANSIT",
"returnType": "CUSTOMER",
"previousTrackingInfo": [
{
"trackingId": "326533604738",
"carrierName": "ATS"
}
]
}
}
}
Step 6: Fetch fulfillmentOrderId
: CustomerOrderNumber, externalChannelID, marchantId : itemId
and Check in Eshopbox if return created or not using externalChannelID, CustomerOrderNumber, itemId:
SELECT
return_shipments.customerReturnNumber,
return_shipments.trackingID,
orders.customerOrderNumber,
orders.vendorOrderNumber,
order_items.lineItemSequenceNumber,
order_items.returnFlag,
order_items.return_shipment_id
FROM
return_shipments
LEFT JOIN
order_items
ON order_items.return_shipment_id = return_shipments.id
LEFT JOIN
orders
ON orders.id = order_items.order_id
LEFT JOIN
channels
ON channels.id = orders.channel_id
WHERE
channels.externalChannelID = 'CH2220' // externalchannel_id
AND orders.customerOrderNumber = 16745640561971932722 // fulfillmentOrderId
AND order_items.itemID IN //merchantSku
(
647775
)
Now we will make grouping of return flow according to return details received from DB with the returnDetails received from Amazon
Note :
Event.TrackingId = queueData.orderDetail.returnShippingInfo.ReverseTrackingInfo.trackingId
DB.TrackingId = return_shipments.trackingID (from Query)
Event.returnId = queueData.orderDetail.id
DB.returnId = return_shipments.customerReturnNumber(FromQuery)
Previous.TrcakingId = queueData.orderDetail.previousTrackingInfo.trackingId
status = queueData.orderDetail
.returnStatus
Step 7:
Case 1: when returnFlag == 0, and empty DB.TrackingId and empty DB.returnId received from DB means return not created before.
Approach :
We need to create the return first(
Amazon Return Complete Flow refer to step 7 case 1)
Then Update the return with new status = “in_transit”/”out_for_delivery”
Method PUT
https://return-dot-eshopbox-client-portal-prod.el.r.appspot.com/_ah/api/esb/v2/updateReturn/{{cust
Request Body:
{
"courierName": "ATS",
"customerReturnNumber": "55b0bbd3-6b9f-4b27-85d5-b625d460d6eb",
"type": "courier_return",
"customerOrderNumber": "e77bf445-bc1e-4de5-9eb2-d228b56b23e0",
"remarks": "REJECT",
"status": "In_transit", //new status from Event
"trackingID": "626024994448"
}
Case 2: Return update request is received with another tracking id and new status
when returnFlag == 1, DB.returnId == Event.ReturnId, DB.trackingId != Event.TrackingId, means tracking Id and status both needs to be updated.
Approach : simply call Update tracking API call ( will make a check of Previous.TrcakingId == DB.trackingId) then Event.TrackingId Id associated with Given returnId.
Method PUT:
https://return-dot-eshopbox-client-portal-prod.el.r.appspot.com/_ah/api/esb/v2/updateReturn/{{cust
Request Body :
{
"courierName": "ATS",
"customerReturnNumber": "55b0bbd3-6b9f-4b27-85d5-b625d460d6eb",
"type": "courier_return",
"customerOrderNumber": "e77bf445-bc1e-4de5-9eb2-d228b56b23e0",
"remarks": "REJECT",
"status": "In_transit", //new status from Event
"trackingID": "626024994448" // new tracking Id from event
}
Case 3: Return update request is received with new return Id and new status.
Step1: Need to create new return with the new returnId after cancelling older return Id.
refer to (Amazon Return Complete Flow Step 7, case 3)
Step 2: Update the return with new return Id and Status:
Method PUT:
https://return-dot-eshopbox-client-portal-prod.el.r.appspot.com/_ah/api/esb/v2/updateReturn/{{cust
Request Body :
{
"courierName": "ATS",
"customerReturnNumber": "55b0bbd3-6b9f-4b27-85d5-b625d460d6eb", //new returnId from event
"type": "courier_return",
"customerOrderNumber": "e77bf445-bc1e-4de5-9eb2-d228b56b23e0",
"remarks": "REJECT",
"status": "In_transit", //new status from Event
"trackingID": "626024994448" // new tracking Id from event
}
Case 4: when update received for simply updating status to “IN_TRANSIT”/”OUT_FOR_DELIVERY”
and returnFlag == 1 and DB.returnId == Event.ReturnId and event.trackingId == DB.trackingIds
Approach: Simply update the return with new status
Method PUT:
https://return-dot-eshopbox-client-portal-prod.el.r.appspot.com/_ah/api/esb/v2/updateReturn/{{cust
Request Body :
{
"courierName": "ATS",
"customerReturnNumber": "55b0bbd3-6b9f-4b27-85d5-b625d460d6eb",
"type": "courier_return",
"customerOrderNumber": "e77bf445-bc1e-4de5-9eb2-d228b56b23e0",
"remarks": "REJECT",
"status": "In_transit", //new status from Event
"trackingID": "626024994448"
}
Case 5: when “DELIVERED” status received from Amazon update simply to Amazon :
https://return-dot-eshopbox-client-portal-prod.el.r.appspot.com/_ah/api/esb/v2/updateReturn/{{cust
{
"courierName": "ATS",
"customerReturnNumber": "b22c516b-6fe2-466f-9afd-24784ebe0c13",
"type": "courier_return",
"customerOrderNumber": "0721f959-23e0-4f83-83a1-20386db315b6",
"remarks": "REJECT",
"status": "delivered",
"trackingID": "626024994448"
"returnDate": "2023-11-30 17:42:30"
}