API ReferenceIntegrationsKnowledge Base

Android Integration - Additional support for Payment Methods

Razorpay Android Standard SDK provides a host of payment methods for your Android app users to make payments. Here are some SDK methods you can use to provide additional support to these payment methods and optimize the payment experience.

UPI Intent Support: Target SDK Version 30+🔗

If your application targetSdkVersion is 30 or above, add the following code in your app's manifest file to support the UPI Intent flow.

Copy<queries> <!-- List of apps which you want to support for Intent pay --> <package android:name="com.google.android.apps.nbu.paisa.user" /> <package android:name="com.phonepe.app"/> <!-- Specific intents you query for, eg: for a custom share UI --> <intent> <action android:name="android.intent.action.SEND" /> </intent> </queries>

Card Utilities🔗

Given below are the methods provided by the SDK to support card payments. You can use the methods to:

  • Fetch card network
  • Verify the validity of a card number
  • Fetch card number length of a card network

Fetch Card Network🔗

You can fetch the card network of the card number provided by the customer using the getCardNetwork method. At least 6 digits of the card number are required to identify the network.

Possible values:

  • visa
  • mastercard
  • maestro16
  • American Express
  • rupay
  • maestro
  • diners
  • unknown (If unable to identify the network)

Validate Card Number🔗

You can determine the validity of the card number entered using the isValidCardNumber method. This is a checksum-based method to determine if the entered card number is valid or not.


Fetch Card Number Length for Card Network🔗

You can fetch the length of a card number for a specific card network using the getCardNetworkLength method.



Given below are the methods provided by the SDK to support netbanking and wallet payments. You can use these methods to fetch:

  • Bank Logo URL
  • Wallet Logo URL
  • Square-shaped Wallet Logo URL

Fetch Bank Logo URL🔗

You can use the getBankLogoUrl method to fetch the bank logo's URL. Here bankCode is the code of bank, which you can get from the response received in onPaymentMethodsReceived callback.


Fetch Wallet Logo URL🔗

You can use the getWalletLogoUrl method to fetch the wallet logo's URL.


Fetch Wallet Square Logo URL🔗

You can use the getWalletSqLogoUrl method to fetch the wallet's square-shaped logo's URL.


Data Validation🔗

The SDK provides basic validation for the payment data JSONObject. In case of a validation error, the SDK returns an error map in the onValidationError callback function.

The sample code shown below describes a validation error on the contact field:

Copyrazorpay.validateFields(payload, new Razorpay.ValidationListener() { @Override public void onValidationSuccess() { try { razorpay.submit(payload); } catch (Exception exception){} } @Override public void onValidationError(Map<String, String> error) { /** * The format for returned map is: * "field" : "contact" * "description" : "Descriptive error message" */ Toast.makeText(activity, "Validation: " + error.get("field") + " " + error.get("description"), Toast.LENGTH_SHORT).show(); } });

Custom WebViewClient and WebChromeClient🔗

Our SDK sets an instance of RazorpayWebViewClient and RazorpayWebChromeClient to the Webview passed to facilitate bank page optimizations. If you want to set your own custom WebViewClient you have to extend RazorpayWebViewClient and pass it to our SDK.

This step is optional and is only required when you want to set a custom WebViewClient/WebChromeClient

The sample code given below shows how to customize the RazorpayWebViewClient:

Copy/** * Extend the RazorpayWebViewClient for your custom hooks */ razorpay.setWebviewClient(new RazorpayWebViewClient(razorpay){ @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { // Make sure you don't forget to call the super method super.onPageStarted(view, url, favicon); Log.d(TAG, "Custom client onPageStarted"); } @Override public void onPageFinished(WebView view, String url) { // Make sure you don't forget to call the super method super.onPageFinished(view, url); Log.d(TAG, "Custom client onPageFinished"); } });

Similarly, you can set your own WebChromeClient:

Copy/** * Extend the RazorpayWebChromeClient for your custom hooks */ razorpay.setWebChromeClient(new RazorpayWebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { // Make sure you don't forget to call the super method super.onProgressChanged(view, newProgress); customProgressBar.setProgress(newProgress); } });

Save Customer Data🔗

You can associate card details with a saved customer or create payments using tokens for saved cards. To use this functionality, you must use customer APIs at server-side.

To create a payment with a new card, you must pass additional parameters customer_id and save along with the other parameters as shown below:

CopyJSONObject data = new JSONObject(); data.put("amount", 29935); data.put("customer_id", "cust_4lsdkfldlteskf"); data.put("save", 1); data.put("method", "card"); data.put("card[name]", "Gaurav Kumar"); data.put("card[number]", "4111111111111111"); data.put("card[expiry_month]", "12"); data.put("card[expiry_year]", "20"); data.put("card[cvv]", "100");

To create a payment with an existing saved card, you must pass the token parameter instead of the card number, expiry and card holder's name fields as shown below:

CopyJSONObject data = new JSONObject(); data.put("amount", 29935); data.put("customer_id", "cust_4lsdkfldlteskf"); data.put("token", "token_4zwefDSCC829ma"); data.put("method", "card"); data.put("card[cvv]", "100");