我在我的 flutter 应用程序中使用了一个 sdk 中的 Paytm它抛出 PlatformException 错误

问题描述

在我的应用程序的一个页面中,我正在调用 startTransaction() 插件方法,并将响应存储在 paytm 文档中。在收到响应时,我想将成功或失败的状态返回到上一页。所以在 init() 函数中,我调用一个异步方法来 startTransaction 并检查响应。

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.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(),],);
            }
        ),);
  }

  
}```

解决方法

您需要根据交易中使用的订单ID和MID调用交易状态API。不需要再次调用starttransaction方法