Skip to main content

Estimate all provider service

Get the list of providers available in the area and call estimate to each provider.

Flow: When call the api, service uses internal logic to check what provider is available.
Then, foreach provider, service send estimate request to 3 party and return the cheapest price.

URL : /api/estimate-all-delivery-provider

Method : POST

Validate Rule

    // validate from address
'from' => ['required', 'array'],
'from.store_code' => ['nullable', 'string'],
'from.name' => ['required_without:from.store_code', 'nullable', 'string'],
'from.address' => ['required_without:from.store_code', 'nullable', 'string'],
'from.ward' => ['required_without:from.store_code', 'nullable', 'string'],
'from.district' => ['required_without:from.store_code', 'nullable', 'string'],
'from.district_id' => ['nullable', 'int'],
'from.province' => ['required_without:from.store_code', 'nullable', 'string'],
'from.province_id' => ['nullable', 'int'],
'from.phone_number' => ['required_without:from.store_code', 'nullable', 'string'],
'from.lat' => ['nullable', 'string'],
'from.lng' => ['nullable', 'string'],
'from.note' => ['nullable', 'string'],

// validate to address
'to' => ['required', 'array'],
'to.store_code' => ['nullable', 'string'],
'to.name' => ['required_without:to.store_code', 'nullable', 'string'],
'to.address' => ['required_without:to.store_code', 'nullable', 'string'],
'to.ward' => ['required_without:to.store_code', 'nullable', 'string'],
'to.district' => ['required_without:to.store_code', 'nullable', 'string'],
'to.province' => ['required_without:to.store_code', 'nullable', 'string'],
'to.phone_number' => ['nullable', 'string'],
'to.lat' => ['nullable', 'string'],
'to.lng' => ['nullable', 'string'],
'to.note' => ['nullable', 'string'],
'to.cod' => ['nullable', 'numeric'],
'to.tracking_number' => ['nullable', 'string'],

// validate items
'items' => ['required', 'array'],
'items.*.name' => ['required', 'string'],
'items.*.sku' => ['required', 'string'],
'items.*.unit' => ['required', 'string'],
'items.*.price' => ['required', 'numeric'],
'items.*.quantity' => ['required', 'int'],

// validate addition information
'order_number' => ['nullable', 'string'],
'service_id' => ['nullable', 'string'],
'payment_method' => ['nullable', 'string'],
'delivery_time_type' => ['nullable', new Enum(DeliveryTimeType::class)],
'order_type' => ['nullable', new Enum(OrderType::class)],
'total_price' => ['required', 'numeric'],

It is basically like validating to create new delivery order.

Input

{
"total_price": 100000,
"from": {
"name": "Sơn",
"address": "7/28 Thành Thái",
"ward": "Phường 6",
"district": "Quận 10",
"province": "Thành phố Hồ Chí Minh",
"phone_number": "0954268777"
},
"to": {
"name": "Hải",
"address": "274 Bùi Đình Tuý",
"ward": "Phường 12",
"district": "Quận Bình Thạnh",
"province": "Thành phố Hồ Chí Minh",
"phone_number": "0954268841"
},
"items": [
{
"name": "Thuốc P00007",
"sku": "P00007",
"unit": "Hop",
"price": 50000,
"quantity": 2
}
]
}

Success Response

Code : 200 OK

Content example

{
"success": true,
"errors": null,
"errorCode": null,
"data": [
{
"name": "Ahamove",
"code": "ahamove",
"price": 35000,
"service_code": "SGN-POOL"
},
{
"name": "Viettel Post",
"code": "viettelpost",
"price": 16500,
"service_code": "PHS"
}
]
}

Error Response

Code : 400 BAD REQUEST

Content :

{
"success": false,
"errors": {
"from.province": [
"The from.province field is required when from.store code is not present."
]
},
"errorCode": "INVALID_INPUT",
"data": null
}