无法解析临时密钥.. CustomerSession.initCustomerSession stripe_sdk 包

Failed to parse Ephemeral Key.. CustomerSession.initCustomerSession stripe_sdk package

根据 Stripe 术语,我对如何正确初始化包感到有点困惑。

App => my platform ,它有一个 AccountId 和一个可发布的密钥。 帐户 => 连接到我的平台的任何卖家。 客户 => 任何向我的卖家付款的买家。

正如我最初理解的那样,我应该使用我的平台可发布密钥和我的平台 AccountId 初始化 Stripe,因为我看到了 stripeAccount 可选参数,但是我看到了文档提示 acc_ 所以很明显用 CustomerId 初始化 StripeAccountId 相反。

但随后我使用 api 版本(我在控制台中升级到最新版本)和 customerId(与上面相同)初始化 CustomerSession,但它显示了一个 Unhandled Exception: Failed to parse Ephemeral Key, Please return the response as it is as you received from stripe server 未被捕获声明。

你能帮我澄清一下吗?我环顾四周,但没有看到任何解释。 非常感谢。

这是我的初始化,我做错了什么?:

try {
              Stripe.init(Environment.stripePublishableKey,
                  stripeAccount: state.user.stripeId);

              CustomerSession.initCustomerSession((apiVersion) async {
                print('apiVersion is : $apiVersion');
                return apiVersion;
              }, apiVersion: '2020-08-27', stripeAccount: state.user.stripeId);
            } catch (error) {
              print('Stripe error: $error');
            }

这些是来自控制台的输出:

I/flutter (26067): apiVersion is : 2020-03-02
E/flutter (26067): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Failed to parse Ephemeral Key, Please return the response as it is as you received from stripe server
E/flutter (26067): #0      EphemeralKeyManager.retrieveEphemeralKey (package:stripe_sdk/src/ephemeral_key_manager.dart:101:9)
E/flutter (26067): <asynchronous suspension>
E/flutter (26067): 
[log] FormatException: Unexpected character (at character 5)
2020-03-02
    ^

``

终于好好看了方法说明

void initCustomerSession( 
Future<String> Function(String) provider,
{ String apiVersion = defaultApiVersion,
String stripeAccount,
bool prefetchKey = true,
})

我看到我需要使用节点服务器上的 Stipe api 创建它:

stripe.ephemeralKeys.create({customer: customer}, {apiVersion: apiVersion})
            .then((result) => {
                console.log('Mongoose findUser customer && stripe_version ephemeralKey is: ', result);
                if(result != null) {
                    res.status(200).send({message: 'Ephemeral key created successfully.', data : result});
                } else {
                    res.status(400).send({message: 'Ephemeral key not created'});
                }
            }).catch((err) => {
                console.log('Mongoose findUser customer && stripe_version ephemeralKey error: ', err);
                res.status(503).send({message: 'Internal error, Ephemeral key not created'});
            });

使用我的存储库中命中端点的方法检索它:

Future<String> getEphemeralKey({String apiVersion, String stripeId}) async {
    String ephemeralKey;
    await _firebaseAuth.currentUser.getIdToken().then((idToken) {
      headers = {
        'Content-Type': 'application/json',
        'api_key': Environment.dbApiKey,
        'AuthToken': idToken
      };
    });
    var params = {'customer': stripeId, 'apiVersion': apiVersion};
    final Uri uri = Uri.http(Environment.dbUrl, 'api/users', params);

    await get(uri, headers: headers).then((resp) {
      if (resp.statusCode == 200) {
        ephemeralKey = jsonEncode(jsonDecode(resp.body)['data']);
      }
    }).catchError((e) {
      print('PaymentMongoRepository getEphemeralKey error: $e');
    });
    return ephemeralKey;
  }

最后我初始化客户会话:

Future<String> createCustomerEphemeralKey(
                  {String apiVersion, String customerId}) async {
                String ephemeralKey;
                await _mongoRepository
                    .getEphemeralKey(
                        apiVersion: apiVersion, stripeId: state.user.stripeId)
                    .then((key) {
                  ephemeralKey = key;
                }).catchError((e) {
                  print(
                      '∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞  AccountConnectionManager getEphemeralKey key error: $e');
                });
                return ephemeralKey;
              }

              CustomerSession.initCustomerSession(
                  (apiVersion) => createCustomerEphemeralKey(
                      apiVersion: '2020-08-27',
                      customerId: state.user.stripeId),
                  stripeAccount: state.user.stripeId);

该方法需要 json 格式字符串中的临时密钥(除错误外,未在任何地方指定:

Unhandled Exception: Failed to parse Ephemeral Key, `Please return the response as it is as you received from stripe server`

我在查看 ÈphimeralKey 的实际包代码时发现了它 .. 希望这可以帮助别人.. 干杯