RAZORPAY POS Integration in Flutter — Android SDK Solution
As an intern on my first project, I was tasked with integrating a POS system using the Ezetap SDK in a Flutter app. The system was meant for a payment application installed on Razorpay’s POS machine, where the app would interact with the SDK to handle transactions. The challenge? The official documentation didn’t cover Flutter SDK integration, leaving me without a clear guide. But, with persistence, the support of Razorpay’s customer service, and guidance from my senior, I managed to navigate through the obstacles.
In this post, I’ll guide you through how I successfully integrated the POS system into my Flutter app.
Step 1: Install ezetap_sdk
To get started with integrating ezetap_sdk into your Flutter project, you need to add the ezetap_sdk package to your pubspec.yaml file:
dependencies:
ezetap_sdk: ^latest_version
After adding the dependency, run flutter pub get to install the package.
Step 2 : Changes in Android Manifest
While integrating Ezetap SDK, I ran into a manifest error related to permissions and configuration settings. Here are the essential AndroidManifest.xml changes I made:
- Internet Permission : The app needs to interact with payment gateways and services over the internet, hence the permission for internet access.
- Camera Permission : Since some devices may involve scanning QR codes or other camera-related operations, I included this permission with optional usage.
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
Step 3: Initialize Ezetap SDK
In this step, you’ll initialize the Ezetap SDK in your Flutter app, preparing it to handle payments.
- Import Package :
import 'package:ezetap_sdk/ezetap_sdk.dart';
- Initialize and Prepare the Device : In your initState method, initialize the SDK and prepare the device for handling payments.
@override
void initState() {
super.initState();
var configJson = {
"demoAppKey": "your app key",
"prodAppKey": "your app key",
"merchantName": "Merchant Name",
"userName": "User Name",
"currencyCode": "INR",
"appMode": "DEMO", // Change to "PROD" for production
"captureSignature": "false",
"prepareDevice": "false"
};
// Initialize the SDK
EzetapSdk.initialize(configJson);
// Prepare the device for payment
EzetapSdk.prepareDevice();
}
Step 4: Payment Initialization
Now that the SDK is initialized, let’s move to payment initialization. Here’s how you can handle a payment request.
var paymentJson = {
"amount": "", // payment amount
"options": {
"providerName": "",
"paymentMode": "Card", // "Payment Mode"
"customer": {
"email": "customer@example.com",
"mobileNo": "1234567890",
"name": "Customer Name"
}
}
};
String result = await EzetapSdk.pay(paymentJson)
.timeout(const Duration(seconds: 150), onTimeout: () {
throw TimeoutException("Payment timed out");
});
In any real-time payment scenario, there’s always a risk that the process could take too long due to network delays, device issues, or other unforeseen circumstances. To handle this gracefully, I utilized a TimeoutException.
Step 5: Handle Payment Responses
After initiating the payment, ensure your app processes the result. Based on the response, you can display messages for success or failure.
- Success : Log the transaction ID and show a success message.
- Failure : Log the error and show an appropriate error message to the user.
Top comments (0)