dart Flutter Stripe未显示/出示付款单

szqfcxe2  于 12个月前  发布在  Flutter
关注(0)|答案(3)|浏览(118)

在我的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):已创建付款单

wydwbb8l

wydwbb8l1#

我检查你的后端响应,你使用的是“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'],
));

字符串

mepcadol

mepcadol2#

我得到了解决方案,有一些不正确的参数值,而初始化付款单

错误

paymentIntentClientSecret: paymentSheetData['paymentIntent'],

字符串

正确

paymentIntentClientSecret: paymentIntentData!['client_secret'],

cotxawn7

cotxawn73#

如果你使用的是stripeconnect,请确保输入Stripe.stripeAccountId值,否则它会出错。

Stripe.stripeAccountId = paymentDetails.stripe_account_id;

      await Stripe.instance.applySettings();

      if (Stripe.stripeAccountId == '') {
        print(
            'You need to connect your Stripe account via the dashboard.');
        return;
      }
    ```

字符串

相关问题