Developer GuideMarch 28, 20258 min read

Node.js Payment Integration Guide: Accept Payments in Minutes

This guide walks you through integrating a free payment gateway into your Node.js application. You'll learn how to create payment links, handle webhooks, and accept UPI & card payments with minimal code.

Prerequisites

  • Node.js 18+ installed
  • A free Node Gateway account (sign up at nodegateway.vercel.app)
  • Your API key from the Node Gateway dashboard
  • Basic knowledge of Express.js

Step 1: Install Dependencies

Create a new Node.js project and install the required packages:

npm init -y
npm install express axios dotenv

Step 2: Configure Your API Key

Create a .env file at the root of your project:

NODE_GATEWAY_API_KEY=your_api_key_here
NODE_GATEWAY_BASE_URL=https://nodegateway.vercel.app/api

Find your API key in the Node Gateway dashboard under Settings → API Keys.

Step 3: Create a Payment Link

Payment links are the fastest way to collect payments. Create one with a simple API call:

const express = require('express');
const axios = require('axios');
require('dotenv').config();

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

app.post('/create-payment-link', async (req, res) => {
  const { amount, description, customerName, customerEmail } = req.body;

  try {
    const response = await axios.post(
      `${process.env.NODE_GATEWAY_BASE_URL}/payment-links`,
      {
        amount,          // Amount in paise (₹100 = 10000)
        description,
        customer: {
          name: customerName,
          email: customerEmail,
        },
        callback_url: 'https://yoursite.com/payment-success',
      },
      {
        headers: {
          Authorization: `Bearer ${process.env.NODE_GATEWAY_API_KEY}`,
          'Content-Type': 'application/json',
        },
      }
    );

    res.json({ paymentUrl: response.data.short_url });
  } catch (error) {
    res.status(500).json({ error: 'Failed to create payment link' });
  }
});

app.listen(3000, () => console.log('Server running on port 3000'));

Step 4: Handle Payment Webhooks

Webhooks notify your server instantly when a payment is completed. Set up a webhook endpoint and configure the URL in your Node Gateway dashboard:

const crypto = require('crypto');

app.post('/webhook/payment', express.raw({ type: 'application/json' }), (req, res) => {
  const signature = req.headers['x-gateway-signature'];
  const webhookSecret = process.env.NODE_GATEWAY_WEBHOOK_SECRET;

  // Verify webhook signature
  const expectedSig = crypto
    .createHmac('sha256', webhookSecret)
    .update(req.body)
    .digest('hex');

  if (signature !== expectedSig) {
    return res.status(400).json({ error: 'Invalid signature' });
  }

  const event = JSON.parse(req.body);

  switch (event.type) {
    case 'payment.captured':
      console.log('Payment successful:', event.payload.payment.entity.id);
      // Fulfill order, send receipt, update database...
      break;

    case 'payment.failed':
      console.log('Payment failed:', event.payload.payment.entity.id);
      // Notify customer, retry logic...
      break;
  }

  res.json({ status: 'ok' });
});

Step 5: Check Payment Status

You can always query the status of any payment by its ID:

app.get('/payment-status/:paymentId', async (req, res) => {
  const { paymentId } = req.params;

  const response = await axios.get(
    `${process.env.NODE_GATEWAY_BASE_URL}/payments/${paymentId}`,
    {
      headers: {
        Authorization: `Bearer ${process.env.NODE_GATEWAY_API_KEY}`,
      },
    }
  );

  res.json({
    id: response.data.id,
    status: response.data.status, // 'captured' | 'failed' | 'pending'
    amount: response.data.amount,
    method: response.data.method,
  });
});

Why Node Gateway for Node.js Projects?

  • 100% free — no setup fees, no monthly charges
  • REST API designed for developers — clean, consistent, well-documented
  • UPI, cards, net banking & wallets in a single integration
  • Real-time webhooks with signature verification
  • Payment links & QR codes for no-code payment collection
  • Dashboard with live analytics, transaction history & exports

Start accepting payments for free

Create your free Node Gateway account and get your API key in minutes.

Create Free Account →