Paytm Payment Gateway

Integrating PayTM Payment Gateway

Aakash
8 min readOct 17, 2023

In this technical blog post, we’ll explore how to integrate the Paytm payment gateway using their Dynamic QR (DQR), Payment Links, and Point of Sale (POS) APIs in your backend app developed with Node.js/Nest.js. Paytm offers a variety of APIs to facilitate payment processing and transaction management. We will cover the key aspects of integrating each of these APIs into our application.

Table of Contents

  1. Introduction to Paytm Payment Gateway
  2. Prerequisites
  3. Creating Dynamic QR Codes (DQR)
  • How to Create a Dynamic QR Code
  • Checking Transaction Status

4. Creating Payment Links

  • How to Create a Payment Link
  • Checking Transaction Status of Payment Links
  • Expiring Payment Links

5. Integrating POS (Point of Sale) System

  • Uploading Payment Requests for POS
  • Checking Transaction Status for POS Payments
  • Voiding Transactions in POS

6. Additional Information

7. Conclusion

1. Introduction to Paytm Payment Gateway

Paytm Payment Gateway provides a secure, reliable, and user-friendly solution for processing payments in your app. With Paytm, you can offer your customers a wide range of payment options, including credit/debit cards, UPI, net banking, Paytm Wallet, and EMI. Paytm’s robust infrastructure ensures that transactions are processed quickly and securely, providing a seamless experience for your users.

To integrate Paytm Payment Gateway into your backend app, you will need to utilize the DQR, POS, and Payment Link APIs. These APIs allow you to generate dynamic QR codes, create payment links, and integrate with a POS system for in-person payments. Let’s explore each of these APIs in detail.

2. Prerequisites

Before we dive into the integration process, make sure you have the following prerequisites in place:

  1. Your backend app built with Node.js/Nest.js.
  2. Access to the Paytm Business Dashboard.
  3. Knowledge of building apps with Node.js/Nest.js.
  4. Familiarity with RESTful APIs.

3. Integration of Dynamic QR Codes (DQR)

Dynamic QR codes are a convenient way to accept payments using Paytm. By generating a unique QR code for each transaction, you can provide a seamless payment experience for your customers. To create a dynamic QR code, you will need to make use of the create-qr-code-api provided by Paytm.

1. How to Create a Dynamic QR Code

To create a dynamic QR code, you need to make an API call to Paytm’s create-qr-code-api. This API requires parameters such as the order ID, amount, and other optional parameters like expiry time and callback URL. Here’s an example of how you can create a dynamic QR code using the Paytm API in our app:

const createQRCode = async (orderId, amount) => {
try {
const response = await axios.post('https://business.paytm.com/docs/api/create-qr-code-api/?ref=dynamicQR', {
orderId,
amount, // Other optional parameters
});
return response.data.qrCode;
} catch (error) {
console.error('Failed to create dynamic QR code:', error);
throw new Error('Failed to create dynamic QR code');
}
};

By making an API call to create-qr-code-api, you will receive a dynamic QR code that you can display to your customers for payment. Remember to handle any errors that may occur during the API call and provide appropriate error messages to your users.

2. Check Transaction Status

Once a payment is made using the dynamic QR code, you will need to check the transaction status to ensure that it is successful. Paytm provides the transaction-status-api for this purpose. By making an API call to this endpoint, you can retrieve the transaction status based on the transaction ID or order ID.

Here’s an example of how you can check the transaction status using the Paytm API:

const checkTransactionStatus = async (transactionId) => {
try {
const response = await axios.post('https://business.paytm.com/docs/api/v3/transaction-status-api?ref=dynamicQR', { transactionId });
return response.data.status;
} catch (error) {
console.error('Failed to check transaction status:', error);
throw new Error('Failed to check transaction status');
}
};

By making an API call to transaction-status-api and providing the transaction ID, you will receive the status of the transaction. You can use this information to update the payment status in your app accordingly.

4. Payment Links Integration

Paytm also allows you to create payment links that can be shared with your customers through various channels such as email, SMS, or social media. Payment links provide a convenient way for your customers to make payments without the need for a separate checkout page. To create payment links, you will need to make use of the create-link-api provided by Paytm.

1. How to Create a Payment Link

To create a payment link, you need to make an API call to Paytm’s create-link-api. This API requires parameters such as the order ID, amount, and other optional parameters like expiry time and callback URL. Here’s an example of how you can create a payment link using the Paytm API in your app:

const createPaymentLink = async (orderId, amount) => {
try {
const response = await axios.post('https://business.paytm.com/docs/api/create-link-api?ref=paymentLinks', {
orderId,
amount, // Other optional parameters
});
return response.data.paymentLink;
} catch (error) {
console.error('Failed to create payment link:', error);
throw new Error('Failed to create payment link');
}
};

By making an API call to create-link-api, you will receive a payment link that you can share with your customers. This link will direct them to a payment page where they can complete the transaction.

2. Checking Transaction Status of Payment Links

After a payment link is shared with your customers, you will need to check the transaction status to ensure that it is successful. Paytm provides the transaction-status-api for this purpose. By making an API call to this endpoint, you can retrieve the transaction status based on the transaction ID or order ID.

Here’s an example of how you can check the transaction status of a payment link using the Paytm API:

const checkTransactionStatus = async (transactionId) => {
try {
const response = await axios.post('https://business.paytm.com/docs/api/create-link-api?ref=paymentLinks', { transactionId });
return response.data.status;
} catch (error) {
console.error('Failed to check transaction status:', error);
throw new Error('Failed to check transaction status');
}
};

By making an API call to transaction-status-api and providing the transaction ID, you will receive the status of the transaction. You can use this information to update the payment status in your app accordingly.

3. Expiring Payment Links

If you want to make a payment link expire after a certain period of time, you can make use of the expire-link-api. This API allows you to set an expiry time for the payment link, after which it will no longer be valid for payment. Here’s an example of how you can expire a payment link using the Paytm API:

const expirePaymentLink = async (orderId) => {
try {
await axios.post('https://business.paytm.com/docs/api/expire-link-api?ref=paymentLinks', { orderId });
console.log('Payment link expired successfully');
} catch (error) {
console.error('Failed to expire payment link:', error);
throw new Error('Failed to expire payment link');
}
};

By making an API call to expire-link-api and providing the order ID of the payment link, you can ensure that the link becomes invalid after the specified expiry time.

5. Point of Sale (POS) Integration

If you have a physical store or need to accept in-person payments, Paytm’s POS integration allows you to seamlessly integrate with your backend app. By using the POS APIs provided by Paytm, you can upload payment requests, check transaction status, and void transactions.

1. Upload Payment Request for POS

To upload payment requests for POS, you need to make an API call to Paytm’s pos-sale-api. This API allows you to upload payment requests with parameters such as the order ID, amount, and other optional parameters like customer’s mobile number and email. Here’s an example of how you can upload a payment request for POS using the Paytm API:

const uploadPaymentRequest = async (orderId, amount, mobileNumber, email) => {
try {
await axios.post('https://business.paytm.com/docs/api/pos-sale-api?ref=poswirelessintegrationapireference', {
orderId,
amount,
mobileNumber,
email, // Other optional parameters
});
console.log('Payment request uploaded successfully');
} catch (error) {
console.error('Failed to upload payment request:', error);
throw new Error('Failed to upload payment request');
}
};

By making an API call to pos-sale-api and providing the necessary parameters, you can upload the payment request for POS, enabling your customers to make in-person payments using Paytm.

2. Check POS Transaction Status

After a payment is made using the POS system, you will need to check the transaction status to ensure that it is successful. Paytm provides the pos-status-enquiry-api for this purpose. By making an API call to this endpoint, you can retrieve the transaction status based on the transaction ID or order ID.

Here’s an example of how you can check the transaction status for POS payments using the Paytm API:

const checkTransactionStatus = async (transactionId) => {
try {
const response = await axios.post('https://business.paytm.com/docs/api/pos-status-enquiry-api?ref=poswirelessintegrationapireference', { transactionId });
return response.data.status;
} catch (error) {
console.error('Failed to check transaction status:', error);
throw new Error('Failed to check transaction status');
}
};

By making an API call to pos-status-enquiry-api and providing the transaction ID, you will receive the status of the transaction. You can use this information to update the payment status in your app accordingly.

3. Cancel/VOID POS Transaction

In some cases, you may need to cancel or void a transaction made through POS. Paytm provides the pos-void-api for this purpose. By making an API call to this endpoint and providing the transaction ID or order ID, you can void the transaction and ensure that no further action is taken on it.

Here’s an example of how you can void a transaction using the Paytm API:

const voidTransaction = async (transactionId) => {
try {
await axios.post('https://business.paytm.com/docs/api/pos-void-api?ref=poswirelessintegrationapireference', { transactionId });
console.log('Transaction voided successfully');
} catch (error) {
console.error('Failed to void transaction:', error);
throw new Error('Failed to void transaction');
}
};

By making an API call to pos-void-api and providing the transaction ID, you can void the transaction and ensure that it is canceled successfully.

6. Additional Information

Here are some additional links and resources that you may find helpful for integrating Paytm Payment Gateway into your backend app:

· Official Documentation for Dynamic QR Code API https://business.paytm.com/docs/api/create-qr-code-api/?ref=dynamicQR

· Official Documentation for Payment Link API https://business.paytm.com/docs/api/create-link-api?ref=paymentLinks

· Official Documentation for POS Integration API https://business.paytm.com/docs/api/pos-sale-api?ref=poswirelessintegrationapireference

Make sure to refer to the official Paytm documentation for detailed information on each API and its parameters. This will ensure that you have a smooth integration process and can handle any edge cases or specific requirements.

7. Conclusion

Integrating Paytm Payment Gateway into your backend app using the DQR, POS, and Payment Link APIs opens up a world of possibilities for accepting payments. Whether your customers prefer to pay online, through a physical store, or with payment links, Paytm provides a secure and seamless experience. By following the steps outlined in this guide and referring to the official documentation, you can easily implement Paytm Payment Gateway and offer a convenient payment solution to your users. Happy coding!

--

--