cashfree_pg 1.2.4+20 cashfree_pg: ^1.2.4+20 copied to clipboard
The official Flutter plugin for Cashfree PG integration. It opens the payment page inside a webview.
import 'dart:convert';
import 'dart:typed_data';
import 'package:cashfree_pg/cashfree_pg.dart';
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(home: MyApp()));
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Uint8List _imageBytesDecoded;
List<dynamic> appList;
Map<dynamic, dynamic> app;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('CFSDK Sample'),
),
body: Column(
children: [
Center(
child: ElevatedButton(
child: Text('DO PAYMENT'),
onPressed: () => makePayment(),
),
),
Center(
child: ElevatedButton(
child: Text('DO UPI Payment'),
onPressed: () => makeUpiPayment(),
),
),
Center(
child: ElevatedButton(
child: Text('Get UPI Apps'),
onPressed: () => getUPIApps(),
),
),
Center(
child: this._imageBytesDecoded != null ? Image.memory(_imageBytesDecoded,fit: BoxFit.cover,) : Icon(Icons.image),
)
],
),
),
);
}
void getUPIApps() {
CashfreePGSDK.getUPIApps().then((value) => {
this.setState(() {
for(int i = 0; i < value.length; i++) {
print(value[i]["id"]);
}
app = value[1];
_imageBytesDecoded = Base64Codec().decode(app["icon"]);
})
});
}
// WEB Intent
makePayment() {
//Replace with actual values
String orderId = "ORDER_ID";
String stage = "PROD";
String orderAmount = "ORDER_AMOUNT";
String tokenData = "TOKEN_DATA";
String customerName = "Customer Name";
String orderNote = "Order_Note";
String orderCurrency = "INR";
String appId = "APP_ID";
String customerPhone = "9094395340";
String customerEmail = "sample@gmail.com";
String notifyUrl = "https://test.gocashfree.com/notify";
Map<String, dynamic> inputParams = {
"orderId": orderId,
"orderAmount": orderAmount,
"customerName": customerName,
"orderNote": orderNote,
"orderCurrency": orderCurrency,
"appId": appId,
"customerPhone": customerPhone,
"customerEmail": customerEmail,
"stage": stage,
"tokenData": tokenData,
"notifyUrl": notifyUrl
};
CashfreePGSDK.doPayment(inputParams)
.then((value) => value?.forEach((key, value) {
print("$key : $value");
//Do something with the result
}));
}
// UPI Intent
Future<void> makeUpiPayment() async {
//Replace with actual values
String orderId = "ORDER_ID";
String stage = "PROD";
String orderAmount = "ORDER_AMOUNT";
String tokenData = "TOKEN_DATA";
String customerName = "Customer Name";
String orderNote = "Order_Note";
String orderCurrency = "INR";
String appId = "APP_ID";
String customerPhone = "9094395340";
String customerEmail = "sample@gmail.com";
String notifyUrl = "https://test.gocashfree.com/notify";
Map<String, dynamic> inputParams = {
"orderId": orderId,
"orderAmount": orderAmount,
"customerName": customerName,
"orderNote": orderNote,
"orderCurrency": orderCurrency,
"appId": appId,
"customerPhone": customerPhone,
"customerEmail": customerEmail,
"stage": stage,
"tokenData": tokenData,
"notifyUrl": notifyUrl
};
CashfreePGSDK.doUPIPayment(inputParams)
.then((value) => value?.forEach((key, value) {
print("$key : $value");
//Do something with the result
}));
}
}