Feat/add ninja van carrier integration#596
Feat/add ninja van carrier integration#596backendArchitect wants to merge 8 commits intokarrioapi:mainfrom
Conversation
danh91
left a comment
There was a problem hiding this comment.
The general idea is that while the bootstrap command creates the plugin file structure.
You need to navigate through the files to setup the data and implementation specific to the NinjaVan API operations and logic
| quicktype --src="${SCHEMAS}/error_response.json" --out="${LIB_MODULES}/error_response.py" | ||
| quicktype --src="${SCHEMAS}/paperless_request.json" --out="${LIB_MODULES}/paperless_request.py" | ||
| quicktype --src="${SCHEMAS}/paperless_response.json" --out="${LIB_MODULES}/paperless_response.py" | ||
| quicktype --src="${SCHEMAS}/rating_request.json" --out="${LIB_MODULES}/rating_request.py" | ||
| quicktype --src="${SCHEMAS}/rating_response.json" --out="${LIB_MODULES}/rating_response.py" | ||
| quicktype --src="${SCHEMAS}/shipping_request.json" --out="${LIB_MODULES}/shipping_request.py" | ||
| quicktype --src="${SCHEMAS}/shipping_response.json" --out="${LIB_MODULES}/shipping_response.py" | ||
| quicktype --src="${SCHEMAS}/tracking_request.json" --out="${LIB_MODULES}/tracking_request.py" | ||
| quicktype --src="${SCHEMAS}/tracking_response.json" --out="${LIB_MODULES}/tracking_response.py" | ||
| quicktype --src="${SCHEMAS}/cancel_request.json" --out="${LIB_MODULES}/cancel_request.py" | ||
| quicktype --src="${SCHEMAS}/cancel_response.json" --out="${LIB_MODULES}/cancel_response.py" |
There was a problem hiding this comment.
The JSON files referenced here need to be from the NinjaVan API.
https://api-docs.ninjavan.co/en
|
|
||
| def get_rates(self, request: lib.Serializable) -> lib.Deserializable[str]: | ||
| response = lib.request( | ||
| url=f"{self.settings.server_url}/service", |
There was a problem hiding this comment.
| url=f"{self.settings.server_url}/service", | |
| url=f"{self.settings.server_url}/1.0/public/price", |
This and all the subsequent API requests needs to be based on the corresponding operation from the NinjaVan API.
By example, this one is the Tariff API
|
|
||
| def create_shipment(self, request: lib.Serializable) -> lib.Deserializable[str]: | ||
| response = lib.request( | ||
| url=f"{self.settings.server_url}/service", |
There was a problem hiding this comment.
Similarly, this one needs to be updated to reflect the Order API
| url=f"{self.settings.server_url}/service", | |
| url=f"{self.settings.server_url}/4.2/orders", |
|
|
||
| def cancel_shipment(self, request: lib.Serializable) -> lib.Deserializable[str]: | ||
| response = lib.request( | ||
| url=f"{self.settings.server_url}/service", |
|
|
||
| def get_tracking(self, request: lib.Serializable) -> lib.Deserializable[str]: | ||
| response = lib.request( | ||
| url=f"{self.settings.server_url}/service", |
| gateway = karrio.gateway["ninja_van"].create( | ||
| dict( | ||
| # add required carrier API setting key/value here | ||
| ) | ||
| ) |
There was a problem hiding this comment.
| gateway = karrio.gateway["ninja_van"].create( | |
| dict( | |
| # add required carrier API setting key/value here | |
| ) | |
| ) | |
| gateway = karrio.gateway["ninja_van"].create( | |
| dict( | |
| client_id="client_id", | |
| client_secret="client_secret", | |
| ) | |
| ) |
| ParsedRateResponse = [] | ||
|
|
||
|
|
||
| RateRequest = {} | ||
|
|
||
| RateResponse = """{} | ||
| """ |
There was a problem hiding this comment.
For the tests, you want to run them and ensure that essentially when a request is created, you get the right output data that needs to be sent to NinjaVan
Sendle is a good example here https://github.com/karrioapi/karrio/blob/main/modules/connectors/sendle/tests/sendle/test_rate.py
| ShipmentCancelPayload = { | ||
| "shipment_identifier": "794947717776", | ||
| } | ||
|
|
||
| ParsedShipmentResponse = [] | ||
|
|
||
| ParsedCancelShipmentResponse = [] | ||
|
|
||
|
|
||
| ShipmentRequest = {} | ||
|
|
||
| ShipmentCancelRequest = {} | ||
|
|
||
| ShipmentResponse = """{} | ||
| """ | ||
|
|
||
| ShipmentCancelResponse = """{} | ||
| """ |
There was a problem hiding this comment.
Same comment about the tests above
| ParsedTrackingResponse = [] | ||
|
|
||
| ParsedErrorResponse = [] | ||
|
|
||
|
|
||
| TrackingRequest = {} | ||
|
|
||
| TrackingResponse = """{} | ||
| """ | ||
|
|
||
| ErrorResponse = """{} | ||
| """ |
| api_key = models.CharField(max_length=100, blank=True, null=True) | ||
| secret_key = models.CharField(max_length=100, blank=True, null=True) | ||
| track_api_key = models.CharField(max_length=100, blank=True, null=True) | ||
| track_secret_key = models.CharField(max_length=100, blank=True, null=True) | ||
| account_number = models.CharField(max_length=50, blank=True, null=True) | ||
| account_country_code = models.CharField( | ||
| max_length=3, blank=True, null=True, choices=providers.COUNTRIES | ||
| ) |
There was a problem hiding this comment.
You need to replace these the the client_id and client_secret that NinjaVan support
|
ThankYou so much @danh91 for detailed review and guide |
|
Hello @danh91 I wrote mannual migration |
Can you share more details? |
Changes
Feat: