How to Integrate Razorpay Payment Gateway in Android?
Last Updated :
04 May, 2025
Many apps nowadays require to have a payment gateway inside their application so that users can do any transactions inside their apps to purchase any product or any service. Many apps use the payment gateway features but the integration of this payment gateway is a difficult task in Android applications. So to make this task simple and easy Razorpay have provided a service with the help of this we can integrate the payment solutions in our app very easily and we can also manage all payment methods in our app. In this article, we will take a look at the implementation of a payment gateway in our Android app.Â
What we are going to build in this article?Â
We will be building a simple Android application in which we will be displaying an EditText and a button. Inside this screen, we have to add the amount which is to be paid and on clicking the button we will open the Razorpay payment gateway and will make a payment. In this article, we will be adding test credentials for implementing Razorpay in Android. A sample video is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java & Kotlin language.Â
Step by Step Implementation
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.
Step 2: Add dependency of Razor pay library in build.gradle file
Navigate to the Gradle Scripts > build.gradle(Module:app) and add the below dependency in the dependencies section. Â Â
dependencies {
...
implementation ("com.razorpay:checkout:1.6.40")
}
 After adding this dependency sync your project and now we will move towards the XML part.Â
Step 3: Adding permissions to the Internet
Navigate to the app > manifests > AndroidManifest.xml file and add the below code to it.Â
<uses-permission android:name="android.permission.INTERNET" />
Step 4: Working with the activity_main.xml file
Navigate to the app > res > layout > activity_main.xml and add the below code to that file.
activity_main.xml:
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
<!--EditText text to enter amount-->
<EditText
android:id="@+id/idEdtAmount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="24dp"
android:hint="Enter amount to be payed"
android:inputType="number" />
<!--button to make payment-->
<Button
android:id="@+id/idBtnPay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pay using RazorPay" />
</LinearLayout>
Step 5: Generating an API key for using Razorpay
Browser the Razorpay site in Google or you can click on the link here. After clicking on this link you simply have to signup with your email and password and add some basic information such as your phone number.Â

Note: Here we are creating a testing credential for using Razor Pay.Â
Inside the setting screen, click on Create a new key option your key will be generated. We will be using key ID in our application to test Razor pay. The key-id will start with rzp_testÂ

Step 6: Working with the MainActivity file
Go to the MainActivity file and refer to the following code. Below is the code for the MainActivity file. Comments are added inside the code to understand the code in more detail.
MainActivity.java
package org.geeksforgeeks.demo;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.razorpay.Checkout;
import com.razorpay.PaymentResultListener;
import org.json.JSONException;
import org.json.JSONObject;
public class MainActivity extends AppCompatActivity implements PaymentResultListener {
// Declare edit text and button variables
private EditText amountEdt;
private Button payBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// initialize all the variables
amountEdt = findViewById(R.id.idEdtAmount);
payBtn = findViewById(R.id.idBtnPay);
// add on click listener to button
payBtn.setOnClickListener(v -> {
// get amount entered by user
String userInput = amountEdt.getText().toString();
// round off the amount
int amount = Math.round(Float.parseFloat(userInput) * 100);
// initialize Razorpay account
Checkout checkout = new Checkout();
// add your own key id here
checkout.setKeyID("Enter your key id here");
// set image
checkout.setImage(R.drawable.gfg_logo);
// initialize json object
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("name", "Geeks for Geeks");
jsonObject.put("description", "Test payment");
jsonObject.put("theme.color", "");
jsonObject.put("currency", "INR");
jsonObject.put("amount", amount);
jsonObject.put("prefill.contact", "9999999999");
jsonObject.put("prefill.email", "[email protected]");
// open razorpay to checkout activity
checkout.open(MainActivity.this, jsonObject);
} catch (JSONException e) {
e.printStackTrace();
}
});
}
@Override
public void onPaymentSuccess(String s) {
// this method is called on payment success.
Toast.makeText(this, "Payment is successful : " + s, Toast.LENGTH_SHORT).show();
}
@Override
public void onPaymentError(int i, String s) {
// on payment failed.
Toast.makeText(this, "Payment Failed due to error : " + s, Toast.LENGTH_SHORT).show();
}
}
MainActivity.kt
package org.geeksforgeeks.demo
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.razorpay.Checkout
import com.razorpay.PaymentResultListener
import org.json.JSONException
import org.json.JSONObject
class MainActivity : AppCompatActivity(), PaymentResultListener {
// Declare edit text and button variables
private lateinit var amountEdt: EditText
private lateinit var payBtn: Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// initialize all the variables
amountEdt = findViewById(R.id.idEdtAmount)
payBtn = findViewById(R.id.idBtnPay)
// add on click listener to button
payBtn.setOnClickListener {
// get amount entered by user
val userInput = amountEdt.getText().toString()
// round off the amount
val amount = Math.round(userInput.toFloat() * 100)
// initialize Razorpay account
val checkout = Checkout()
// add your own key id here
checkout.setKeyID("Enter your key id here")
// set image
checkout.setImage(R.drawable.gfg_logo)
// initialize json object
val jsonObject = JSONObject()
try {
jsonObject.put("name", "Geeks for Geeks")
jsonObject.put("description", "Test payment")
jsonObject.put("theme.color", "")
jsonObject.put("currency", "INR")
jsonObject.put("amount", amount)
jsonObject.put("prefill.contact", "9999999999")
jsonObject.put("prefill.email", "[email protected]")
// open razorpay to checkout activity
checkout.open(this@MainActivity, jsonObject)
} catch (e: JSONException) {
e.printStackTrace()
}
}
}
override fun onPaymentSuccess(s: String) {
// this method is called on payment success.
Toast.makeText(this, "Payment is successful : $s", Toast.LENGTH_SHORT).show()
}
override fun onPaymentError(i: Int, s: String) {
// on payment failed.
Toast.makeText(this, "Payment Failed due to error : $s", Toast.LENGTH_SHORT).show()
}
}
Output:
As we are using test credentials so our payment will not be done. For making your payments live you have to make your application live in the Razorpay console and generate a new key.Â
Similar Reads
How to Integrate Razorpay Payment Gateway in Flutter?
Razorpay helps process online payments for online as well as offline businesses. Razor pay allows you to accept credit cards, debit cards, net banking, wallet, and UPI payments with the Mobile App integration. It uses a seamless integration, allowing the customer to pay on your app/website without b
5 min read
How to Integrate Google reCAPTCHA in Android?
Google reCAPTCHA is one of the services provided by Google which is used to verify whether the user is a bot or not. The Google reCAPTCHA is seen in many websites and applications to verify the users. In this article, we will take a look at the implementation of Google reCAPTCHA in Android. What we
7 min read
How to Integrate In-App Review API into Android App?
Once we publish our app over the PlayStore and as it became live there, app rating and reviews become very crucial to driving audience and downloads to your app. In order to increase this, we ask our users to rate the app through a popup window and redirecting them to the PlayStore. But this nowaday
3 min read
How to Integrate Facebook Audience Network (FAN) Native Ads in Android?
In order to earn money from the Android app or game, there are many ways such as in-App Purchases, Sponsorship, Advertisements, and many more. But there is another popular method to earn money from the Android app is by integrating a third-party advertisement e.g known as Facebook Audience Network (
10 min read
How to Create Swipe Navigation in Android?
When talking about Android Apps, the first thing that comes to mind is variety. There are so many varieties of Android apps providing the user with a beautiful dynamic UI. One such feature is to navigate our Android Apps using left and right swipes as opposed to clicking on buttons. Not only does it
6 min read
UPI Payment Integration in Android using Jetpack Compose
If you are selling any product or providing any service in your android application, then you should have integrated a feature in your android application where you can allow users to make payments through your application. In this article, we will take a look at the implementation of payment gatewa
4 min read
How to Integrate Google Admob Rewarded Video Ads in Android?
In order to earn money from the Android app or game, there are many ways such as in-app purchases, Sponsorship, Advertisements, and many more. But there is another popular method to earn money from the Android app is by integrating an advertisement e.g. known as Google AdMob. Google AdMob is designe
7 min read
How to Update Data in Realm Database in Android?
In previous articles, we have seen adding and reading data from our realm database in Android. In that article, we were adding course details in our database and reading the data in the form of a list. In this article, we will take a look at updating this data in our android app. What we are going
7 min read
How to Use Google Play Install Referrer API in Android?
Google Play Install Referrer is the API that is used in most of the applications but it is not been seen in the app. This functionality works under the hood and is used to check the sources from where the app is getting most of the downloads. Google Play Install Referrer API tells us that from where
5 min read
How to Integrate Facebook Audience Network (FAN) Interstitial Ads in Android?
In order to earn money from the Android app or game, there are many ways such as in-App Purchases, Sponsorship, Advertisements, and many more. But there is another popular method to earn money from the Android app is by integrating a third party advertisement e.g known as Facebook Audience Network (
6 min read