{
	"info": {
		"_postman_id": "7d1fbd5f-b8e1-4926-86de-bd164bd01ea3",
		"name": "LLMP /V3",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"item": [
		{
			"name": "Quotation",
			"event": [
				{
					"listen": "prerequest",
					"script": {
						"exec": [
							"let time = new Date().getTime();",
							"",
							"let twentyMinutesLater = new Date();",
							"twentyMinutesLater.setMinutes(twentyMinutesLater.getMinutes() + 20);",
							"let scheduleAt = twentyMinutesLater.toISOString();",
							"",
							"let twoHoursLater = new Date();",
							"twoHoursLater.setHours(twoHoursLater.getHours() + 2);",
							"let deliveryBy = twoHoursLater.toISOString();",
							"",
							"let body = {",
							"    \"data\":{",
							"        \"scheduleAt\": scheduleAt,",
							"        \"deliveryBy\": deliveryBy, // optional field. default to 4 hours if not passed",
							"        \"serviceType\": \"PLUS\",",
							"        \"stops\": [",
							"        {",
							"            \"coordinates\": {",
							"                \"lat\": \"22.317099174709117\",",
							"                \"lng\": \"114.190136797322\"",
							"            },",
							"            \"address\": \"Honour Building Block C, 78-80W, To Kwa Wan Rd, To Kwa Wan\"",
							"        },",
							"        {",
							"            \"coordinates\": {",
							"                \"lat\": \"22.3353139\",",
							"                \"lng\": \"114.1758402\"",
							"            },",
							"            \"address\": \"InnoCentre, 72 Tat Chee Avenue\"",
							"            }",
							"        ],",
							"        //\"deliveryStage\": \"LAST_MILE\", optional field",
							"        // \"item\": { optional field",
							"        //     \"quantity\": \"5\",",
							"        //     \"weight\": \"10\",",
							"        //     \"categories\": [",
							"        //         \"FOODORINGREDIENT\",",
							"        //         \"FURNITURE_AND_HOUSEHOLD_GOODS\"",
							"        //     ],",
							"        //     \"handlingInstructions\": [",
							"        //         \"FRAGILE_OR_HANDLE_WITH_CARE\",",
							"        //         \"KEEP_UPRIGHT\"",
							"        //     ]",
							"        // },",
							"    }",
							"}",
							"",
							"body = JSON.stringify(body);",
							"",
							"let appSecret = pm.environment.get('appSecret');",
							"let signature = CryptoJS.HmacSHA256(`${time.toString()}\\r\\nPOST\\r\\n/v3/quotations\\r\\n\\r\\n${body}`, appSecret);",
							"",
							"postman.setEnvironmentVariable('signature', signature.toString());",
							"postman.setEnvironmentVariable('time', time);",
							"postman.setEnvironmentVariable('body', body);"
						],
						"type": "text/javascript"
					}
				},
				{
					"listen": "test",
					"script": {
						"exec": [
							"const response = pm.response.json().data;",
							"pm.environment.set(\"quotationId\", response.quotationId);",
							"",
							"//Set \"scheduleAt\" and \"deliveryBy\" variable",
							"pm.environment.set(\"scheduleAt\", response.scheduleAt);",
							"pm.environment.set(\"deliveryBy\", response.deliveryBy);",
							"",
							"//Set \"stopId-0\" variable",
							"pm.environment.set(\"stopId-0\", response.stops[0].stopId);",
							"",
							"//Set \"stopId-1\" variables",
							"pm.environment.set(\"stopId-1\", response.stops[1].stopId);"
						],
						"type": "text/javascript"
					}
				}
			],
			"request": {
				"auth": {
					"type": "noauth"
				},
				"method": "POST",
				"header": [
					{
						"key": "Content-Type",
						"value": "application/json",
						"type": "text"
					},
					{
						"key": "Authorization",
						"value": "hmac {{appKey}}:{{time}}:{{signature}}",
						"type": "text"
					},
					{
						"key": "Market",
						"value": "{{market}}",
						"type": "text"
					},
					{
						"key": "Platform",
						"value": "PLUS",
						"type": "text"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{{body}}"
				},
				"url": {
					"raw": "{{hostname}}/v3/quotations",
					"host": [
						"{{hostname}}"
					],
					"path": [
						"v3",
						"quotations"
					]
				}
			},
			"response": []
		},
		{
			"name": "Orders",
			"event": [
				{
					"listen": "prerequest",
					"script": {
						"exec": [
							"let time = new Date().getTime();",
							"",
							"let body = {",
							"    \"data\":{",
							"        \"quotationId\": pm.environment.get('quotationId'), //This is from the response on POST Quotation. A Unique identifier that encapsulates each quotation and its delivery information",
							"        \"sender\": {",
							"            //Stop id Identifier for each stop returned from Lalamove. ",
							"            \"stopId\":pm.environment.get('stopId-0'),  //StopId of pick up point",
							"            \"name\": \"Brian\",  //Pick-up point contact details",
							"            \"phone\": \"+85293031007\",",
							"            \"remarks\": \"Remarks for the pick-up point\" // optional",
							"        },",
							"        \"recipients\": [{",
							"            \"stopId\": pm.environment.get('stopId-1'), //StopId of the drop-off point (#1) ",
							"            \"name\": \"Christie\", //Contact information at the drop-off point (#1)",
							"            \"phone\": \"+85293031007\",",
							"            \"remarks\":\"Plus testing\" // Additional info about the delivery. eg. building, floor and flat. Use newline \\r\\n for better readability. Up to 1500 characters.",
							"        }],",
							"        \"clientRef\": \"PARCEL_TRACKING_NUMBER\", // Identifier for parcel. Used for barcode scanning",
							"        \"partner\": \"CLIENT_1\", //optional - Specify Partner's name for effective tracking and organization,",
							"        \"metadata\": {",
							"           \"clientID\": \"THIS_IS_FOR_CLIENT\",",
							"        } // optional field",
							"    }",
							"}",
							"",
							"body = JSON.stringify(body);",
							"",
							"let appSecret = pm.environment.get('appSecret');",
							"let signature = CryptoJS.HmacSHA256(`${time.toString()}\\r\\nPOST\\r\\n/v3/orders\\r\\n\\r\\n${body}`, appSecret);",
							"",
							"postman.setEnvironmentVariable('time', time);",
							"postman.setEnvironmentVariable('body', body);",
							"postman.setEnvironmentVariable('signature', signature.toString());"
						],
						"type": "text/javascript"
					}
				},
				{
					"listen": "test",
					"script": {
						"exec": [
							"const response = pm.response.json().data;",
							"",
							"//Set \"orderId\" variable",
							"pm.environment.set(\"orderId\", response.orderId);"
						],
						"type": "text/javascript"
					}
				}
			],
			"request": {
				"auth": {
					"type": "noauth"
				},
				"method": "POST",
				"header": [
					{
						"key": "Content-Type",
						"value": "application/json",
						"type": "text"
					},
					{
						"key": "Authorization",
						"value": "hmac {{appKey}}:{{time}}:{{signature}}",
						"type": "text"
					},
					{
						"key": "Market",
						"value": "{{market}}",
						"type": "text"
					},
					{
						"key": "Platform",
						"value": "PLUS",
						"type": "text"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{{body}}"
				},
				"url": {
					"raw": "{{hostname}}/v3/orders",
					"host": [
						"{{hostname}}"
					],
					"path": [
						"v3",
						"orders"
					]
				}
			},
			"response": []
		},
		{
			"name": "Orders",
			"event": [
				{
					"listen": "prerequest",
					"script": {
						"exec": [
							"let time = new Date().getTime();",
							"",
							"let body = {};",
							"",
							"let orderId = pm.environment.get('orderId');",
							"let appSecret = pm.environment.get('appSecret');",
							"body = JSON.stringify(body);",
							"",
							"let signature = CryptoJS.HmacSHA256(`${time.toString()}\\r\\nGET\\r\\n/v3/orders/${orderId}\\r\\n\\r\\n`, appSecret);",
							"",
							"postman.setEnvironmentVariable('signature', signature.toString());",
							"postman.setEnvironmentVariable('time', time);",
							"postman.setEnvironmentVariable('body', body);",
							"postman.setEnvironmentVariable('orderId', orderId);"
						],
						"type": "text/javascript"
					}
				}
			],
			"protocolProfileBehavior": {
				"disableBodyPruning": true
			},
			"request": {
				"auth": {
					"type": "noauth"
				},
				"method": "GET",
				"header": [
					{
						"key": "Content-Type",
						"value": "application/json",
						"type": "text"
					},
					{
						"key": "Authorization",
						"value": "hmac {{appKey}}:{{time}}:{{signature}}",
						"type": "text"
					},
					{
						"key": "Market",
						"value": "{{market}}",
						"type": "text"
					},
					{
						"key": "Platform",
						"value": "PLUS",
						"type": "text"
					}
				],
				"body": {
					"mode": "raw",
					"raw": ""
				},
				"url": {
					"raw": "{{hostname}}/v3/orders/:orderId",
					"host": [
						"{{hostname}}"
					],
					"path": [
						"v3",
						"orders",
						":orderId"
					],
					"variable": [
						{
							"key": "orderId",
							"value": "{{orderId}}"
						}
					]
				}
			},
			"response": []
		},
		{
			"name": "Edit Order",
			"event": [
				{
					"listen": "prerequest",
					"script": {
						"exec": [
							"let time = new Date().getTime();",
							"",
							"//new value of \"scheduleAt\"",
							"let fiveHoursLater = new Date();",
							"fiveHoursLater.setHours(fiveHoursLater.getHours() + 5);",
							"let newScheduleAt = fiveHoursLater.toISOString();",
							"",
							"//new value of \"deliveryBy\"",
							"let eightHoursLater = new Date();",
							"eightHoursLater.setHours(eightHoursLater.getHours() + 8);",
							"let newDeliveryBy = eightHoursLater.toISOString();",
							"",
							"let orderId = pm.environment.get('orderId');",
							"",
							"let body = {",
							"    \"data\": {",
							"        \"scheduleAt\": newScheduleAt,",
							"        \"deliveryBy\": newDeliveryBy,",
							"        \"stops\": [",
							"            {",
							"                \"coordinates\": {",
							"                    \"lat\": \"22.322492\",",
							"                    \"lng\": \"114.217242\"",
							"                },",
							"                \"address\": \"九龍牛頭角安基苑商業中心地下及1樓\",",
							"                \"name\": \"Annie\",",
							"                \"phone\": \"65971098\",",
							"                \"remarks\": \"Patch-A-Remark\"",
							"            },",
							"            {",
							"                \"coordinates\": {",
							"                    \"lat\": \"22.3242426\",",
							"                    \"lng\": \"114.2176995\"",
							"                },",
							"                \"address\": \"淘大花園S座, 香港牛頭角牛頭角道77號淘大花園S座 5樓04室\",",
							"                \"name\": \"Becky\",",
							"                \"phone\": \"12345678\",",
							"                \"remarks\": \"Patch-B-Remark\"",
							"            },",
							"        ],",
							"        // \"item\": { optional field",
							"        //     \"quantity\": \"12\",",
							"        //     \"weight\": \"2.5\",",
							"        //     \"categories\":[",
							"        //         \"FOOD_DELIVERY\",",
							"        //         \"OFFICE_ITEM\"",
							"        //     ],",
							"        //     \"handlingInstructions\":[",
							"        //         \"KEEP_UPRIGHT\"",
							"        //     ]",
							"        // },",
							"        // \"metadata\": {\"name\": \"123\"}  optional field",
							"    }",
							"}",
							"",
							"body = JSON.stringify(body);",
							"",
							"let appSecret = pm.environment.get('appSecret');",
							"let signature = CryptoJS.HmacSHA256(`${time.toString()}\\r\\nPATCH\\r\\n/v3/orders/${orderId}\\r\\n\\r\\n${body}`, appSecret);",
							"",
							"postman.setEnvironmentVariable('time', time);",
							"postman.setEnvironmentVariable('body', body);",
							"postman.setEnvironmentVariable('signature', signature.toString());"
						],
						"type": "text/javascript"
					}
				}
			],
			"request": {
				"auth": {
					"type": "noauth"
				},
				"method": "PATCH",
				"header": [
					{
						"key": "Content-Type",
						"value": "application/json",
						"type": "text"
					},
					{
						"key": "Authorization",
						"value": "hmac {{appKey}}:{{time}}:{{signature}}",
						"type": "text"
					},
					{
						"key": "Market",
						"value": "{{market}}",
						"type": "text"
					},
					{
						"key": "Platform",
						"value": "PLUS",
						"type": "text"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{{body}}"
				},
				"url": {
					"raw": "{{hostname}}/v3/orders/:orderId",
					"host": [
						"{{hostname}}"
					],
					"path": [
						"v3",
						"orders",
						":orderId"
					],
					"variable": [
						{
							"key": "orderId",
							"value": "{{orderId}}"
						}
					]
				}
			},
			"response": []
		},
		{
			"name": "Cancel Order",
			"event": [
				{
					"listen": "prerequest",
					"script": {
						"exec": [
							"let time = new Date().getTime();",
							"",
							"let body = {};",
							"let orderId = pm.environment.get('orderId');",
							"let appSecret = pm.environment.get('appSecret');",
							"",
							"body = JSON.stringify(body);",
							"",
							"let signature = CryptoJS.HmacSHA256(`${time.toString()}\\r\\nDELETE\\r\\n/v3/orders/${orderId}\\r\\n\\r\\n${body}`, appSecret);",
							"",
							"postman.setEnvironmentVariable('signature', signature.toString());",
							"postman.setEnvironmentVariable('time', time);",
							"postman.setEnvironmentVariable('body', body);"
						],
						"type": "text/javascript"
					}
				}
			],
			"request": {
				"auth": {
					"type": "noauth"
				},
				"method": "DELETE",
				"header": [
					{
						"key": "Content-Type",
						"value": "application/json",
						"type": "text"
					},
					{
						"key": "Authorization",
						"value": "hmac {{appKey}}:{{time}}:{{signature}}",
						"type": "text"
					},
					{
						"key": "Market",
						"value": "{{market}}",
						"type": "text"
					},
					{
						"key": "Platform",
						"value": "PLUS",
						"type": "text"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{{body}}"
				},
				"url": {
					"raw": "{{hostname}}/v3/orders/:orderId",
					"host": [
						"{{hostname}}"
					],
					"path": [
						"v3",
						"orders",
						":orderId"
					],
					"variable": [
						{
							"key": "orderId",
							"value": "{{orderId}}"
						}
					]
				}
			},
			"response": []
		}
	]
}