Skip to main content

NextJs Installation

NextJs With Pages Routes

Create a file in the api directory

/api/payment/route.js
import { PaytmConfig } from("@enjoys/paytm")
const paytm = new PaytmConfig({
PAYTM_ENVIRONMENT: "LIVE",
PAYTM_MERCHANT_KEY: "rBHSFqbQmGZJ1mu7",
PAYTM_MERCHANT_ID: "LwKutv58548207890301",
PAYTM_MERCHANT_WEBSITE: "DEFAULT",
CALLBACK_URL: "http://localhost:8080/api/payment/response",
});
export default function handler(req, res ) {

if (req.method === 'POST') {
paytm.InitializeTransaction(req, res)
} else {
res.status(500).json({ error: 'Unhanled Route' })
}

}

NextJs With App Routes

/api/payment/route.js
import { PaytmConfig } from("@enjoys/paytm")
const paytm = new PaytmConfig({
PAYTM_ENVIRONMENT: "LIVE",
PAYTM_MERCHANT_KEY: "rBHSFqbQmGZJ1mu7",
PAYTM_MERCHANT_ID: "LwKutv58548207890301",
PAYTM_MERCHANT_WEBSITE: "DEFAULT",
CALLBACK_URL: "http://localhost:8080/api/payment/response",
});
export async function POST(req, res) {
paytm.InitializeTransaction(req, res)
return
}