简体   繁体   English

Firebase Stripe 创建临时密钥的函数错误

[英]Firebase Functions Error for Stripe Create Ephemeral Key

I am attempting to use firebase-functions to create a Stripe ephemeral key via a tutorial.我正在尝试使用 firebase-functions 通过教程创建 Stripe 临时密钥。 Here is the node.js code to do so:这是执行此操作的 node.js 代码:

  exports.createEphemeralKey = functions.https.onCall(async (data, context) => {
 
    const customerId = data.customer_id;
    const stripeVersion = data.stripe_version;
    const uid = context.auth.uid;
   
    if (uid === null) {
        console.log('Illegal access attempt due to unauthenticated attempt.')
        throw new functions.https.HttpsError('internal', 'Illegal access attempt');
    }
   
    return stripe.ephemeralKeys.create(
      { customer: customerId },
      { stripe_version: stripeVersion }
    ).then((key) => {
      return key
    }).catch( (err) => {
      functions.logger.log('Error creating ephemeral key', err)
      throw new functions.https.HttpsError('internal', 'Unable to create ephemeral key: ' + err)
    });
  });

Immediately upon running, Xcode shows the following error code: Xcode一运行,立即显示如下错误代码:

Error Domain=com.firebase.functions Code=13 "INTERNAL" UserInfo={NSLocalizedDescription=INTERNAL}

When I click to Manage my credit cards (which triggers the Stripe Payment Sheet), the Stripe payment sheet never loads and just shows "Loading..."当我单击“管理我的信用卡”(触发 Stripe 付款表)时,Stripe 付款表从不加载,只显示“正在加载...”

My hunch is that my Swift code is OK, and that this is a problem solely with the node.js createEphemeralKey function. I think the customerID is fine, as I can generate it with a print function in Xcode. Might this be an issue with the stripeVersion?我的预感是我的 Swift 代码没问题,这只是 node.js createEphemeralKey function 的问题。我认为 customerID 没问题,因为我可以在 Xcode 中使用打印 function 生成它。这可能是 stripeVersion 的一个问题? Or something else?或者是其他东西?

here you will find how to check in the Firebase logs if the ephemeral key is created如果创建了临时密钥,您将在这里找到如何检查 Firebase 日志

Figured it out.弄清楚了。 There were two issues:有两个问题:

  1. You need to use camelcase (camelCase) as opposed to snakecase (snake_case).您需要使用驼峰式 (camelCase) 而不是蛇形 (snake_case)。
  2. You need to use apiVersion as opposed to stripeVersion.您需要使用 apiVersion 而不是 stripeVersion。

Here is the code that worked:这是有效的代码:

exports.createEphemeralKey = functions.https.onCall(async (data, context) => {
 
    const customerId = data.customerId;
    const apiVersion = data.stripeVersion;
    const uid = context.auth.uid;
   
    if (uid === null) {
        console.log('Illegal access attempt due to unauthenticated attempt.')
        throw new functions.https.HttpsError('internal', 'Illegal access attempt');
    }
   
    return stripe.ephemeralKeys.create(
      { customer: customerId},
      { apiVersion: apiVersion} 
    ).then((key) => {
      return key
    }).catch( (err) => {
      functions.logger.log('Error creating ephemeral key', err)
      throw new functions.https.HttpsError('internal', 'Unable to create ephemeral key: ' + err)
    })
  })

Then in Xcode remember to change your data:然后在Xcode记得改你的数据:

let data = [
"apiVersion": apiVersion,
"customerId": UserManager.instance.user?.stripeId
] 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase 调用 Stripe 时函数出错 - Firebase Functions error when calling Stripe “提供的 API 密钥无效”使用 firebase 云功能中的条带扩展 - "Invalid API Key provided" using the stripe extension in firebase cloud functions 使用 Firebase Cloud Functions 创建 Stripe Connect 帐户 - Creating a Stripe Connect account with Firebase Cloud Functions 使用 firebase、云函数和条纹的条纹支付表问题。 “意外字符(在第 2 行,字符 1) - Issue with Stripe Payment Sheet using firebase, cloud functions and stripe. "Unexpected Character (at line 2, character 1) <html><head> 将 Google Secret Manager 与 Firebase 函数和 Stripe(顶级)结合使用 - Using Google Secret Manager with Firebase Functions and Stripe (top level) 尝试部署 Firebase 功能时出现“意外的令牌条带” - "Unexpected token stripe" when trying to deploy Firebase Functions Firebase 功能:不清楚“连接错误” - Firebase Functions: Unclear "connection error" Firebase 功能不正确 statusCode 错误 - Firebase functions incorrect statusCode error Firebase 功能:错误:客户端离线 - Firebase Functions: Error: Client is offline Firebase 云函数捕获/处理错误 - Firebase cloud functions catch/handle error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM