Search code examples
flutterexceptionhybrid-mobile-appplatformpaytm

I'm using the Paytm all in one sdk in my flutter application. It's throwing PlatformException error


In my app, in a page I'm calling the startTransaction() plugin method, and storing the response as in the paytm documentation. On recieving response, I want to return the the status whether it was success or failure to previous page. So in init() function I'm calling another async method to startTransaction and check for the response.

PlatformException (0, Unknown error, {response : { response of transaction})

class StartTransaction extends StatefulWidget {
  int orderId;
  double totalAmount;
  PaymentPayload paymentPayload;
  bool success;
  StartTransaction({this.orderId,this.totalAmount});
  @override
  _StartTransactionState createState() => _StartTransactionState();
}

class _StartTransactionState extends State<StartTransaction> {

@override
  void initState() {
    super.initState();
    initiateTransaction();
  }

  Future initiateTransaction() async {
    if(widget.success == null){
      widget.paymentPayload = await createPaymentGateway(
          widget.orderId,
          userBloc.userData.username,
        widget.totalAmount.toStringAsFixed(2),
          context);
      var pgResp = AllInOneSdk.startTransaction(
          widget.paymentPayload.mid,
          widget.orderId.toString(),
          widget.totalAmount.toStringAsFixed(2),
          widget.paymentPayload.txnToken,
          widget.paymentPayload.callbackUrl,
          true,
          false);
      pgResp.then((value) {
        print(value);
        setState(() {
          widget.success = value['RESPCODE'] == 01;
        });
      }).catchError((onError) {
        setState(() {
          widget.success = false;
        });
      });
    }
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: FutureBuilder(
            builder: (context, snapshot) {
              if(widget.success == true) {
                print('Payment successful');
                Navigator.pop(context,true);
              } else if(widget.success == false) {
                print('Payment unsuccessful');
                Navigator.pop(context,false);
              }
              return Center(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Text('We are processing your transaction', style: TextStyle(fontSize: 36),),
                    CircularProgressIndicator(),
                  ],
                ),
              );
            }
        ),
      ),
    );
  }

  
}```

Solution

  • You need to call transaction status API based on the order id and MID used in the transaction. There is no need to call the starttransaction method again