UPI Autopay and Recurring Payments in Flutter
The NPCI e-mandate flow for your Flutter app — subscription approval, first charge, and the amount limits that break real launches. So, in this article, I will be showing you how you can implement UPI AutoPay — the recurring payment feature built on NPCI e-mandates — in your Flutter app. A quick framing for anyone new to Indian payments. UPI AutoPay is NPCI's recurring payment system: your…
This article explains how to implement UPI AutoPay, a recurring payment feature based on NPCI e-mandates, in a Flutter application. UPI AutoPay allows customers to approve a mandate once and then have their accounts debited on a schedule, such as daily, weekly, or monthly, without needing to re-enter card details or re-approve each month. This method is widely used by subscription businesses in India through payment gateways like Razorpay, Cashfree, and PayU.
To implement UPI AutoPay in Flutter, follow these steps:
1. Create the mandate on your backend server instead of within the Flutter app. This ensures that gateway keys are never exposed. The backend should create the mandate using the customer's subscription plan, notify preferences, and other details, and then provide the subscription ID and an approval URL to the Flutter app.
2. In the Flutter app, create a service function that calls the backend to create the mandate. This function should send the desired amount and receive the approval URL from the backend.
3. Launch the approval flow by using the approval URL. Prefer launching the URL in an external app (e.g., the customer's UPI app) using the `launchUrl` function from the `url_launcher` package. If deep linking fails, fall back to displaying the gateway's hosted page in a `WebView`.
4. Handle the return to your app by intercepting the deep link that the gateway redirects back to your app after the customer approves or cancels the mandate. This can be achieved by using the `Navigator` class to push a new route with a `Scaffold` containing a `WebView` displaying the returned URL.
By following these steps, you can seamlessly integrate UPI AutoPay into your Flutter application, enabling recurring payments for your subscription-based services.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.