Flutter Stripe 不显示/显示付款单
Posted
技术标签:
【中文标题】Flutter Stripe 不显示/显示付款单【英文标题】:Flutter Stripe does not show/present payment sheet 【发布时间】:2022-01-16 22:59:24 【问题描述】:在我的 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@stripe.com',
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):已创建付款表
【问题讨论】:
您从后端服务器获取的数据是否正确? 我建议您通过他们的 github 问题与开发人员/社区联系,看看他们是否可以在这里提出可能有帮助的建议:github.com/flutter-stripe/flutter_stripe/issues @vishnuanilkumar 后端响应textdoc.co/akteSsynvKdZREmP 请您检查并确认是否缺少任何内容或是否正确? @Dr_Usman,您能否确保 createPaymentIntent 的响应中存在“customer”、“paymentIntent”、“ephemeralKey”。如果其中 3 个有效,您还需要在条形仪表板中创建客户 【参考方案1】:我检查了您使用“paymentIntent”而不是“client_secret”的后端响应,您应该如下初始化您的付款表
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
applePay: true,
googlePay: true,
style: ThemeMode.dark,
testEnv: true,
merchantCountryCode: 'US',
merchantDisplayName: 'Prospects',
customerId: paymentSheetData!['customer'],
paymentIntentClientSecret: paymentSheetData['client_secret'],
customerEphemeralKeySecret: paymentSheetData['ephemeralKey'],
));
【讨论】:
【参考方案2】:我得到了解决方案,初始化付款单时参数值不正确
错误
paymentIntentClientSecret: paymentSheetData['paymentIntent'],
正确
paymentIntentClientSecret: paymentIntentData!['client_secret'],
【讨论】:
以上是关于Flutter Stripe 不显示/显示付款单的主要内容,如果未能解决你的问题,请参考以下文章