NPM Package to integrate ONDC into Node.js backend

Overview

ondc-node

This library can be used to integrate ONDC in JavaScript based applications.

Package is developed in TypeScript and will work with Node.Js & other JavaScript based stacks.

Introduction 👋

ONDC stands for Open Network for Digital Commernce.

ONDC is an Open Network which makes it easy for any buyer and seller to engage in a transactions.

LOGO

How to install? 👀

npm i ondc-node --save

☝️ Using to call APIs

Initialization

const ondc = require('ondc-node');
const instance = new ondc.ONDC({
    host: "http://localhost:5000",
    bapId: "bap.com",
    bapUri: "https://bap.com/beckn",
    bppId: "bpp.com",
    bppUri: "https://bpp.com/beckn",
    country: "IND",
    city: "std:080",
    ttl: "P1M"
});

Search an Item

const response = await instance.search({
        "item": {
            "descriptor": {
                "name": "ABC Aata"
            }
        },
        "fulfillment": {
            "end": {
                "location": {
                    "gps": "12.4535445,77.9283792"
                }
            }
        }
    })

✌️ Using as Express Middleware

const ONDC = require('ondc-node');
const express = require("express");

const app = express();
app.use(express.json());

app.use(ONDC.Middleware({"on_search": onSearchHandler, "init": initHandler}));

🤩 Effortless Authorization 🔐 with ONDC

You can use ondc.createAuthorizationHeader function to create Authorization header signature.

    const ondc = require('ondc-node');
    // Private key & Public keys are must for Auth to work
    const instance = new ondc.ONDC({
        host: "http://localhost:5000",
        bapId: "bap.com",
        bapUri: "https://bap.com/beckn",
        bppId: "bpp.com",
        bppUri: "https://bpp.com/beckn",
        country: "IND",
        city: "std:080",
        ttl: "P1M",
        publicKey: "<Public Key>",
        privateKey: "<Private Key>",
        uniqueKey: "dev.test.ondc-node.com",
        subscriberId: "<Gateway Address>",
    });

    let body = {
        "item": {
            "descriptor": {
                "name": "ABC Aata"
            }
        },
        "fulfillment": {
            "end": {
                "location": {
                    "gps": "12.4535445,77.9283792"
                }
            }
        }
    };
    // apiKey is sent in Authorization Header
    ondc.apiKey = await ondc.createAuthorizationHeader(body);
    const response = await instance.search(body)

Next function is ondc.verifyHeader which is used to verify the Authorization header signature with senders Public Keys.

You can fetch the public key from Gateway using /lookup call.

    const publicKey = "<Public key of Sender>";

    // verifyHeader return true/false
    let output = await ondc.verifyHeader(req.header.Authorization, {
        signing_public_key: publicKey
    }, req.body);

    console.log(`output: ${output}`);

Reference 📚

Functions Covered 🚀

Async Function Callback Function Other Function
search on_search get_cancellation_reasons
select on_select cancellation_reasons
init on_init get_return_reasons
confirm on_confirm return_reasons
status on_status get_rating_categories
track on_track rating_categories
cancel on_cancel get_feedback_categories
update on_update feedback_categories
rating on_rating get_feedback_form
support on_support feedback_form

Content

You might also like...

Multi-platform node package bundle to a package.json.

dmpc Multi-platform node package bundle to a package.json. install ### npm mode npm i -g @kingsword/dmpc ### yarn mode yarn global add @kingsword/dmp

Oct 16, 2022

NPM Package that simplifies Auth with Google OAuth2 🔐

NPM Package that simplifies Auth with Google OAuth2 🔐

Node Google OAuth2 🔐 A simple authentication flow for Google OAuth2 Explore the docs » Report Bug Table of Contents About The Project Getting Started

Jun 17, 2022

portfolio-project is a npm package to automatically update your projects section in your portfolio website. It will fetch the selected repositories directly from your GitHub account.

portfolio-project is a npm package to automatically update your projects section in your portfolio website. It will fetch the selected repositories directly from your GitHub account.

portfolio-project Those days of manually updating portfolio website after every new project made are gone ⚡ Yesss . . . you read that right. 😉 portfo

Aug 3, 2021

Detect npm packages by author name in your package-lock.json or yarn.lock.

detect-package-by-author Detect npm packages by author name in your package-lock.json or yarn.lock. Install Install with npm: # Not Yet Publish # npm

Jan 11, 2022

A Compiler npm Package.

vcompiler 🎉 Version 1.x is live ! 🎉 Introducation It is the npm package for the compilation of the code. Currently it supports the following program

May 30, 2022

Source of the cosmwasm npm package

Source of the cosmwasm npm package

About Cosmwasm.js was created to help new developers get started with their first dApps. It is just a wrapper package to easily import needed features

Dec 28, 2022

Npm package :p

Npm package :p

💩 poopoo-api Welcome to an "ok" api ⭐ If you like this package, don't forget to star Github package repo here and the website repo here Example code:

Mar 18, 2022

A cool npm package.

aditya.utils Colorful Console const a = require('aditya.utils') a.logblue("TEXT") // Blue Text a.logred("TEXT") // Red Text a.loggreen("TEXT") // Gree

Apr 8, 2022

A cool npm package.

aditya.utils Colorful Console const a = require('aditya.utils') a.logblue("TEXT") // Blue Text a.logred("TEXT") // Red Text a.loggreen("TEXT") // Gree

Apr 8, 2022
Comments
  • Signature verification Not working

    Signature verification Not working

    I figured that the apiKey parameter is not implicitly initialized because of which calls were failing. However even after providing the apiKey value on the creation of a new ONDC object the verification is failing at the gateway. This usually happens when the signature generated is invalid.

    here is the screenshot image

    we can have a video call if you want to, so that I can walk you through the issue.

    opened by sourabhmandal 0
  • Getting error as

    Getting error as "Invalid json in response body"

    Please refer following code.

    const instance = new ondc.ONDC({ "host": "http://localhost:5000", "action": "search", "bapId": "ondc.gofrugal.com/ondc/18275", "bapUri": "https://ondc.gofrugal.com/ondc/seller/adaptor", "bppId": "ondc.yaarilabs.com", "bppUri": "https://ondc.yaarilabs.com/", "domain": "nic2004:60232", "country": "IND", "city": "std:080", "ttl": "PT30S", "key": "<encryption key>", "signingPublicKey" : "<signing key>", "privateKey" : "<private key>", "uniqueKey" : "<uniqueKey>", "subscriberId" : "<subscriberId>" });

    let body = {
            "item": {
                "descriptor": {
                    "name": "Milk"
                }
            },
            "fulfillment": {
                "end": {
                    "location": {
                        "gps": "12.4535445,77.9283792"
                    }
                }
            }
        };
    

    instance.apiKey = await instance.createAuthorizationHeader(body); let result = await instance.search(body);

    opened by yogesh-karpe 1
Releases(1.1.3)
Owner
Utkarsh Mehta
Senior Software Engineer (Open Source Dev Tools) at BoxyHQ.
Utkarsh Mehta
Package fetcher is a bot messenger which gather npm packages by uploading either a json file (package.json) or a picture representing package.json. To continue...

package-fetcher Ce projet contient un boilerplate pour un bot messenger et l'executable Windows ngrok qui va permettre de créer un tunnel https pour c

AILI Fida Aliotti Christino 2 Mar 29, 2022
npm i uuid, npm i nodemon, npm i commander

goit-nodejs-hw-01 Получаем и выводим весь список контактов в виде таблицы (console.table) node index.js --action list Получаем контакт по id node inde

Oksana Banshchykova 3 Jul 5, 2022
A lightweight, standalone package to integrate full PWA features into Remix 💿

Remix PWA PWA integration & support for Remix Remix PWA is a lightweight, standalone npm package that adds full Progressive Web App support to Remix ?

Abdur-Rahman 220 Jan 3, 2023
This repository demonstrates how to integrate your Dialogflow agent with 3rd-party services services using a Node.JS backend service

This repository demonstrates how to integrate your Dialogflow agent with 3rd-party services services using a Node.JS backend service. Integrating your service allows you to take actions based on end-user expressions and send dynamic responses back to the end-user.

ddayto 10 Jul 21, 2022
Repo for tricking NPM into not hoisting your package. No dependencies and a warning if imported.

noist (Short for No Hoist) Repo for tricking NPM into not hoisting your package. No dependencies and a warning if imported. Why? As of npm@7 NPM suppo

Zackery Griesinger 20 Oct 27, 2022
An example project to how to integrate Chat Engine into a marketplace

Add Chat to Your Marketplace This is a example online marketplace with Chat Engine fully integrated. It's meant to help people building online marketp

Adam La Morre 13 Dec 22, 2022
A NPM package powered by Yeoman that generates a scaffolding boilerplate for back-end workflow with Node.js.

generator-noderplate Generate Node.js starter files with just one command! We have deployed a npm package that will generate a boilerplate for nodejs

Samarjeet 3 Jan 24, 2022
An npm package for demonstration purposes using TypeScript to build for both the ECMAScript Module format (i.e. ESM or ES Module) and CommonJS Module format. It can be used in Node.js and browser applications.

An npm package for demonstration purposes using TypeScript to build for both the ECMAScript Module format (i.e. ESM or ES Module) and CommonJS Module format. It can be used in Node.js and browser applications.

Snyk Labs 57 Dec 28, 2022
Gatsby-Formik-contact-form-with-backend-panel - Full working contact form with backend GUI panel.

Gatsby minimal starter ?? Quick start Create a Gatsby site. Use the Gatsby CLI to create a new site, specifying the minimal starter. # create a new Ga

Bart 1 Jan 2, 2022
Venni backend - The backend of the Venni client apps implementing the credit card payments, matching algorithms, bank transfers, trip rating system, and more.

Cloud Functions Description This repository contains the cloud functions used in the Firebase backend of the Venni apps. Local Development Setup For t

Abrantes 1 Jan 3, 2022