search

Paytm Miniapps Node Client SDK

A node client SDK to interact with Paytm Mini Apps ecosystem.

Installation Guide

Requirements

Make sure the nodejs version 8.17.0 or above is installed. To check the current node version, run the following command:

copy icon
node -v

 

Getting Started

  1. To use it in your code, include the following lines in your package.json.
    copy icon
    "dependencies": {
        ...
        "paytm-mini-programs-nodejs-sdk": "https://github.com/paytm/paytm-mini-programs-nodejs-sdk.git"
        ...
    }
  2. Install with npm:
    copy icon
    npm install

 

Development

  1. Clone the following repository.
    copy icon
    git clone https://github.com/paytm/paytm-mini-programs-nodejs-sdk.git
  2. Install dependencies.
    copy icon
    npm install

 

Documentation

To generate complete documentation, run the following command.

copy icon
npm run docs

Open the generated document via ./docs/<repository name>/<version>/index.html

 

 

Debugging

To view debug logs for this client, run your app with the environment variable DEBUG=miniapps.node.*.

copy icon
DEBUG=miniapps.node.* NODE_ENV=staging node app.js

 

Unit Test Case

To run unit test cases for this client, use the following command:

copy icon
npm test

 

Code Coverage

To generate code coverage for test cases, use the following command:

copy icon
npm run coverage

Open the generated document via ./coverage/index.html.

SDK Code

Auth Client

  • Configuring Auth Client

copy icon
const miniAppsClientSdk = require('paytm-mini-programs-nodejs-sdk');
const OauthClient = miniAppsClientSdk.clients.oauth;
const oauthClient = new OauthClient({
    clientId : "<Auth Client ID received on onboarding>"
    clientSecret : "<Auth Client Secret received on onboarding>"
},{
    ENDPOINT : "https://accounts.paytm.com",
    TIMEOUT : 10 * 1000
});
  • Example of Fetch Access Token

copy icon
(async function() {
    try {
        const requestOpts = {
            code : "<Auth code received from trust login>"
        };
        const response = await oauthClient.oauthToken(requestOpts);
        console.log('Here is oauth token response', JSON.stringify(response));
    } catch(err) {
        console.log('Some error occurred while fetching oauth token', err);
    }
}());
  • Example of User Profile

copy icon
(async function() {
    try {
        const requestOpts = {
            scopeCode : "<received from fetch access token api response: access_token>"
        };
        const response = await oauthClient.userProfile(requestOpts);
        console.log('Here is user profile response', JSON.stringify(response));
    } catch(err) {
        console.log('Some error occurred while fetching user profile', err);
    }
}());

 

Mini Apps Common Client

  • Configuring Common Client

copy icon
const miniAppsClientSdk = require('paytm-mini-programs-nodejs-sdk');
const MiniAppsCommonClient = miniAppsClientSdk.clients.common;
const commonClient = new MiniAppsCommonClient({
    clientId : "<Auth Client ID received on onboarding>"
},{
    ENDPOINT : "https://miniapps.paytm.com",
    TIMEOUT : 10 * 1000
});
  • Example of Fetch Open ID

copy icon
(async function() {
    try {
        const sso_token = "<received from fetch access token api response: access_token>"
        const response = await commonClient.getPartnerOpenId(sso_token);
        console.log('Here is partner open id response', JSON.stringify(response));
    } catch(err) {
        console.log('Some error occurred while fetching open id', err);
    }
}());
  • Example of Send Notification

copy icon
(async function() {
    try {
        const payload = {
            name : "<name>",
            vertical : "<vertical>",
            url : "<url>"
        };

        const requestObject = {
            access_token : "<received from fetch access token: access_token>",
            mid : "<merchant mid received on onboarding>",
            openId : "<received from fetch open id>,
            orderId : "<paytm order id received after placing order>",
            templateName : "<notification template name received on onboarding>",
            notificationPayload : payload
        };
        
        const response = await commonClient.sendPartnerNotification(requestObject);
        console.log('Here is send partner notification response', JSON.stringify(response));
    } catch(err) {
        console.log('Some error occurred while sending partner notification', err);
    }
}());