paint-brush
A Guide to Unity + Razorpay Payment Gateway Integrationby@magicofspade
673 reads
673 reads

A Guide to Unity + Razorpay Payment Gateway Integration

by Sai Krishna RaghunathanJune 13th, 2023
Read on Terminal Reader
Read this story w/o Javascript

Too Long; Didn't Read

My team & I was working on an [AR](https://hackernoon.com/tagged/ar)&VR project. The most difficult problem that we faced was integrating custom payment gateways to our app that’s built on Unity. To date, many developers used to email me to help them with their payment gateway integration so decided to share it here.
featured image - A Guide to Unity + Razorpay Payment Gateway Integration
Sai Krishna Raghunathan HackerNoon profile picture

My team & I was working on an AR&VR project — around mid-2017, the most difficult problem that we faced was integrating custom payment gateways to our app that’s built on Unity. To date, many developers used to email me to help them with their payment gateway integration so decided to share it here.


We had a use case where we have to collect payment from customers and update it in our backend e-commerce store.


There were two options for us one was to use available payment solutions with Unity or to build our own integration with other payment gateways.


Readymade solutions weren’t suitable because it was accepting payments in USD and even if some in-app purchase solutions were working in our regional currency (INR) it was expensive. so we found a workaround to integrate a custom payment gateway with any Unity app.


Below are the steps I used for my app but it should be similar to your use case and for any other payment gateways. I personally feel Razorpay is very comfortable because have very good tech support and they have a feature that other payment gateways don’t have, I will come to that later.


So this is how it works.


Mostly every payment gateway has some sort of web-based checkout that works just with a browser. we decided to use that. since all we needed was a browser it was easy to open a webview. you can open a website directly from Unity using inbuilt functions but it was easy for me to use this asset — “UniWebView” It’s very easy and straightforward.


Razorpay Standard Web Integration (https://razorpay.com/docs/payment-gateway/web-integration/standard/)


UniWebView (https://uniwebview.com/)


The concept is straightforward,


I hosted a PHP page in my server with the standard checkout code and accessed that page from Unity webview. All values like name, price and other dynamic portions are passed as parameters. So we will have a pay now button or checkout button on our hosted page if you feel it as redundant or an extra step you can set auto-trigger whenever that page is loaded. Tada! Now you can collect payment from your customer. The remaining flow depends upon your use case.


If you are from India, you might face this problem. we have multi-factor authentication where you have to type One time password or some kind of pin. payment gateways like Stripe, and Paytm rather than redirecting our existing page, open a popup or a new window. this will work in ordinary browsers but since we are using the Unity web view it’s impossible for a popup.


This is where Razorpay is awesome. you can set whether you wanted to redirect or open a new window in their standard checkout code. you can read about this on this link (https://razorpay.com/docs/payment-gateway/callback-url/) in case if the link is outdated, you can feel free to check with Razorpay’s tech support they will assist you.


Let me know if there is something else that I have missed to mention here. Thank you :)