Overview
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.
- The first step is to visit the merchant’s store or website and select something to purchase.
- Now customers land on the checkout page of the merchant’s store and choose the payment method.
- 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.
- Now the payment processor confirms the payment and sends the proper response to the customer.
- 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.
- After successful payment, the bank deposits the funds into the merchant’s account as the final settlement.
Benefits of using Payment Gateways in games
- Provide different modes of payment in our games for the users.
- Avoid charges of publishers for IAP in games.
- 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.
Introduction of Phonepe
Phone pe is the leading payment option nowadays that provides many different modes of payment.
- Credit/Debit Card
- Net Banking
- UPI
- Wallet
Steps To Create Phonepe Plugin for Android
- 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 - 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
- Import the ‘YOUR_PHONEPE_PLUGIN.arr’ plugin into your unity project.
- 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.
maven { url https://phonepe.bintray.com/PhonePeIntentSDK" }
- Add the following dependencies in ‘launcherTemplate.gradle’.
implementation 'phonepe.intentsdk.android.release:IntentSDK:0.1.5' implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
- The next step is to enable those custom Gradle from the player settings in unity.
- Now it’s time to create a bridge between unity and the android plugin, so for that create a new file called ‘PPayNativeHelper.cs’
- Create two variables for set reference of native plugin and callback.
AndroidJavaObject androidJavaObject; Action PaymentCallbackHandler;
- Now in the Awake method, set the reference of the Phonepe plugin, and initialize it by calling the initialization method from the plugin.
public override void Awake() { base.Awake(); androidJavaObject = new AndroidJavaObject("com.yudiz.ppayunity.MainActivity"); androidJavaObject.Call("Initialize", this.gameObject.name); }
- 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.
public void StartPayment(string payload, string checksum, string endpoint, Action action) { PaymentCallbackHandler = action; androidJavaObject.Call("StartPayment", payload, checksum, endpoint); }
- The next step is to create a callback method ‘OnPPPaymentFlowCompleted‘, that we have called from the native plugin to Unity.
public void OnPPPaymentFlowCompleted(string data) { PaymentCallbackHandler(); PaymentCallbackHandler = null; }
- 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.
- 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.
public async void StartPaymentWithPhonepay() { string info = await GetPhonePayPaymentData(100);//for get payment data from server if (!string.IsNullOrEmpty(info)) { await Task.Delay(500); JSONNode obj = JSON.Parse(info); ppTransactionId = obj["data"]["iTransactionId"]; StartPayment(obj["data"]["base64Payload"], obj["data"]["checksum"], obj["data"]["apiEndpoint"], PPPaymentComplete); } }
- 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.
async void PPPaymentComplete() { string info = await CheckPPPaymentStatus(ppTransactionId);//Check transaction status if (!string.IsNullOrEmpty(info)) { Debug.Log("PPPaymentComplete: " + info); } }
Here is the sample response from Phonepe after the completion of the payment flow.
{ "success":true, "code":"PAYMENT_SUCCESS", "message":"Your payment is successful.", "data":{ "transactionId":"TX32321849644234", "merchantId":"UATMERCHANT", "providerReferenceId":"P1806151323093900554957", "amount":1000, "paymentState":"COMPLETED", "payResponseCode":"SUCCESS", "paymentModes":[ { "mode":"ACCOUNT", "amount":1000, "utr":"816626521616" } ], "transactionContext":{ } } }
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.
Conclusion
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.