cashfree_pg 1.2.2+16 cashfree_pg: ^1.2.2+16 copied to clipboard
The official Flutter plugin for Cashfree PG integration. It opens the payment page inside a webview.
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> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('CFSDK Sample'),
),
body: Column(
children: [
Center(
child: RaisedButton(
child: Text('DO PAYMENT'),
onPressed: () => makePayment(),
),
),
Center(
child: RaisedButton(
child: Text('DO UPI Payment'),
onPressed: () => makeUpiPayment(),
),
),
],
),
),
);
}
// 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
}));
}
}