search

Node SDK Integration

Installation Guide

 

Requirements

Node 8.9.0 or later

 

Installing Paytm's payment gateway SDK with npm

  1. To install Node SDK available on npmjs.com, run below command
    npm install paytm-pg-node-sdk


    OR
     

    Add below lines to package.json of your project

    "dependencies": {
            ...
            "paytm-pg-node-sdk": "^1.0.4"
            ...
    }

     

  2. Run below command on command line to install dependencies to your project
    npm install

     

  3. To start using SDK functions, add the following lines in your project
    const Paytm = require('paytm-pg-node-sdk');

     

Generate API Keys

ATTRIBUTE DESCRIPTION
MID A unique merchant identifier issued by Paytm for your account.
Merchant Key A 16-digit unique merchant identifier issued by Paytm for your account.

Note: Merchant Key is a secret key used for encryption so never share this with anyone. And, You have to generate separate API Keys for test and production environment.

Steps to generate API keys

  1. Log into your Dashboard.
  2. Select the environment (Test/Production) for which you want to generate the API key.
  3. For Test mode, click Generate Key to generate key under Test API details tab.
  4. For Production mode, activate your account here to generate Production API details.

SDK Code

Initialization

Merchant will initialize the following mandatory parameters: environment, mid, key and website, after which merchant can directly call SDK methods to call APIs of payment gateway.

// For Staging 
var environment = Paytm.LibraryConstants.STAGING_ENVIRONMENT;

// For Production 
// var environment = Paytm.LibraryConstants.PRODUCTION_ENVIRONMENT;

// Find your mid, key, website in your Paytm Dashboard at https://dashboard.paytm.com/next/apikeys 
var mid = "YOUR_MID_HERE";
var key = "YOUR_KEY_HERE";
var website = "YOUR_WEBSITE_NAME";
var client_id = "YOUR_CLIENT_ID_HERE";

var callbackUrl = "MERCHANT_CALLBACK_URL";
Paytm.MerchantProperties.setCallbackUrl(callbackUrl);

Paytm.MerchantProperties.initialize(environment, mid, key, client_id, website);
// If you want to add log file to your project, use below code
Paytm.Config.logName = "[PAYTM]";
Paytm.Config.logLevel = Paytm.LoggingUtil.LogLevel.INFO;
Paytm.Config.logfile = "/path/log/file.log";

Note: Make sure log file (/path/log/file.log) has write permission.

 

Payments

Create Transaction Token

var channelId = Paytm.EChannelId.WEB;
var orderId = "UNIQUE_ORDER_ID";
var txnAmount = Paytm.Money.constructWithCurrencyAndValue(Paytm.EnumCurrency.INR, "1.00");
var userInfo = new Paytm.UserInfo("CUSTOMER_ID"); 
userInfo.setAddress("CUSTOMER_ADDRESS");
userInfo.setEmail("CUSTOMER_EMAIL_ID");
userInfo.setFirstName("CUSTOMER_FIRST_NAME");
userInfo.setLastName("CUSTOMER_LAST_NAME");
userInfo.setMobile("CUSTOMER_MOBILE_NO");
userInfo.setPincode("CUSTOMER_PINCODE");
var paymentDetailBuilder = new Paytm.PaymentDetailBuilder(channelId, orderId, txnAmount, userInfo);
var paymentDetail = paymentDetailBuilder.build();
var response = Paytm.Payment.createTxnToken(paymentDetail);

 

GetPaymentStatus

var orderId = "YOUR_ORDER_ID";
var readTimeout = 80000;
var paymentStatusDetailBuilder = new Paytm.PaymentStatusDetailBuilder(orderId);
var paymentStatusDetail = paymentStatusDetailBuilder.setReadTimeout(readTimeout).build();
var response = Paytm.Payment.getPaymentStatus(paymentStatusDetail);

 

Refunds

InitiateRefund

var orderId = "YOUR_ORDER_ID";
var refId = "REFERENCE_ID";
var txnId = "TRANSACTION_ID";
var txnType = "REFUND";
var refundAmount = "1";
var readTimeout = 80000;
var subWalletAmount = {};
var extraParamsMap = {};
subWalletAmount[Paytm.UserSubWalletType.FOOD] = 1.00;
subWalletAmount[Paytm.UserSubWalletType.GIFT] = 1.00;
var refund = new Paytm.RefundDetailBuilder(orderId, refId, txnId, txnType, refundAmount);
var refundDetail = refund.setReadTimeout(readTimeout).setSubwalletAmount(subWalletAmount).setExtraParamsMap(extraParamsMap).build();
var response = Paytm.Refund.initiateRefund(refundDetail);

 

 

GetRefundStatus

var orderId = "YOUR_ORDER_ID";
var refId = "REFERENCE_ID";
var readTimeout = 8000;
var refundStatusDetailBuilder = new Paytm.RefundStatusDetailBuilder(orderId, refId);
var refundStatusDetail = refundStatusDetailBuilder.setReadTimeout(readTimeout).build();
var response = Paytm.Refund.getRefundStatus(refundStatusDetail);

 

 

SDK Method References

 

Class Methods HTTP request Description

Payments

createTxnToken POST/theia/api/v1/initiateTransaction Returns a token which will be used in further frontend Payment calls
getPaymentStatus POST/merchant-status/api/v1/getPaymentStatus Returns the Payment status

Refunds

initiateRefund POST/refund/api/v1/async/refund Initiates the Refund
getRefundStatus POST/refund/api/v1/refundStatus Returns the Refund status

Downloads

Models