---
# System prepended metadata

title: evm-3pl-aggregator Integration

---

# evm-3pl-aggregator Integration
## Existing Everpro
### Postpaid
#### Generate AWB
```plantuml
participant "everpro-order" as eo
participant "NSQ" as nsq
participant "everpro-3pl-aggregator" as 3plAgg
participant "3pl" as 3pl
database "popaket_order" as db2

activate eo
eo -> eo
note left
...
existing generate awb logic
...
end note
eo -> eo : prepare generate awb data
eo -> nsq : publish generate awb
note left
topic `create-logistic-order-*3pl_name`
end note
deactivate eo
nsq -> 3plAgg: consume genarate awb
activate 3plAgg
3plAgg -> 3pl: generate awb to 3pl
3pl --> 3plAgg: return awb data
3plAgg -> nsq : publish update awb number
note left
topic `create-order-data`
end note
deactivate 3plAgg
nsq -> eo : consume update awb number
activate eo
eo -> db2 : update status and awb
```

#### Tracking via API
```plantuml
actor "User External" as ua
participant "everpro-client-gateway" as ecg
participant "everpro-order" as eo
participant "everpro-3pl-aggregator" as 3plAgg
participant 3pl

ua -> ecg: request tracking
activate ecg
ecg -> eo: send grpc GetTracking()
activate eo
eo -> eo
note left
...
existing flow
- get order to db
- get origin location 
  to everpro-logistic-openapi service
...
end note
eo -> eo : prepare tracking data
eo -> 3plAgg : send grpc Tracking()
activate 3plAgg
3plAgg -> 3pl : send request tracking to 3pl
3pl --> 3plAgg : return response
3plAgg -> 3plAgg : mapping order status
3plAgg --> eo : return tracking data
deactivate 3plAgg
eo -> eo
note left
...
existing flow
- update last tracking status
- send last mile callback *if any*
- update order status 
    *if logistic include in whitelist*
...
end note
eo --> ecg : return tracking response
deactivate eo
ecg --> ua: return tracking response
deactivate ecg

```
#### Tracking via CMS
```plantuml
actor "User External" as ua
participant cms
participant "everpro-client-dashboard" as ecd
participant "everpro-order" as eo
participant "everpro-3pl-aggregator" as 3plAgg
participant 3pl

ua -> cms : click `Lacak`
activate cms
cms -> ecd : send request tracking
activate ecd
ecd -> eo : send grpc GetOrderDetail()
activate eo
eo -> eo
note right
...
existing flow
- get order to db
- get origin location 
  to everpro-logistic-openapi service
...
end note
eo -> eo : prepare tracking data
eo -> 3plAgg : send grpc Tracking()
activate 3plAgg
3plAgg -> 3pl : send request tracking to 3pl
3pl --> 3plAgg : return response
3plAgg -> 3plAgg : mapping order status
3plAgg --> eo : return tracking data
deactivate 3plAgg
eo -> eo
note right
...
existing flow
- update last tracking status
- send last mile callback *if any*
- update order status 
    *if logistic include in whitelist*
...
end note
eo --> ecd : return tracking response
deactivate eo
ecd --> cms: return tracking response
deactivate ecd
cms -> ua : show tracking order
deactivate cms
```
### Prepaid
#### Generate AWB Prepaid
```plantuml
participant "everpro-logistic-client" as elc
participant "everpro-logistic" as el
participant "everpro-3pl-aggregator" as 3plAgg
participant "3pl" as 3pl
database "popaket_logistic" as db1

activate elc
elc -> elc
note left
...
existing generate awb logic
...
end note
elc -> elc: prepare generate awb data
alt new generate awb
elc -> 3plAgg: send grpc generate awb
activate 3plAgg
3plAgg -> 3pl: generate awb to 3pl
3pl --> 3plAgg: return awb data
3plAgg --> elc: return awb data response
deactivate 3plAgg
else
elc -> el : send http generate awb
activate el
el -> 3pl: generate awb to 3pl
3pl --> el: return awb data
el --> elc: return awb data response
deactivate el
end

elc -> db1: update status and awb
elc -> elc
note left
...
existing generate awb logic
...
end note
```

## Purpose Solution
### Generate Token
```plantuml
participant "everpro-logistic-client/order" as evp
participant "evm-3pl-client-gateway" as evm
database "cache" as db

evp -> db : get token to redis
db --> evp : return
alt redis not found
evp -> evm : send request generate token
evm --> evp : return response
evp -> db : store token to redis
end
evp -> evp: return token
```
### Postpaid
#### Generate AWB
```plantuml
participant "everpro-order" as eo
participant "NSQ" as nsq
participant "evm-3pl-client-gateway" as evm
participant "everpro-3pl-aggregator" as 3plAgg
participant "3pl" as 3pl
database "popaket_order" as db2

activate eo
eo -> eo
note left
...
existing generate awb logic
...
end note
eo -> eo : prepare generate awb data

alt new generate awb
eo -> nsq :  publish new generate awb
note left
topic `new-create-logistic-order-*3pl_name`
end note
nsq -> eo : cosume new generate awb
eo -> eo : generate token
eo -> evm: send http generate awb
activate evm
evm-> 3pl : generate awb to 3pl
3pl--> evm: return awb data
evm --> eo: return awb data
deactivate evm
else

eo -> nsq : publish generate awb
note left
topic `create-logistic-order-*3pl_name`
end note
deactivate eo
nsq -> 3plAgg: consume genarate awb
activate 3plAgg
3plAgg -> 3pl: generate awb to 3pl
3pl --> 3plAgg: return awb data
3plAgg -> nsq : publish update awb number
note left
topic `create-order-data`
end note
deactivate 3plAgg
nsq -> eo : consume update awb number
end
eo -> db2 : update status and awb
```
#### Tracking via API
```plantuml
actor "User External" as ua
participant "everpro-client-gateway" as ecg
participant "everpro-order" as eo
participant "evm-3pl-client-gateway" as evm
participant "everpro-3pl-aggregator" as 3plAgg
participant 3pl

ua -> ecg: request tracking
activate ecg
ecg -> eo: send grpc GetTracking()
activate eo
eo -> eo
note left
...
existing flow
- get order to db
- get origin location 
  to everpro-logistic-openapi service
...
end note
eo -> eo : prepare tracking data
alt logistic include in whitelist tracking to evm-3pl-aggregator
eo -> evm: send http tracking
activate evm
evm -> 3pl : send request tracking to 3pl
3pl --> evm : return response
evm --> eo: return tracking reponse
deactivate evm
eo -> eo : mapping order status
else
eo -> 3plAgg : send grpc Tracking()
activate 3plAgg
3plAgg -> 3pl : send request tracking to 3pl
3pl --> 3plAgg : return response
3plAgg -> 3plAgg : mapping order status
3plAgg --> eo : return tracking data
deactivate 3plAgg
end
eo -> eo
note left
...
existing flow
- update last tracking status
- send last mile callback *if any*
- update order status 
    *if logistic include in whitelist*
...
end note
eo --> ecg : return tracking response
deactivate eo
ecg --> ua: return tracking response
deactivate ecg

```
#### Tracking via CMS
```plantuml
actor "User External" as ua
participant cms
participant "everpro-client-dashboard" as ecd
participant "everpro-order" as eo
participant "everpro-3pl-aggregator" as 3plAgg
participant 3pl

ua -> cms : click `Lacak`
activate cms
cms -> ecd : send request tracking
activate ecd
ecd -> eo : send grpc GetOrderDetail()
activate eo
eo -> eo
note right
...
existing flow
- get order to db
- get origin location 
  to everpro-logistic-openapi service
...
end note
eo -> eo : prepare tracking data
alt logistic include in whitelist tracking to evm-3pl-aggregator
eo -> evm: send http tracking
activate evm
evm -> 3pl : send request tracking to 3pl
3pl --> evm : return response
evm --> eo: return tracking reponse
deactivate evm
eo -> eo : mapping order status
else
eo -> 3plAgg : send grpc Tracking()
activate 3plAgg
3plAgg -> 3pl : send request tracking to 3pl
3pl --> 3plAgg : return response
3plAgg -> 3plAgg : mapping order status
3plAgg --> eo : return tracking data
deactivate 3plAgg
end
eo -> eo
note right
...
existing flow
- update last tracking status
- send last mile callback *if any*
- update order status 
    *if logistic include in whitelist*
...
end note
eo --> ecd : return tracking response
deactivate eo
ecd --> cms: return tracking response
deactivate ecd
cms -> ua : show tracking order
deactivate cms
```
### Prepaid
#### Generate AWB
```plantuml
participant "everpro-logistic-client" as elc
participant "everpro-logistic" as el
participant "everpro-3pl-aggregator" as 3plAgg
participant "evm-3pl-client-gateway" as evm
participant "3pl" as 3pl
database "popaket_logistic" as db1

activate elc
elc -> elc
note left
...
existing generate awb logic
...
end note
elc -> elc: prepare generate awb data
alt new generate awb to new logistic aggregator
elc -> elc : generate token
elc -> evm : send http generate awb
activate evm
evm -> 3pl : generate awb to 3pl
3pl --> evm : return awb data
evm --> elc : return awb data response
deactivate evm
else new generate awb to existing 3pl-aggregator
elc -> 3plAgg: send grpc generate awb
activate 3plAgg
3plAgg -> 3pl: generate awb to 3pl
3pl --> 3plAgg: return awb data
3plAgg --> elc: return awb data response
deactivate 3plAgg
else
elc -> el : send http generate awb
activate el
el -> 3pl: generate awb to 3pl
3pl --> el: return awb data
el --> elc: return awb data response
deactivate el
end
elc -> db1: update status and awb
elc -> elc
note left
...
existing generate awb logic
...
end note
```

