# ID Express Integration
## Existing Flow
### Get rates
```plantuml
participant "frontend" as fe
participant "everpro-logistic-client" as logisticclient
database "popaket_logistic" as db
participant "everpro-logistic-openapi" as openapi
database "popaket_logistic_openapi" as db2
participant "everpro-3pl-aggregator" as 3plaggregator
database "popaket_3pl_aggregator" as db3
participant "3PL" as 3pl
fe -> logisticclient : request get rate
activate logisticclient
logisticclient -> db : get 3PL location mapping
db --> logisticclient
note right
table `logistic_codes`
end note
logisticclient -> db : get 3PL discount
db --> logisticclient
note right
table `popaket_discounts`
end note
logisticclient -> db : get available 3PL services (reguler, sameday, etc)
db --> logisticclient
note right
table `logistic_rates`
end note
logisticclient -> db : get 3PL pickup time data
db --> logisticclient
note right
table `pickup_times` and pickup_time_rates
end note
logisticclient -> db : get 3PL cashback setting
db --> logisticclient
note right
table `popaket_cashbacks`
end note
logisticclient -> db : get 3PL COD setting
db --> logisticclient
note right
table `cod_fee_settings`
end note
logisticclient -> openapi : grpc get rate request
activate openapi
openapi -> db2 : check available logistics
db2 --> openapi
note right
table `logistics`
end note
openapi -> 3plaggregator : grpc get rate request
activate 3plaggregator
3plaggregator -> db3 : get weight rounding setting
db3 --> 3plaggregator
note right
table `weight_rounding_3pl`
end note
3plaggregator -> 3plaggregator : weight rounding logic
group we will working on here to implement ID Express API
3plaggregator -> 3pl : send get rate request to 3PL
activate 3pl
3pl -> 3plaggregator : return the shipment price
deactivate 3pl
end
3plaggregator -> openapi : return the rate data
deactivate 3plaggregator
openapi -> db2 : check package type setting
db2 --> openapi
note right
table `package_types`
end note
openapi -> db2 : get 3PL insurance setting
db2 --> openapi
note right
table `logistic_insurance_settings`
end note
openapi -> db2 : get 3PL available rates
db2 --> openapi
note right
table `rates`
end note
openapi -> logisticclient : return the get rate data
deactivate openapi
logisticclient -> fe : return
```
### Get Pickup Time
```plantuml
participant "frontend" as fe
participant "everpro-logistic-client" as elc
database "popaket_logistic" as db
fe -> elc : get available pickup time list
activate elc
elc -> db : get pickup time
db --> elc
elc -> db : get the holiday date
db --> elc
elc -> elc : validate the holiday,\ndont show the pickup time if today is holiday
elc -> fe : return the available pickup time
deactivate elc
```
### Generate AWB Internal
```plantuml
participant "everpro-logistic-client" as elc
participant "NSQ" as nsq
database "popaket_logistic" as db
participant "everpro-logistic" as el
participant "3PL" as 3pl
activate elc
elc -> elc
note left
...
existing create order logic
...
end note
alt is delay (especially for same day 3PL)
elc -> elc : prepare order data
elc -> nsq : produce delay generate awb data
nsq -> elc : consume delay generate awb data
end
elc -> elc : prepare generate awb data
group we will modify this part to redirect IDX to 3pl-aggregator
elc -> el : hit endpoint generate awb for specific 3PL
activate el
el -> 3pl : generate awb to 3PL
3pl -> el : return awb data
el -> elc : return awb data response
end
deactivate el
elc -> db : update status and awb
elc -> elc
note left
...
existing create order logic
...
end note
```
### Tracking
#### Tracking in CMS (used tracking V2)
```plantuml
participant "frontend" as fe
participant "everpro-logistic-client" as elc
database "popaket_logistic" as db_pl
participant "everpro-3pl-aggregator" as 3pl_aggregator
participant "everpro-logistic" as el
participant "3pl" as 3pl
participant "everpro-wallet" as ew
fe -> elc: request get tracking
note left
Tracking V2
end note
activate elc
elc -> db_pl: get order data
db_pl --> elc
elc -> db_pl: get logistic data
db_pl --> elc
elc -> elc: calculate price data for tracking response
note left
Total COD, COD Fee Percentage, etc
end note
elc -> db_pl: get location data
db_pl --> elc
elc->elc: check the logistic tracking version
alt the logistic including new tracking
elc->3pl_aggregator: grpc get tracking request
activate 3pl_aggregator
3pl_aggregator-> 3pl: send tracking request to 3pl
activate 3pl
3pl --> 3pl_aggregator: return the tracking data
deactivate 3pl
3pl_aggregator --> elc : return the tracking data
deactivate 3pl_aggregator
elc->elc: check callback condition
alt callback is not active
elc -> db_pl: update last tracking status
elc -> db_pl: update order status
end
else the logistic does not include new tracking
elc->el : request get tracking
activate el
el->3pl: send tracking request to 3pl
activate 3pl
3pl-->el: return the tracking data
deactivate 3pl
el --> elc : return the tracking data
deactivate el
end
elc -> elc: check cashback
alt if order status is completed
elc -> ew : disburse cashback
activate ew
ew --> elc
deactivate ew
else if order status is canceled or returned
elc -> ew : cancel cashback disbursement
activate ew
ew --> elc
deactivate ew
end
elc -->fe: return tracking response
```
#### Tracking in Admin (in Order Detail)
```plantuml
participant "frontend" as fe
participant "everpro-admin" as ea
participant "everpro-logistic-client" as elc
database "popaket_logistic" as db_pl
participant "everpro-3pl-aggregator" as 3pl_aggregator
participant "everpro-logistic" as el
participant "3pl" as 3pl
fe -> ea : request get order detail
ea -> elc : request get order detail
activate elc
elc -> db_pl : get order data
db_pl --> elc
alt awb number is not null
elc -> elc : check the logistic tracking version
alt the logistic including new tracking
elc->3pl_aggregator: grpc get tracking request
activate 3pl_aggregator
3pl_aggregator-> 3pl: send tracking request to 3pl
activate 3pl
3pl --> 3pl_aggregator: return the tracking data
deactivate 3pl
3pl_aggregator --> elc : return the tracking data
deactivate 3pl_aggregator
elc->elc: check callback condition
alt callback is not active
elc -> db_pl: update last tracking status
elc -> db_pl: update order status
end
else the logistic does not include new tracking
elc->el : request get tracking
activate el
el->3pl: send tracking request to 3pl
activate 3pl
3pl-->el: return the tracking data
deactivate 3pl
el --> elc : return the tracking data
deactivate el
end
end
elc --> ea: return order detail data
deactivate elc
ea --> fe : return response
```
### Cancel Order
#### Cancel Order in CMS
```plantuml
participant "frontend" as fe
participant "everpro-logistic-client" as elc
database "popaket_logistic" as db_pl
participant "slack" as s
participant "everpro-logistic" as el
participant "3PL" as 3pl
participant "everpro-wallet" as ew
fe -> elc : request cancel order
activate elc
elc -> db_pl : get order data
db_pl --> elc
elc -> elc: check if logistics can be canceled via API
alt not supported
elc -> db_pl : update order status to request cancel (401)
elc -> s : send notif request cancel to slack
elc --> fe: return response
else supported
group we will modify this part to redirect IDX to 3pl-aggregator
elc -> el: request cancel order to everpro-logistic
activate el
el -> 3pl: send cancel request to 3pl
activate 3pl
3pl --> el: return response
deactivate
el-->elc: return response
deactivate el
end
elc -> elc: check if the order has been paid
alt order has been paid
elc -> ew: cancel order wallet (Refund and cancel COD disbursement)
activate ew
ew --> elc
deactivate ew
end
elc -> db_pl: update order status to canceled (700)
elc -> ew : cancel cashback disbursement
activate ew
ew --> elc
deactivate ew
elc-->fe: return response
end
```
#### Cancel Order in Admin
```plantuml
participant "frontend" as fe
participant "everpro-admin" as ea
participant "everpro-logistic-client" as elc
database "popaket_logistic" as db_pl
participant "everpro-logistic" as el
participant "3PL" as 3pl
participant "everpro-wallet" as ew
fe -> ea : request cancel order
ea -> elc : request cancel order
activate elc
elc -> db_pl : get order data
db_pl --> elc
elc -> elc: check if logistics can be canceled via API
alt supported cancel via API
group we will modify this part to redirect IDX to 3pl-aggregator
elc -> el: request cancel order to API 3pl
activate el
el -> 3pl: send cancel request to 3pl
activate 3pl
3pl --> el: return response
deactivate
el --> elc
deactivate el
end
end
elc -> elc: check if the order has been paid
alt order has been paid
elc -> ew: cancel order wallet (Refund and cancel COD disbursement)
activate ew
ew --> elc
deactivate ew
end
elc -> db_pl: update order status to canceled (700)
elc -> db_pl: insert order status logging via NSQ
elc -> ew : cancel cashback disbursement
activate ew
ew --> elc
deactivate ew
elc --> ea: return response
deactivate elc
ea --> fe: return response
```
## New Flow
### Generate AWB Internal
```plantuml
participant "everpro-logistic-client" as elc
participant "NSQ" as nsq
database "popaket_logistic" as db
participant "everpro-3pl-aggregator" as 3plaggregator
participant "everpro-logistic" as el
participant "3PL" as 3pl
activate elc
elc -> elc
note left
...
existing create order logic
...
end note
alt is delay (especially for same day 3PL)
elc -> elc : prepare order data
elc -> nsq : produce delay generate awb data
nsq -> elc : consume delay generate awb data
end
elc -> elc : prepare generate awb data
alt is ID Express
elc -> 3plaggregator : send grpc generate AWB
activate 3plaggregator
3plaggregator -> 3pl : generate awb to 3PL
3pl -> 3plaggregator : return awb data
3plaggregator -> elc : return awb data response
deactivate 3plaggregator
elc -> db : save the sortingCode from ID Express
else
elc -> el : hit endpoint generate awb for specific 3PL
activate el
el -> 3pl : generate awb to 3PL
3pl -> el : return awb data
el -> elc : return awb data response
deactivate el
end
elc -> db : update status and awb
elc -> elc
note left
...
existing create order logic
...
end note
```
### Get Rates
```plantuml
participant "everpro-logistic-client" as elc
participant "everpro-logistic-openapi" as openapi
participant "everpro-3pl-aggregator" as 3plaggregator
participant "3PL" as 3pl
database "popaket_3pl_aggregator" as db3
elc -> openapi : get rate request
activate openapi
openapi -> 3plaggregator : grpc get rate request
activate 3plaggregator
3plaggregator -> db3 : get weight rounding setting
db3 --> 3plaggregator
note right
table `weight_rounding_3pl`
end note
3plaggregator -> 3plaggregator : weight rounding logic
group goroutine 1 to get the standard rate
3plaggregator -> 3pl : send get rate Standard request to 3PL
activate 3pl
3pl -> 3plaggregator : return the shipment price
deactivate 3pl
end
group goroutine 1 to get the cargo rate
3plaggregator -> 3pl : send get rate Cargo request to 3PL
activate 3pl
3pl -> 3plaggregator : return the shipment price
deactivate 3pl
end
3plaggregator -> 3plaggregator : combine the data into 1 array
3plaggregator -> openapi : return the rate data
deactivate 3plaggregator
openapi -> elc : get rate response
deactivate openapi
```
#### Get Rates iDLite
```plantuml
participant "everpro-logistic-client" as elc
participant "everpro-logistic-openapi" as openapi
participant "everpro-3pl-aggregator" as 3plaggregator
participant "3PL" as 3pl
database "popaket_logistic" as db
elc -> openapi : get rate request
activate openapi
openapi -> 3plaggregator : grpc get rate request
activate 3plaggregator
3plaggregator -> db : get location mapping
note right
add column isSupportIdLite
end note
db --> 3plaggregator
group goroutine 1 to get the standard rate
3plaggregator -> 3pl : send get rate Standard request to 3PL
activate 3pl
3pl -> 3plaggregator : return the shipment price
note right
if weight <= 0.504 kg the IDX should return iDLite rate price
if weight >= 0.505 kg the IDX should return iDSTD rate price
end note
deactivate 3pl
note left
set the rateCode to `iDLite` if weight <= 0.504 kg and isSupportIdLite is true
end note
end
group goroutine 1 to get the cargo rate
3plaggregator -> 3pl : send get rate Cargo request to 3PL
activate 3pl
3pl -> 3plaggregator : return the shipment price
deactivate 3pl
end
3plaggregator -> 3plaggregator : combine the data into 1 array
3plaggregator -> openapi : return the rate data
deactivate 3plaggregator
openapi -> elc : get rate response
deactivate openapi
```
### Tracking
```plantuml
participant "everpro-logistic-client" as elc
database "popaket_logistic" as db_pl
participant "everpro-3pl-aggregator" as 3pl_aggregator
participant "everpro-logistic" as el
participant "everpro-wallet" as ew
activate elc
elc -> db_pl: get order data
db_pl --> elc
elc -> db_pl: get logistic data
db_pl --> elc
elc -> elc: calculate price data for tracking response
note left
Total COD, COD Fee Percentage, etc
end note
elc -> db_pl: get location data
db_pl --> elc
elc->elc: check the logistic tracking version
alt the logistic including new tracking
elc->3pl_aggregator: grpc get tracking request
activate 3pl_aggregator
3pl_aggregator-> 3pl: send tracking request to 3pl
activate 3pl
3pl --> 3pl_aggregator: return the tracking data
deactivate 3pl
3pl_aggregator --> elc : return the tracking data
deactivate 3pl_aggregator
elc->elc: check callback condition
alt callback is not active
elc -> db_pl: update last tracking status
elc -> db_pl: update order status
end
end
elc -> elc: check cashback
alt if order status is completed
elc -> ew : disburse cashback
activate ew
ew --> elc
deactivate ew
else if order status is canceled or returned
elc -> ew : cancel cashback disbursement
activate ew
ew --> elc
deactivate ew
end
```
### Get Pickup Time
```plantuml
participant "frontend" as fe
participant "everpro-logistic-client" as elc
database "popaket_logistic" as db
fe -> elc : get available pickup time list
activate elc
elc -> db : get pickup time
db --> elc
elc -> elc : add validation for ID Express
note left
show only pickup time 1,5 hour from now
end note
elc -> db : get the holiday date
db --> elc
elc -> elc : validate the holiday,\ndont show the pickup time if today is holiday
elc -> fe : return the available pickup time
deactivate elc
```
### Webhook
```plantuml
participant "3pl" as 3pl
participant "everpro-logistic" as el
participant "NSQ" as nsq
participant "everpro-loigistic-client" as elc
database "popaket_logistic" as db_pl
participant "everpro-wallet" as ew
participant "everpro-3pl-aggregator" as 3pl_aggregator
database "popaket_3pl_aggregator" as db_3plAgg
3pl -> el : send callback tracking
activate el
el -> nsq : produce callback update status
el --> 3pl: return response
deactivate el
nsq -> elc : consume callback update status
activate elc
elc -> elc : check callback condition
alt if callback is activate
elc -> db_pl : get order data
db_pl --> elc
elc -> db_pl : update last tracking status
elc -> db_pl : update order status
elc -> elc : calculate ERP
elc -> db_pl : update order ERP
elc -> elc: check cashback
alt if order status is completed
elc -> ew : disburse cashback
activate ew
ew --> elc
deactivate ew
else if order status is canceled or returned
elc -> ew : cancel cashback disbursement
activate ew
ew --> elc
deactivate ew
end
end
deactivate elc
nsq -> 3pl_aggregator: consume callback update status
activate 3pl_aggregator
3pl_aggregator -> db_3plAgg : insert callback status log
```
### Bulk Create Order
#### Validate Excel
```plantuml
participant "everpro-logistic-client" as elc
database "popaket_logistic" as db
elc -> elc :
note left
existing process
end note
group loop the orders
alt if the logistic is ID Express
elc -> db : get the available pickup time 2 hour from now
db --> elc
else
elc -> elc : pickup start time is 30 minutes from now\npickup end time is 3 hour from now
end
elc -> elc
note right
... existing process
end note
end
```
### Cancel Order
```plantuml
participant "frontend" as fe
participant "everpro-logistic-client" as elc
database "popaket_logistic" as db_pl
participant "everpro-logistic" as el
participant "everpro-3pl-aggregator" as 3pl_agg
participant "3PL" as 3pl
fe -> elc : request cancel order
activate elc
elc -> elc :
note right
existing cancel order logic
end note
alt is ID Express
elc -> 3pl_agg: send grpc cancel order request
activate 3pl_agg
3pl_agg -> 3pl : send cancel request to 3pl
3pl --> 3pl_agg : return response
deactivate 3pl_agg
3pl_agg --> elc : return response
else
elc -> el: request cancel order to everpro-logistic
activate el
el -> 3pl: send cancel request to 3pl
activate 3pl
3pl --> el: return response
deactivate
el-->elc: return response
deactivate el
end
elc -> db_pl: update order status to canceled (700)
elc -> elc :
note left
existing cancel order logic
end note
elc-->fe: return response
```
### Order List V2
```plantuml
participant "everpro-logistic-client" as elc
database popaket_logistic as db_pl
elc -> elc :
note left
existing proccess
end note
elc -> db_pl: get order data
note right
get new data `logistic_reference_number`
end note
db_pl --> elc: return data
elc -> elc :
note right
existing proccess
end note
```
### Print Label in Admin dashboard
```plantuml
participant "everpro-logistic-client" as elc
database "popaket_logistic" as db_pl
elc -> elc :
note left
existing proccess
end note
elc -> db_pl: get order data
note right
get new data `logistic_reference_number`
end note
db_pl --> elc: return data
elc->elc: get template label
note right
create a new template for ID Express
end note
elc -> elc :
note left
existing proccess
end note
```