Giter Club home page Giter Club logo

delivery-nodejs-sdk's Introduction

Lalamove's Delivery SDK

Prerequisites:

  1. NodeJs
  2. NPM
  3. Typescript

To install the dependencies and build the SDK run make build

To test the SDK locally:

  1. Run make test
  2. Now you should be able to import the SDK to your Nodejs files in /testing directory (ex. const delivery_sdk = require('@lalamove/lalamove-js');)

To format code and show the styling problems run make format


Usage

Initialize SDK Client

You can specify the environment in a config object SDKClient.Config. By default it will initialize client for sandbox env. To use it for production just pass production string.

    const SDKClient = require("@lalamove/lalamove-js");

    const sdkClient = new SDKClient.ClientModule(
        new SDKClient.Config(
            "public_key",
            "secret_key",
            "sandbox"
        )
    );

Quotation

sdkClient.Quotation

Create quotation

To create new quotation for your order call

sdkClient.Quotation.create(market: string, quotationPayload: QuotationPayload): Promise<IQuotation>;

function.

You can import SDKClient.QuotationPayloadBuilder, a helper function that will allow you to build the payload needed for Quotation in easy manner.

Request

    const co = {
        lat: "22.3353139",
        lng: "114.1758402",
    };

    const co2 = {
        lat: "22.3203648",
        lng: "114.169773",
    };

    const stop1 = {
        coordinates: co,
        address: "Wu Kai Sha Road",
    };

    const stop2 = {
        coordinates: co2,
        address: "Wu Kai Sha Road",
    };

    const quotationPayload = SDKClient.QuotationPayloadBuilder.quotationPayload()
        .withLanguage("en_HK")
        .withServiceType("COURIER")
        .withStops([stop1, stop2])
        .build();


    await sdkClient.Quotation.create("HK", quotationPayload);

Response

Promise of

IQuotation {
    id: string;
    scheduleAt: Date;
    serviceType: string;
    specialRequests: string[];
    expiresAt: Date;
    priceBreakdown: PriceBreakdown;
    isRouteOptimized: boolean;
    stops: Stop[];
}

Retrieve quotation

Request

const quotDetail = await sdKClient.Quotation.retrieve(market: string, quotationId: string);

Response

Promise of

IQuotation {
    id: string;
    scheduleAt: Date;
    serviceType: string;
    specialRequests: string[];
    expiresAt: Date;
    priceBreakdown: PriceBreakdown;
    isRouteOptimized: boolean;
    stops: Stop[];
}

Order

SDKCLient.Order

Create order

To place an new order

sdKClient.Order.create(market: string, orderPayload: OrderPayload): Promise<IOrder>;

function.

You can import SDKClient.OrderPayloadBuilder, a helper function that will allow you to build the payload needed for Order in easy manner.

const orderPayload = SDKClient.OrderPayloadBuilder.orderPayload()
        .withIsPODEnabled(true)
        .withQuotationID(quotation.id)
        .withSender({
            stopId: quotation.stops[0].stopId,
            name: "Michal",
            phone: "+85256847123",
        })
        .withRecipients([
            {
                stopId: quotation.stops[1].stopId,
                name: "Rustam",
                phone: "+85256847456",
            },
        ])
        .withMetadata({
            "internalId": "xyx211d"
        })
        .build();

Request

const order = await sdKClient.Order.create("HK", orderPayload);

Response

Promise of

interface IOrder {
    id: string;
    quotationId: string;
    priceBreakdown: PriceBreakdown;
    driverId: string;
    shareLink: string;
    status: string;
    distance: Measurement;
    stops: StopWithContact[];
    metadata: object;
}

Edit order

To edit an existing order

sdKClient.Order.edit(market: string, orderId: string, patchOrderPayload: PatchOrderPayload): Promise<IOrder>;

function.

You can import SDKClient.PatchOrderPayloadBuilder, a helper function that will allow you to build the payload needed for Order in easy manner.

const patchOrderPayload = SDKClient.PatchOrderPayloadBuilder.patchOrderPayload()
        .withStops([
            {
                coordinates: {
                lat: "22.3353139",
                lng: "114.1758402",
                },
                address: "Wu Kai Sha Road",
                name: "Michal",
                phone: "+85256847123",
            },
            {
                coordinates: {
                lat: "22.2827206",
                lng: "114.2123009",
                },
                address: "Quarry Bay, Hong Kong",
            },
            {
                coordinates: {
                lat: "22.3203648",
                lng: "114.169773",
                },
                address: "Wu Kai Sha Road",
                name: "Rustam",
                phone: "+85256847456",
            },
        ])
        .build();

Request

const order = await sdKClient.Order.edit("HK", order.id, payload);

Response

Promise of

interface IOrder {
    id: string;
    quotationId: string;
    priceBreakdown: PriceBreakdown;
    driverId: string;
    shareLink: string;
    status: string;
    distance: Measurement;
    stops: StopWithContact[];
    metadata: object;
}

Retrieve order

Request

await sdKClient.Order.retrieve("HK", order.id);

Response

Promise of

interface IOrder {
    id: string;
    quotationId: string;
    priceBreakdown: PriceBreakdown;
    driverId: string;
    shareLink: string;
    status: string;
    distance: Measurement;
    stops: StopWithContact[];
    metadata: object;
}

Add priority fee

Request

await sdKClient.Order.addPriorityFee("HK", order.id, "15")

Response

Promise of

interface IOrder {
    id: string;
    quotationId: string;
    priceBreakdown: PriceBreakdown;
    driverId: string;
    shareLink: string;
    status: string;
    distance: Measurement;
    stops: StopWithContact[];
    metadata: object;
}

Cancel order

Request

await sdKClient.Order.cancel("HK", order.id);

Response

Promise of

interface IOrder {
    id: string;
    quotationId: string;
    priceBreakdown: PriceBreakdown;
    driverId: string;
    shareLink: string;
    status: string;
    distance: Measurement;
    stops: StopWithContact[];
    metadata: object;
}

Driver

sdkClient.Driver

Retrieve driver

To retrieve driver details for your order call

sdkClient.Driver.retrieve(market, driverId, orderID)

function.

You can get driverId from order details when a driver picks up the order. The resulting object that will be returned by the function above is as follows:

{
    "driverId": "93965",
    "name": "Driver's Name'",
    "phone": "+85210002001",
    "plateNumber": "**T-00*",
    "photo": "www.example.com/photo"
}

Change driver

To change the driver for your order call

sdkClient.Driver.cancel(market, driverId, orderID)

function.

You can get driverId from order details when a driver picks up the order. The return value of the function above is as follows:

true

Market

A market is the location where Lalamove has launched its services. This SDK allows you to get all the service types in all cities in the specified market

Retrieve market

To retrieve all cities with their corresponding service types in a specific market call

sdkClient.Market.retrieve(market)

City

sdkClient.City

Retrieve city

To retrieve service types for a specific city sdkClient.City.retrieve(market, id)

The id param is a city identifier. You can see different city codes by calling retrieve.Market

delivery-nodejs-sdk's People

Contributors

ck-johnny avatar muhaimincs avatar unitsphere avatar zilongqiu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

delivery-nodejs-sdk's Issues

Bad request

{"name":"APIError","httpStatus":400,"callerModule":0,"errors":[{"id":"ERR_BAD_REQUEST"}],"date":"2022-04-18T07:21:34.650Z"}

why do I keep receiving this?

Lalamove SG Market - API Support

Hi Team,

This is to write to check if there are any plan for Lalamove SG market to have delivery nodejs sdk? If yes, can you please re-direct me to correct repository or person who can help us on this?

Best Regards,
Manish

Quotation and Order Interface Issue

Hi, Currently I integrate Lalamove API using this SDK. I found that both quotation and order raw response from HTTP call have not been formatted to the Interface defined on the SDK.

I already made a fix for that and used my fix for our project because I need a fast solution, if you guys want to take a look at the fix, please kindly visit my fork here and my short-term solution by publishing the update under my own NPM here (I will kindly remove it if you guys disagree with that public npm)

If you want me to open PR please show me to which branch I should do it.

Cheers,
Iqbal

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.