Google pay 在测试模式下完全正常工作,但在此 API 中的“v1/ payment_intents”中设置实时密钥后,它无法正常工作并出现以下错误。我正在使用 Stripe 插件。
Future<void> startGooglePay() async {
final googlePaySupported = await Stripe.instance.isGooglePaySupported(IsGooglePaySupportedParams(testEnv:
false));
if (googlePaySupported) {
try {
// 1. fetch Intent Client Secret from backend
final response = await fetchPaymentIntentClientSecret();
print(response);
final clientSecret = response['client_secret'];
// 2.present google pay sheet
await Stripe.instance.initGooglePay(GooglePayInitParams( merchantName: "Test Name",
countryCode: 'US',testEnv: false));
await Stripe.instance.presentGooglePay(PresentGooglePayParams(clientSecret: clientSecret,currencyCode: "GBP"),);
await Stripe.instance.initPaymentSheet(paymentSheetParameters: SetupPaymentSheetParameters(
googlePay: PaymentSheetGooglePay(merchantCountryCode: 'US'),
paymentIntentClientSecret: response['client_secret'],
setupIntentClientSecret:response['client_secret'],
customerEphemeralKeySecret: response['client_secret'],
customerId:PLPrefrence.getPrefValue(key: PLPrefrence.user_code).toString()
));
await Stripe.instance.retrievePaymentIntent(response['client_secret']).then((value){
print(value.id);
print(value.status);
print(value.confirmationMethod.name);
});
} catch (e) {
print('ErrorStripePrint : ${e}');
errorDialog(errorMessage: "$e");
}
} else {
errorDialog(errorMessage: "Google pay is not supported on this device");
}
}
现在这是 payment_intents API 的 API 调用
Future<Map<String, dynamic>> fetchPaymentIntentClientSecret() async {
final url = Uri.parse('https://api.stripe.com/v1/payment_intents');
Map<String, dynamic> body = {
'amount':calculateAmount(amount: _plController.isUseWalletbalance.value ?
_plController.processedAmount.value : widget.grandTotal.toString()).toString(),
'currency': "GBP",
'payment_method_types[]': 'card',
};
final response = await http.post(
url,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer ${PLKeys.stripeSK_Live}',
},
body: body,
);
return json.decode(response.body);
}
如果我将 testEnv 设置为 true 并测试密钥,这样它就可以工作,但是设置 testEnv false 并设置条带实时模式密钥,这样它就不起作用,并且会出现上面上传图片的问题。
@Alpit Panchal 你解决这个问题了吗?请指导我。是否需要在 google pay 控制台中注册应用程序才能进行生产访问,才能启用 google pay stripe 的实时交易?