Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add ninja van carrier integration #596

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

codeArtisanry
Copy link
Contributor

Changes


Feat:

  • Add NinjaVan Integration

Copy link
Member

@danh91 danh91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines 13 to 23
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, this one needs to be updated to reflect the Order API

Suggested change
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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here


def get_tracking(self, request: lib.Serializable) -> lib.Deserializable[str]:
response = lib.request(
url=f"{self.settings.server_url}/service",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this one for tracking

Comment on lines +4 to +8
gateway = karrio.gateway["ninja_van"].create(
dict(
# add required carrier API setting key/value here
)
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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",
)
)

Comment on lines +78 to +84
ParsedRateResponse = []


RateRequest = {}

RateResponse = """{}
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +112 to +129
ShipmentCancelPayload = {
"shipment_identifier": "794947717776",
}

ParsedShipmentResponse = []

ParsedCancelShipmentResponse = []


ShipmentRequest = {}

ShipmentCancelRequest = {}

ShipmentResponse = """{}
"""

ShipmentCancelResponse = """{}
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about the tests above

Comment on lines +62 to +73
ParsedTrackingResponse = []

ParsedErrorResponse = []


TrackingRequest = {}

TrackingResponse = """{}
"""

ErrorResponse = """{}
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Comment on lines +11 to +18
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
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to replace these the the client_id and client_secret that NinjaVan support

@codeArtisanry
Copy link
Contributor Author

ThankYou so much @danh91 for detailed review and guide
I'll update it and let you know

@codeArtisanry
Copy link
Contributor Author

codeArtisanry commented Jun 7, 2024

Hello @danh91
I'm having trouble in generating migration file can you please help me with that ??

# Generated by Django 4.2.11 on 2024-06-07 11:53

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        ("providers", "0072_rename_eshippersettings_eshipperxmlsettings_and_more"),
    ]

    operations = [
        migrations.CreateModel(
            name="NinjaVanSettings",
            fields=[
                (
                    "carrier_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="providers.carrier",
                    ),
                ),
                ("client_id", models.CharField(max_length=255)),
                ("client_secret", models.CharField(max_length=255)),
                (
                    "grant_type",
                    models.CharField(default="client_credentials", max_length=255),
                ),
            ],
            options={
                "verbose_name": "NinjaVan Settings",
                "verbose_name_plural": "NinjaVan Settings",
                "db_table": "ninjavan_settings",
            },
            bases=("providers.carrier",),
        ),
    ]

I wrote mannual migration

@danh91
Copy link
Member

danh91 commented Jun 7, 2024

Hello @danh91

I'm having trouble in generating migration file can you please help me with that ??


# Generated by Django 4.2.11 on 2024-06-07 11:53



from django.db import migrations, models

import django.db.models.deletion





class Migration(migrations.Migration):



    dependencies = [

        ("providers", "0072_rename_eshippersettings_eshipperxmlsettings_and_more"),

    ]



    operations = [

        migrations.CreateModel(

            name="NinjaVanSettings",

            fields=[

                (

                    "carrier_ptr",

                    models.OneToOneField(

                        auto_created=True,

                        on_delete=django.db.models.deletion.CASCADE,

                        parent_link=True,

                        primary_key=True,

                        serialize=False,

                        to="providers.carrier",

                    ),

                ),

                ("client_id", models.CharField(max_length=255)),

                ("client_secret", models.CharField(max_length=255)),

                (

                    "grant_type",

                    models.CharField(default="client_credentials", max_length=255),

                ),

            ],

            options={

                "verbose_name": "NinjaVan Settings",

                "verbose_name_plural": "NinjaVan Settings",

                "db_table": "ninjavan_settings",

            },

            bases=("providers.carrier",),

        ),

    ]

I wrote mannual migration

Can you share more details?
What command did you run? Did you get any errors?
Is there any error logs you can share?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants