在我的flutter项目中,我试图使用flutter_stripe包集成Stripe支付。
我已经初始化和配置正确.但当试图提出paymentSheet什么也没有显示或发生.也没有错误的原因.因为它停留在行,并没有运行代码后,.我也尝试了插件简单的示例代码,以及但不工作,因为我想要.任何帮助将不胜感激.
main.dart
Stripe.publishableKey = StripeService.publishableKey;
Stripe.merchantIdentifier = 'merchant.flutter.stripe.test';
Stripe.urlScheme = 'flutterstripe';
await Stripe.instance.applySettings();
runApp(const MyApp());
}
字符串
service.dart
Future<void> initPaymentSheet() async {
try {
// 1. create payment intent on the server
final paymentSheetData = await createPaymentIntent("1200", 'usd');
print("payment intent created");
// create some billingdetails
final billingDetails = BillingDetails(
email: '[email protected]',
phone: '+48888000888',
address: Address(
city: 'Houston',
country: 'US',
line1: '1459 Circle Drive',
line2: '',
state: 'Texas',
postalCode: '77063',
),
); // mocked data for tests
// 2. initialize the payment sheet
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
applePay: true,
googlePay: true,
style: ThemeMode.dark,
testEnv: true,
merchantCountryCode: 'US',
merchantDisplayName: 'Prospects',
customerId: paymentSheetData!['customer'],
paymentIntentClientSecret: paymentSheetData['paymentIntent'],
customerEphemeralKeySecret: paymentSheetData['ephemeralKey'],
));
print("payment sheet created");
await Stripe.instance.presentPaymentSheet();
print("after payment sheet presented");
} on Exception catch (e) {
if (e is StripeException) {
print("Error from Stripe: ${e.error.localizedMessage}");
} else {
print("Unforeseen error: ${e}");
}
rethrow;
}
型
}
输出
I/flutter(14987):创建付款意向
I/flutter(14987):已创建付款单
3条答案
按热度按时间wydwbb8l1#
我检查你的后端响应,你使用的是“paymentIntent”而不是“client_secret”,你应该初始化你的付款表如下
字符串
mepcadol2#
我得到了解决方案,有一些不正确的参数值,而初始化付款单
错误
字符串
正确
型
cotxawn73#
如果你使用的是stripeconnect,请确保输入Stripe.stripeAccountId值,否则它会出错。
字符串