azhar1038 / UPI-Plugin-Flutter

Flutter Plugin to do UPI transaction using different apps like PhonePe, Google Pay, PayTM etc.
MIT License
53 stars 38 forks source link

When I'm using this UPI-Plugin-Flutter api...I'm getting following error in upi app: Payment Declined, For Security reasons, you are not allowed to send money from your bank account for this payment. You don't have to enter your UPI PIN to receive money/cashback. #42

Closed bhagyashrieducloud closed 3 years ago

bhagyashrieducloud commented 3 years ago

My code is following: import 'package:flutter/material.dart'; import 'package:flutter_app/src/CustomThemes/Theme.dart'; import 'package:upi_india/upi_india.dart';

class UpiPayPage extends StatefulWidget { @override _UpiPayPageState createState() => _UpiPayPageState(); }

class _UpiPayPageState extends State { Future _transaction; UpiIndia _upiIndia = UpiIndia(); List apps;

TextStyle header = TextStyle( fontSize: 18, fontWeight: FontWeight.bold, );

TextStyle value = TextStyle( fontWeight: FontWeight.w400, fontSize: 14, );

@override void initState() { _upiIndia.getAllUpiApps(mandatoryTransactionId: false).then((value) { setState(() { apps = value; }); }).catchError((e) { apps = []; }); super.initState(); }

Future initiateTransaction(UpiApp app) async { return _upiIndia.startTransaction( app: app, receiverUpiId: "7744556756@apl", receiverName: 'Ram Varma', transactionRefId: 'Testing Upi India Plugin', transactionNote: 'Not actual. Just an example.', amount: 1.00, ); }

Widget displayUpiApps() { if (apps == null) return Center(child: CircularProgressIndicator()); else if (apps.length == 0) { return Center( child: Text( "No apps found to handle transaction.", style: header, ), ); } else { return Align( alignment: Alignment.topCenter, child: SingleChildScrollView( physics: BouncingScrollPhysics(), child: Wrap( children: apps.map((UpiApp app) { return GestureDetector( onTap: () { _transaction = initiateTransaction(app); setState(() {}); }, child: Container( height: 100, width: 100, child: Column( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.center, children: [ Image.memory( app.icon, height: 60, width: 60, ), Text(app.name), ], ), ), ); }).toList(), ), ), ); } }

String _upiErrorHandler(error) { switch (error) { case UpiIndiaAppNotInstalledException: return 'Requested app not installed on device'; case UpiIndiaUserCancelledException: return 'You cancelled the transaction'; case UpiIndiaNullResponseException: return 'Requested app didn\'t return any response'; case UpiIndiaInvalidParametersException: return 'Requested app cannot handle the transaction'; default: return 'An Unknown error has occurred'; } }

void _checkTxnStatus(String status) { switch (status) { case UpiPaymentStatus.SUCCESS: print('Transaction Successful'); break; case UpiPaymentStatus.SUBMITTED: print('Transaction Submitted'); break; case UpiPaymentStatus.FAILURE: print('Transaction Failed'); break; default: print('Received an Unknown transaction status'); } }

Widget displayTransactionData(title, body) { return Padding( padding: const EdgeInsets.all(8.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text("$title: ", style: header), Flexible( child: Text( body, style: value, )), ], ), ); }

@override Widget build(BuildContext context) { return Theme( data: basicTheme1(), child: Scaffold( appBar: AppBar( title: Text('UPI'), ), body: Column( children: [ Expanded( child: displayUpiApps(), ), Expanded( child: FutureBuilder( future: _transaction, builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { if (snapshot.hasError) { return Center( child: Text( _upiErrorHandler(snapshot.error.runtimeType), style: header, ), // Print's text message on screen ); }

                // If we have data then definitely we will have UpiResponse.
                // It cannot be null
                UpiResponse _upiResponse = snapshot.data;

                // Data in UpiResponse can be null. Check before printing
                String txnId = _upiResponse.transactionId ?? 'N/A';
                String resCode = _upiResponse.responseCode ?? 'N/A';
                String txnRef = _upiResponse.transactionRefId ?? 'N/A';
                String status = _upiResponse.status ?? 'N/A';
                String approvalRef = _upiResponse.approvalRefNo ?? 'N/A';
                _checkTxnStatus(status);

                return Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      displayTransactionData('Transaction Id', txnId),
                      displayTransactionData('Response Code', resCode),
                      displayTransactionData('Reference Id', txnRef),
                      displayTransactionData('Status', status.toUpperCase()),
                      displayTransactionData('Approval No', approvalRef),
                    ],
                  ),
                );
              } else
                return Center(
                  child: Text(''),
                );
            },
          ),
        )
      ],
    ),
  ),
);

} }

azhar1038 commented 3 years ago

It is because if #32

RamHaridas commented 3 years ago

So, that's it? No solution?