Nightly Procrastination Machine

    giaohangnhanh
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.2 • Public • Published

    Giao Hang Nhanh

    A Node.js API Wrapper Library for Giao Hang Nhanh

    If you've found an bug/issue, please send me an email.

    If you enjoyed this project — or just feeling generous, consider buying me a beer. Cheers! 🍻

    Installation

    npm install giaohangnhanh
    # OR
    yarn add giaohangnhanh

    Usage

    How to get API token instruction.

    import GHN from 'giaohangnhanh';
    const token: string = 'apikey';
    const ghn: GHN = new GHN(token);
    // OR
    const ghn: GHN = new GHN(token, { test: true }); // enable test flag for testing API token

    Full Documentation

    Order

    Create Order

    Documentation

    const shop_id: number = 0;
    const info = {
      to_name: '',
      to_phone: '',
      to_address: '',
      to_ward_code: '',
      to_district_id: 0,
      service_id: 0,
      service_type_id: 0,
      content: '',
      weight: 0,
      length: 0,
      width: 0,
      height: 0,
      payment_type_id: 1, // CHOTHUHANG - CHOXEMHANGKHONGTHU - KHONGCHOXEMHANG
      required_note: ''
    };
    const order = await ghn.order.createOrder(shop_id, info);

    Get Order Info

    Documentation

    const order_code: string = '';
    const order = await ghn.order.getOrder(order_code);

    Get Order Info (by client_order_code)

    Documentation

    const client_order_code: string = '';
    const orderByClientCode = await ghn.order.getOrderByClientCode(client_order_code);

    Get Fee of Order Info

    Documentation

    const order_code: string = '';
    const orderFee = await ghn.order.getOrderFee(order_code);

    Update Order

    Documentation

    const updatedOrder: any = {
      content: 'Updated Test Content'
    }
    const { message } = await ghn.order.updateOrder(shop_id, order_code, updatedOrder);

    Update COD of Order

    Documentation

    const cod_amount: number = 0;
    const { message } = await ghn.order.updateOrderCOD(order_code, amount);

    Print Order

    Documentation

    const order_codes: Array<string> = [order_code];
    const printOrder = await ghn.order.printOrder([order_code]);

    Return Order

    Documentation

    const order_codes: Array<string> = [order_code];
    const returnOrder = await ghn.order.returnOrder(order_codes);

    Cancel Order

    Documentation

    const order_codes: Array<string> = [order_code];
    const cancelOrder = await ghn.order.cancelOrder(order_codes);

    Service - Calculate Fee

    Get Services

    Documentation

    const shop_id: number = 0;
    const from_district: number = 0;
    const to_district: number = 0;
    const services = await ghn.service.getServices(shop_id, from_district, to_district);

    Calculate Fee

    Documentation

    const shop_id: number = 0;
    const service_id: number = 0;
    const to_ward_code: string = '';
    const to_district_id: number = 0;
    const weight: number = 0; // gram
    const length: number = 0; // cm
    const width: number = 0; // cm
    const height: number = 0; // cm
    const options = {
      service_id,
      to_ward_code,
      to_district_id,
      weight,
      length,
      width,
      height
    };
    const feeData = await ghn.service.calculateFee(shop_id, options);

    Calculate the Expected Delivery Time

    Documentation

    const shop_id: number = 0;
    const from_district_id: number = 0;
    const from_ward_code: string = '';
    const to_district_id: number = 0;
    const to_ward_code: string = '';
    const service_id: number = 0;
    const timeData = await ghn.service.calculateExpectedDeliveryTime(shop_id, {
      from_district_id,
      from_ward_code,
      to_district_id,
      to_ward_code,
      service_id
    });

    Address

    Get Provinces

    Documentation

    const provinces = await ghn.address.getProvinces();

    Get Districts

    Documentation

    const province_id: number = 0;
    const districts = await ghn.address.getDistricts(province_id);

    Get Wards

    Documentation

    const district_id: number = 0;
    const wards = await ghn.address.getWards(district_id);

    Get Stations

    Documentation

    const district_id: number = 0; // optional
    const ward_code: string = ''; // optional
    const options = { district_id, ward_code, offset: 0, limit: 1000 };
    const stations = await ghn.address.getStations(options);

    Store

    Get Stores

    Documentation

    const client_phone: string = '';
    const pagination = { offset: 0, limit: 10000 };
    const stores = await ghn.store.getStores(client_phone, pagination);

    Create Store

    Documentation

    const district_id: number = 0; // required
    const ward_code: string = ''; // required
    const name: string = ''; // required
    const phone: string = ''; // required
    const address: string = ''; // required
    const info = { name, phone, address };
    const { shop_id } = await ghn.store.createStore(district_id, ward_code, info);

    Add Staff to the Store

    Documentation

    const shop_id: number = 0;
    const phone_number: string = '';
    const { client_shop_id } = await ghn.store.addStaff(shop_id, phone_number);

    Delivery Again

    Documentation

    const shop_id: number = 0;
    const order_codes: Array<string> = [];
    const orders = await ghn.store.deliverAgain(shop_id, order_codes);

    Ticket

    Get Ticket

    Documentation

    const ticket_id: number = 0;
    const ticket = await ghn.ticket.getTicket(ticket_id);

    Create Ticket

    Documentation

    const c_email: string = '';
    const category: string = ''; // optional: Tư vấn - Hối Giao/Lấy/Trả hàng - Thay đổi thông tin - Khiếu nại
    const description: string = '';
    const order_code: string = '';
    const ticket_info: any = { c_email, category, description, order_code };
    const ticket = await ghn.ticket.createTicket(ticket_info);

    Create Feedback of Ticket

    Documentation

    const ticket_id: number = 0;
    const feedback_info = { description: '' };
    const ticket = await ghn.ticket.addFeedbackToTicket(ticket_id, feedback_info);

    Install

    npm i giaohangnhanh

    DownloadsWeekly Downloads

    10

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    160 kB

    Total Files

    12

    Last publish

    Collaborators

    • hieudoanm