payment_gateway_plugin 2.0.0 copy "payment_gateway_plugin: ^2.0.0" to clipboard
payment_gateway_plugin: ^2.0.0 copied to clipboard

Omniware's Payment Gateway Plugin for Flutter

example/lib/main.dart

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:payment_gateway_plugin/payment_gateway_plugin.dart';
import 'hash_generator.dart'; // Import the hash generator file

void main() {
  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
                    // 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,
                    ),
                  ),
                ),
            ],
          ),
        ),
      ),
    );
  }

  void open(Map<String, dynamic> request, BuildContext context) async {
    try {
      response = await PaymentGatewayPlugin.open(
        'https://pgbiz.omniware.in', request
      );
      // Response Handling
      var r = jsonDecode(response);
      print(r['status']);
      print(r['payment_response']);
    } on PlatformException {
      response = 'Failed to get initiate.';
    }
    setState(() {
      paymentResponse = response;
    });
  }
}
0
likes
0
points
289
downloads

Publisher

unverified uploader

Weekly Downloads

Omniware's Payment Gateway Plugin for Flutter

Homepage

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on payment_gateway_plugin