Skip to main content

Mobile WebView

Overview

When integrating the Nimbbl Web checkout in mobile webviews, UPI apps need to be opened natively from the mobile app. This guide shows how to intercept UPI app URL schemes and handle redirects for Android, iOS, React Native, Flutter platforms.

RECOMMENDED

We strongly recommend using platform-specific SDKs (Android SDK, iOS SDK, React Native SDK, Flutter SDK) for better performance, seamless UPI handling, and optimized user experience. If you still prefer to use the Nimbbl Web checkout in a mobile WebView, this guide will help you handle UPI intent redirects properly.

Platform Integration

Override shouldOverrideUrlLoading

Override the shouldOverrideUrlLoading method in your WebView to intercept UPI app URLs and handle the redirection.

WebViewClient Implementation

import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import java.util.List;

public class PaymentWebViewClient extends WebViewClient {

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null) {
// Check if the URL is a UPI app scheme
String[] upiSchemes = {
"upi://pay", "amazonpay://pay", "credpay://pay",
"gpay://pay", "jupiter://pay", "kiwi://pay", "mobikwik://pay",
"navipay://pay", "popclubapp://pay", "paytmmp://pay",
"phonepe://pay", "super.money://pay", "whatsapp://pay",
"freecharge://pay"
};

boolean isUpiUrl = false;
for (String scheme : upiSchemes) {
if (url.startsWith(scheme)) {
isUpiUrl = true;
break;
}
}

if (isUpiUrl) {

// Create intent to open UPI app
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));

// Check if the UPI app is installed
PackageManager pm = getPackageManager();
List<ResolveInfo> resInfo = pm.queryIntentActivities(intent, 0);

if (!resInfo.isEmpty()) {
// UPI app is installed, open it
startActivity(intent);
} else {
// Handle case when UPI app is not installed
// You can show a message to the user or redirect to app store
showMessage("UPI app not installed. Please install the app to continue.");
}

return true; // URL handled, don't load in WebView
}
}
return false; // Let WebView handle other URLs
}
}

Usage in Activity

import android.webkit.WebView;
import android.webkit.WebSettings;

public class PaymentActivity extends AppCompatActivity {

private WebView webView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_payment);

webView = findViewById(R.id.webview);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);

// Set custom WebViewClient to handle UPI redirects
webView.setWebViewClient(new PaymentWebViewClient());

// Load Nimbbl checkout URL
String checkoutUrl = "https://sonic.nimbbl.tech/?token=YOUR_ORDER_TOKEN";
webView.loadUrl(checkoutUrl);
}
}

Supported UPI App Schemes

The following UPI app URL schemes are supported for handling UPI intent redirects:

UPI AppAndroid Base URLiOS App URL
Amazon Payamazonpay://payamazonpay://pay
CREDcredpay://paycred://pay
Google Paygpay://paygpay://pay
Jupiterjupiter://payjupiter://pay
Kiwikiwi://paykiwi://pay
MobiKwikmobikwik://paymobikwik://pay
NaviPaynavipay://paynavipay://pay
PopClubpopclubapp://paypopclubapp://pay
Paytmpaytmmp://paypaytm://pay
PhonePephonepe://payphonepe://pay
Super Moneysuper.money://paysupermoney://pay
WhatsApp Paywhatsapp://paywhatsapp://pay
Freechargefreecharge://payfreecharge://pay
Generic UPIupi://payupi://pay

Best Practices

  1. Error Handling: Always handle the case when a UPI app is not installed. Provide clear feedback to users and optionally redirect them to the app store.

  2. User Experience: Show loading indicators while the UPI app is opening to provide better user feedback.

  3. Testing: Test with multiple UPI apps to ensure all redirects work correctly.

  4. Fallback: Consider implementing a fallback mechanism if the UPI app fails to open.

  5. Security: Validate URLs before opening them to prevent security vulnerabilities.

Troubleshooting

UPI App Not Opening

  • Ensure the URL scheme is correctly added to your app's configuration
  • Check that the UPI app is installed on the device
  • Verify that the URL format matches the expected scheme

WebView Not Loading Checkout

  • Ensure JavaScript is enabled in your WebView
  • Check that the checkout URL is correct and accessible
  • Verify network permissions are granted

Payment Not Completing

  • Ensure the WebView can navigate back to your app after payment
  • Check that callback URLs are properly configured
  • Verify that the order token is valid
IMPORTANT
  • Always test UPI redirects on real devices, as simulators may not have UPI apps installed
  • Ensure proper error handling for cases when UPI apps are not available
  • Keep your WebView implementation updated to handle new UPI app schemes