4th Aug 2021

Using Payment Gateways With Unity

Game Development

Written By, Hitesh Dabhi


The Payment Gateway Technology is used by the seller or by the merchant for collecting digital payments from their customers. Simply, we can say that a payment gateway is a technology that collects and transfer data from customers to the payment processor and then transfer response back to the customer.

As we all know, most people worldwide choose to go cashless while they are purchasing anything from any offline or online stores. So in this kind of situation, the importance of an online payment system will be increased, and for the establishment of an online payment system merchants must require a payment gateway to satisfy the goal of digital payment.

If you are an online seller or merchant then it’s not mandatory to be an expert in the payment gateway. but you must have the basic knowledge of how a digital payment flows from your customer’s bank account to your bank account, so let’s see how the payment gateway works.

How Payment Gateway works

The payment gateway is the main component of the digital payment processing system. The payment gateway is responsible for sending the customer’s information to the merchant acquiring bank, where the actual transaction is processed.

Payment gateway technology is always developing to satisfy customer’s choices and technical capacities. In the early days, we all know that terminals were accepting credit cards using magnetic strips, which require paper signatures to complete the payment. But with the rise of chip technologies, the signature part has been removed and now we need a PIN that is entered directly into the payment gateway. Nowadays, there is also an option for contactless purchases, many customers now using their mobile phones as a payment device in place of physical cards.

The payment gateway’s architecture is always different as it depends on whether it is an on-site payment or an online payment. The online payment gateway will need APIs that allow communicating with the payment processing network. in-store payment gateway will use POS terminals that connect with the payment processing network through the internet.

Now let’s understand how payment transfers from the customer’s bank to the merchant’s account.

  1. The first step is to visit the merchant’s store or website and select something to purchase.
  2. Now customers land on the checkout page of the merchant’s store and choose the payment method.
  3. After selecting a payment method now customer move to the payment page. Where customers add their payment details and payment gateway encrypt the data and transfer it to the payment processor.
  4. Now the payment processor confirms the payment and sends the proper response to the customer.
  5. If the customer’s bank approves the payment then the amount will be credited to the merchant’s account from the customer’s bank account and send a successful response to the customer, and if the customer’s bank declines the payment then it sends a failed response to the customer.
  6. After successful payment, the bank deposits the funds into the merchant’s account as the final settlement.

Benefits of using Payment Gateways in games

  1. Provide different modes of payment in our games for the users.
  2. Avoid charges of publishers for IAP in games.
  3. Better user experience and security.

Introduction of Native Plugins

For native plugin development, you can refer to the articles below as it has detailed information regarding the plugin development.

  1. Plugin For Android
  2. Plugin For unity java using android studio

Introduction of Phonepe

Phone pe is the leading payment option nowadays that provides many different modes of payment.

  1. Credit/Debit Card
  2. Net Banking
  3. UPI
  4. Wallet

Steps To Create Phonepe Plugin for Android

  1. Configure your server to initiate and validate the transaction. You can find a way to do that at the following link:
    Phone pe Reference API
  2. Now it’s time to create a plugin for Phonepe, for that you need to follow the instruction given in the above link.

Steps To Integrate Phonepe Plugin with Unity

  1. Import the ‘YOUR_PHONEPE_PLUGIN.arr’ plugin into your unity project.
  2. Now set up the ‘baseProjectTemplate.gradle’ file for the Phonepe. File is located at path: Assets/Plugins/Android/baseProjectTemplate.gradle. Add below line in repositories.
  3. Add the following dependencies in ‘launcherTemplate.gradle’.
  4. The next step is to enable those custom Gradle from the player settings in unity.player-settings
  5. Now it’s time to create a bridge between unity and the android plugin, so for that create a new file called ‘PPayNativeHelper.cs’
  6. Create two variables for set reference of native plugin and callback.
  7. Now in the Awake method, set the reference of the Phonepe plugin, and initialize it by calling the initialization method from the plugin.
  8. Create StartPayment methods with the same signature that we have created in the Phonepe native plugin. And make a call to the native plugins method from it.
  9. The next step is to create a callback method ‘OnPPPaymentFlowCompleted‘, that we have called from the native plugin to Unity.
  10. So now we have completed the bridge between the native plugin and unity, so now create one game object in your scene and attach ‘PPayNativeHelper.cs’ to it.
  11. Now you can start with the payment with Phonepe. To start payment you have to get payment data from your server and pass that data in the ‘StartPayment’ method so it will open Phonepe SDK to complete the transaction.
  12. After completing the payment flow it will send the response to the ‘PPPaymentComplete’ method so from this method you can validate the response with the server and get the status of your transaction.

    Here is the sample response from Phonepe after the completion of the payment flow.

    After successful integration, you will be able to make payment through the Phonepe in your game. The below screen is an example of how the Phonepe screen will be displayed to the users.



Hence, Payment Gateway will help you to collect digital payments from the users, so it’s a good practice to have a payment gateway in your game that uses real cash, it will reduce extra charges that are charged by the app publisher. you can create a native plugin of any native features for unity that is not supported directly by the unity. We have used many payment gateways in Rummy24, you can check from the following link Rummy24.

Written By,

Game Developer at Yudiz Solutions Pvt. Ltd