flutter stripe付款错误尚未初始化付款单



我正在尝试在Flutter中实现条纹支付方法。

但是它给出了问题说:

颤振:异常/DISPLAYPAYMENTSHEET = =比;StripeException(错误:LocalizedErrorMessage(代码:FailureCode。Failed, localizedMessage: No付款表尚未初始化,提示:未初始化付款表stripeErrorCode: null, declineCode: null, type:#0 methodchannelstripe . _parsepaymentsheeresult(包:stripe_platform_interface/src/method_channel_stripe.dart: 310:11)# 1 MethodChannelStripe。presentPaymentSheet(包:stripe_platform_interface/src/method_channel_stripe.dart: 246:14)# 2 Stripe.presentPaymentSheet(包:flutter_stripe/src/stripe.dart:367:12) #3 FutureExtensions.onError。(飞镖:异步/future.dart: 1049:15)

我检查了Android上的所有构建设置以及iOS设置,一切正常。

这是我的代码对于分条支付方式:

Future<void> makePayment() async {
try {
paymentIntentData = await createPaymentIntent('20', 'USD');
await Stripe.instance
.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
paymentIntentClientSecret:
paymentIntentData != null ? ['client_secret'].join('') : null,
style: ThemeMode.light,
merchantDisplayName: 'John',
))
.then((value) {});
await displayPaymentSheet();
} catch (e) {
if (kDebugMode) {
print(e.toString());
}
}
}
displayPaymentSheet() async {
try {
await Stripe.instance.presentPaymentSheet().then((newValue) {
if (kDebugMode) {
print('payment intent${paymentIntentData!['id']}');
}
print('payment intent${paymentIntentData!['client_secret']}');
print('payment intent${paymentIntentData!['amount']}');
print('payment intent$paymentIntentData');
//orderPlaceApi(paymentIntentData!['id'].toString());
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text("Congratulation you have buy 20 Credits")));
paymentIntentData = null;
}).onError((error, stackTrace) {
if (kDebugMode) {
print('Exception/DISPLAYPAYMENTSHEET==> $error $stackTrace');
}
});
} on StripeException catch (e) {
if (kDebugMode) {
print('Exception/DISPLAYPAYMENTSHEET==> $e');
}
showDialog(
context: context,
builder: (_) => const AlertDialog(
content: Text("Cancelled "),
));
} catch (e) {
print('$e');
}
}
createPaymentIntent(String amount, String currency) async {
try {
Map<String, dynamic> body = {
'amount': calculateAmount(amount),
'currency': currency,
'payment_method_types[]': 'card'
};
var response = await http.post(
Uri.parse('https://api.stripe.com/v1/payment_intents'),
body: body,
headers: {
'Authorization':
'Bearer sk_test_key,
'Content-Type': 'application/x-www-form-urlencoded'
});
return jsonDecode(response.body.toString());
} catch (e) {
print(e.toString());
}
}
calculateAmount(String amount) {
final price = int.parse(amount) * 100;
return price.toString();
}

这是我的主文件:

void main() async {
WidgetsFlutterBinding.ensureInitialized();
Stripe.publishableKey = 'pk_test_';
Stripe.merchantIdentifier = 'any string works';
await Stripe.instance.applySettings();

runApp(const MyApp());
}

它不能在Android和iOS的真实设备上运行。我检查了Android和iOS上的所有构建设置。一切都很好。

我觉得你做这个的顺序不对。你需要遵循这个指南。

首先await是PaymentIntent的创建,然后awaitinitPaymentSheet,你从PaymentIntent创建方法传递秘密,然后presentPaymentSheet

相关内容

  • 没有找到相关文章