payment_gateway_plugin 3.0.6 payment_gateway_plugin: ^3.0.6 copied to clipboard
Omniware's Payment Gateway Plugin for Flutter
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:payment_gateway_plugin/payment_gateway_plugin.dart';
import 'hash_generator.dart';
void main() {
PaymentGatewayPlugin.init();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: _AppState(),
);
}
}
class _AppState extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<_AppState> {
dynamic response;
String paymentResponse = "";
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Payment Gateway'),
),
body: Padding(
padding: const EdgeInsets.all(10),
child: ListView(
children: <Widget>[
Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(10),
child: const Text(
'Welcome Payment Gateway',
style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.w500,
fontSize: 30,
),
),
),
Container(
height: 50,
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
child: ElevatedButton(
child: const Text('Pay Now'),
onPressed: () {
final params = getParams(); // Get parameters from hash_generator
print("Params => " + params.toString());
// Initiate payment
open(params, context);
},
),
),
if (paymentResponse.isNotEmpty)
Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(10),
child: Text(
'Payment Response : $paymentResponse',
style: const TextStyle(
color: Colors.blue,
fontWeight: FontWeight.w500,
fontSize: 20,
),
),
),
if(paymentResponse.isEmpty)
Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(10),
child: const Text(
'Payment Response is Empty',
style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.w500,
fontSize: 20,
),
),
),
],
),
),
),
);
}
void open(Map<String, dynamic> request, BuildContext context) async {
try {
print("Request Params => " + request.toString());
response = await PaymentGatewayPlugin.open('https://pgbiz.omniware.in', request);
if (response != null) {
print("Response => ${response.toString()}"); // This prints the map to console
String status = response['status'] ?? 'Unknown';
String responseMessage = response['response']?.toString() ?? 'No response';
setState(() {
paymentResponse = "Status: $status\nResponse: $responseMessage";
});
} else {
setState(() {
paymentResponse = "No response received from the payment gateway.";
});
}
} on PlatformException {
setState(() {
paymentResponse = 'Failed to initiate payment.';
});
}
}
}