Guide To Integrate Paytm Payment Gateway Using Python Server SDKs

As an entrepreneur, integrating a payment gateway with your online store is an integral step for taking your shop live. For all the online payment needs, you will have to onboard a payment gateway and integrate it with your website.

If you are not someone who understands the technical bits of integrating payment gateway with the server-side of your store, the process can get tedious. You will need to install APIs to integrate a payment gateway.

Paytm Payment Gateway has a really simple and straightforward way of integration. You can complete the integration process all by yourself even if you don’t have any technical expertise.

If you are particularly looking forward to integrating Paytm Payment Gateway using Python server SDK, this article will guide you through the process.

Before that, let’s first learn a little bit of the basics of server-side and client-side coding.

What is the difference between server-side and client-side?

Just like all online stores, your shop too has two sides to it: client-side and server-side.

The client-side simply means the part of the programming that takes care of what customers will look at and interact with. Whereas, the server-side denotes the back-end of your website that ensures whatever commands or information the customer provides gets stored or implemented as it should be.

Server-sideClient-side
Server-side script runs on the serverClient-side runs on users’ browser
It controls the back-end of the website and manages data that users’ inputIt is front-end of the website, which is visible to users
Programming languages like Python, PHP, Ruby on Rails, and Java are usedMostly, JavaScript programming language is used
The script is run on the server before the page is sent to the browserThe web server processes the script and only renders HTML to users

Integrating payment gateway with your website will require server-side SDKs (software development kits). SDKs are provided by the company whose product you have to integrate. They are simply a set of software tools and programs that help with integration.

Server-side programming languages include Java, PHP, Ruby on Rails, SQL, and Python.

Interesting Read: Simple Ways to Integrate Paytm Payment Gateway in PHP

Paytm provides server-side kits in different languages for major APIs required to integrate Paytm Payment Gateway. These kits allow easy integration of Paytm PG.

Once the integration is done, you can start accepting money from customers via any payment methods such as Paytm wallet, credit card, debit card, net banking, and UPI.

Integrate Paytm PG with Python server SDK

The first requirement to integrate Paytm PG using Python server kit is to ensure you have Python 3.5 or the latest version to work with. You can install the Python package for Paytm Payment Gateway SDK with the following command: pip install paytm-pg

The next course of action is to generate API keys, which involves three simple steps.

What are the contents of API keys?

  • MID (Merchant ID) – This is a unique identifier issued to every merchant.
  • Merchant Key – This is a unique secret key used for secure encryption of every payment or refund request. This needs to be kept on the server side and should never be shared with anyone.
  • Industry Type ID – This is a part of bank and paymode configuration done with respect to an account.
  • Website – This parameter is used to support multiple callback URLs to post the payment response. Each URL needs to be mapped to a website parameter.

Now that you are aware of the contents of API keys, here is the process to generate API keys:

Step 1: Log in to your Paytm for Business account and go to your dashboard.

Step 2: Select the type of environment for which you want to create API keys. The two types of environments are Test API Details and Production API Details. To generate production API keys, your account must be activated.

Step 3: For Test mode, click on the ‘Generate Key’ button under the Test API Details tab. It will generate the Test API key.

Interesting Read: Paytm Payment Gateway Integration in Java-Based Website

Integrating SDK code

After generating the API keys, you are required to integrate the SDK code with your website. You can download the Python server-side SDK from this link.

Below are the SDK codes for initialisation, creating transaction token, payment status, refund, and refund status.

  • Initialisation

You will have to initialise the mandatory parameters like environment, mid, key, and website. You can find these details in your API keys that you generated above. Visit this link to get these details if you have not saved them. You will be asked to enter these details in the codes mentioned below:

# For Staging 

environment = LibraryConstants.STAGING_ENVIRONMENT

 

# For Production 

# environment = LibraryConstants.PRODUCTION_ENVIRONMENT

 

mid = “YOUR_MID_HERE”

key = “YOUR_KEY_HERE”

website = “YOUR_WEBSITE_NAME”

client_id = “YOUR_CLIENT_ID_HERE”

 

callbackUrl = “MERCANT_CALLBACK_URL”

MerchantProperty.set_callback_url(callbackUrl)

 

MerchantProperty.initialize(environment, mid, key, client_id, website)

If you want to add log file to your project, use the follow codes:

file_path = ‘/path/log/file.log’

mode = “w”

handler = logging.FileHandler(file_path, mode)

formatter = logging.Formatter(“%(name)s: %(levelname)s: %(message)s”)

handler.setFormatter(formatter)

MerchantProperty.set_log_handler(handler)

MerchantProperty.set_logging_disable(False)

MerchantProperty.set_logging_level(logging.DEBUG)

  • Transaction Token for Payments

channel_id = EChannelId.WEB

order_id = “UNIQUE_ORDER_ID”

txn_amount = Money(EnumCurrency.INR, “1.00”)

user_info = UserInfo()

user_info.set_cust_id(“CUSTOMER_ID”)

user_info.set_address(“CUSTOMER_ADDRESS”)

user_info.set_email(“CUSTOMER_EMAIL_ID”)

user_info.set_first_name(“CUSTOMER_FIRST_NAME”)

user_info.set_last_name(“CUSTOMER_LAST_NAME”)

user_info.set_mobile(“CUSTOMER_MOBILE_NO”)

user_info.set_pincode(“CUSTOMER_PINCODE”)

payment_details = PaymentDetailsBuilder(channel_id, order_id, txn_amount, user_info).build()

response = Payment.createTxnToken(payment_details)

  • Payment Status

order_id = “YOUR_ORDER_ID”

read_timeout = 30*1000

payment_status_detail = PaymentStatusDetailBuilder(order_id).set_read_timeout(read_timeout).build()

response = Payment.getPaymentStatus(payment_status_detail)

  • Initiate Refund

order_id = “YOUR_ORDER_ID”

ref_id = “REFERENCE_ID”

txn_id = “TRANSACTION_ID”

txn_type = “REFUND”

refund_amount = “1”

refund = RefundDetailBuilder(order_id, ref_id, txn_id, txn_type, refund_amount).set_sub_wallet_amount(sub_wallet_amount).set_extra_params_map(extra_params_map).build()

response = Refund.doRefund(refund)

  • Refund Status

order_id = “ORDER_ID”

ref_id = “REFERENCE_ID”

refund_status_details = RefundStatusDetailBuilder().set_order_id(order_id).set_ref_id(ref_id).build()

response = Refund.getRefundStatus(refund_status_details)

Conclusion

Integrating Paytm Payment Gateway with your store should not be difficult. This guide will help you complete the integration process without any glitch.

Once you are done with the integration, you can start accepting money from your customers online. This integration will enable your online shop to accept money via all the payment methods.

Frequently Asked Questions

Question: What are the other server-side languages for which Paytm Payment Gateway provides SDK integration?

Answer: Apart from Python, you can integrate Paytm Payment Gateway with our server-side SDKs for the following languages:

  • PHP
  • JS Node
  • Java

Question: Do I need to know Python to integrate Paytm Payment Gateway’s server-side SDK?

Answer: Not necessarily. The guide mentioned above in the article is sufficient for you to integrate and start accepting digital payments from customers.

 

Switch To Paytm Payment Gateway Today

You May Also Like
Accept Payments at Zero fees
Read More

Accept Payments Online at Zero Fees with Paytm

While there is no extra cost associated with making online payments on the consumer side, businesses need to pay certain charges. That’s the reason why they look for ways to accept payments at a 0% fee.