Paytm integration with Ruby on Rails

Post by
author-image
Damini Patel

ruby on rails

What is Paytm Payment Gateway?

Even though Drupal is quite a secure platform for the business, it is still not completely secured from the hands of spam bots and hackers. Being an open-source makes Drupal more of a secure thing and it is taken care by a number of security experts who work continuously to check for weaknesses in the core or for vulnerabilities and its modules. Once the security team finds such an issue then they will quickly come up with a security update or a patch for the module in question and release it soon.

Terms you need to know before proceeding further

  • MID :This is a unique identifier provided to every merchant by Paytm. MID is part of your account credentials and is different on staging and production environment. Your staging MID is available here and production MID will be available once your activation is complete.
  • Merchant Key :This is a unique secret key used for secure encryption of every request. This needs to be kept on server side and should not be shared with anyone.
  • CHANNEL_ID :This parameter is used to control the theme of the payment page. Based on the channel passed, Paytm will render the layout suitable for that specific platform For websites, the value is WEB For Mobile websites/App, the value is WAP
  • WEBSITE :For staging environment: WEBSTAGING,
    For production environment: Will be available here once your activation is completeli>
  • INDUSTRY_TYPE_ID : For staging environment: "Retail",
    For production environment: Will be available here once your activation is complete.
  • CALLBACK_URL : On completion of transaction, Paytm payment gateway will send the response on this URL. Sample URL is - https://merchant.com/callback/
  • Payment_url : when start payment it’s redirect to payment gateway. In that we can not go back or not refresh the page.

These are the steps to integrate Paytm as payment gateway in your rails app.

Step 1:

Need to create developer account from here: create account

Step 2:

After successful account creation, Grab credentials and place it inside secrets.yml or credentials.yml

paytm give you
Test Merchant ID = ''
Test Merchant Key = ''
Website = WEBSTAGING
Industry Type = Retail
Channel ID (For Website) = WEB
Channel ID (For Mobile Apps) = WAP
transaction_url: https://securegw-stage.paytm.in/theia/processTransaction

Step 3:

We need to process and verify the payment. Create one controller named paytm_controller.rb

step 4:

Add service in your app. We make services for controller code refactor

start_payment_service.rbverify_payment_service.rb

Step 5:

Add routes in routes.rb file

match '/paytm_payment' => 'paytm#start_payment', via: [:post], :as => :paytm_payment
match '/confirm_payment' => 'paytm#verify_payment', via: [:post]

Step 6:

Reduce logic from view file, create one helper named paytm_helper.rb

Step 7:

We will add encyption_new_pg.rb file for encrypt data in module named encryption_new_pg.rb inside helpers/paytm folder

Step 8:

Now we can create a view for start and verify the payment. For that, we can add 2 files named start_payment.html.erb and verify_payment.html.erb

start_payment.html.erb verify_payment.html.erb

 

Step 9:

Add paytm payment button which initializes payment.

<%= form_tag paytm_payment_path, method: :post, remote: false, :style => "" do %>
    <button >Start Payment</button>
<% end %>

Everything is done now you will have a complete working payment gateway on your web app. Any question regarding the process or if any issue in implementing the above steps you can comment and we will be glad to help. Thank you!

twitter Twit
facebook Share
googlebookmarks Mark
linkedin Share

CONTACT US

We are open for new challenges and we help you reach your goals!