我正在尝试通过以下代码在Google支付上实施Google Pay。
void onButtonPressed() async{
setState((){_googlePayToken = "Fetching";});
try {
await GooglePay.openGooglePaySetup(
price: "0.5",
onGooglePaySuccess: onSuccess,
onGooglePayFailure: onFailure,
onGooglePayCanceled: onCancelled);
setState((){_googlePayToken = "Done Fetching";});
} on PlatformException catch (ex) {
setState((){_googlePayToken = "Failed Fetching";});
}
}
void onSuccess(String token){
setState((){
Navigator.popUntil(
context,
(_) => !Navigator
.canPop(
context));
Navigator.pushReplacement(
context,
new CupertinoPageRoute(
builder: (BuildContext
context) =>
userNoteHome()));
_googlePayToken = token;
});
}
void onFailure(){
setState((){
showDialog(
barrierDismissible: false,
context: context,
builder: (context) {
return CupertinoAlertDialog(
title: Text("Payment Failed",style: TextStyle(color: darkbrown,fontFamily: 'Montserrat',fontWeight: FontWeight.bold),),
content: Padding(padding:EdgeInsets.only(top: 5),child:Text("Will you like to try again?",style: TextStyle(fontFamily: 'Montserrat'),)),
actions: <Widget>[
FlatButton(
onPressed: () async {
onButtonPressed();
Navigator.of(context, rootNavigator: true).pop();
},
child: Text('Yes',style: TextStyle(color: darkbrown,fontFamily: 'Montserrat',fontWeight: FontWeight.bold),)),
FlatButton(
onPressed: () async {
// onButtonPressed();
Navigator.of(context, rootNavigator: true).pop();
},
child: Text('No',style: TextStyle(color: darkbrown,fontFamily: 'Montserrat',fontWeight: FontWeight.bold),)),
],
);
});
_googlePayToken = "Failure";
});
}
void onCancelled(){
setState((){_googlePayToken = "Cancelled";
showDialog(
barrierDismissible: false,
context: context,
builder: (context) {
return CupertinoAlertDialog(
title: Text("Payment Cancelled",style: TextStyle(color: darkbrown,fontWeight: FontWeight.bold,fontFamily: 'Montserrat'),),
content: Padding(padding:EdgeInsets.only(top: 5),child:Text("Are you sure you want to cancel payment?",style: TextStyle(fontFamily: 'Montserrat'),)),
actions: <Widget>[
FlatButton(
onPressed: () async {
// onButtonPressed();
Navigator.of(context, rootNavigator: true).pop();
},
child: Text('Yes',style: TextStyle(color: darkbrown,fontWeight: FontWeight.bold,fontFamily: 'Montserrat'),)),
FlatButton(
onPressed: () async {
onButtonPressed();
Navigator.of(context, rootNavigator: true).pop();
},
child: Text('No',style: TextStyle(color: darkbrown,fontWeight: FontWeight.bold,fontFamily: 'Montserrat'),)),
],
);
});
});
}
我收到此错误消息,提示“无法识别的应用。请确保您信任此应用,然后再继续”。起初,我以为是因为它处于测试模式,所以我在Google Play商店中部署了该应用程序,但错误仍然相同。