繁体   English   中英

如何使用 Firebase 函数在 iOS 中获取条带临时密钥?

[英]How do I use a Firebase Function to get a stripe emphemeral key in iOS?

我正在尝试使用 firebase 函数从 Stripe 中获取一个临时密钥。 这是我在 firebase 日志中看到的错误:

getStripeEphemeralKeysUnhandled 错误类型错误:无法在 func (/workspace/node_modules/firebase-functions/lib/providers/ 的exports.getStripeEphemeralKeys.functions.https.onCall (/workspace/index.js:40:42) https.js:273:32) 在 process._tickCallback (internal/process/next_tick.js:68:7)

这是在 xcode 控制台中显示的错误:

创建临时密钥时出错:Error Domain=com.firebase.functions Code=13 "INTERNAL" UserInfo={NSLocalizedDescription=INTERNAL} INTERNAL

用 Javascript 编写的 firebase 函数:

 const functions = require('firebase-functions'); const stripe_key = "sk_test_LT2Wc4v9kUD6XxG8Nq2LNh4P00thTqtiSa" const admin = require('firebase-admin'); var stripe = require('stripe')(stripe_key); admin.initializeApp(functions.config().firebase); exports.createStripeCustomer = functions.https.onCall(async (data, context) => { const full_name = data.full_name; const email = data.email; const customer = await stripe.customers.create({ email: email, name: full_name, description: full_name }); console.log('new customer created: ', customer.id) return { customer_id: customer.id } }); exports.getStripeEphemeralKeys = functions.https.onCall(async (data, context) => { const api_version = data.api_version; const customer_id = data.customer_id; const key = await stripe.ephemeralKeys.create ( {customer: customer_id}, {apiVersion: api_version} ); return key; });

使用 swift 的 iOS 调用

func createCustomerKey(withAPIVersion apiVersion: String, completion: @escaping STPJSONResponseCompletionBlock) {
        let stripe_customer_id = MyDefaults.getDefaultsForCustID()
        functions.httpsCallable("getStripeEphemeralKeys").call(["api_version" : apiVersion, "customer_id" : stripe_customer_id]) { (response, error) in
            if let error = error {
                completion(nil, error)
            }
            if let response = (response?.data as? [String: Any]) {
                completion(response, nil) 
            }
        }
    }

我对 Javascript 不够精通,无法知道错误的含义,除了 create 这个词似乎有问题。 任何想法都非常感谢!

好的,谢谢@floatingLomas #Rafael Lemos。 你们走在正确的轨道上。 这是条纹版本。 我遇到了一些 pod 错误,我正在推动稍后修复,因此清理并更新了可可豆荚 ruby​​ 和 npm...

我现在很好——谢谢!!!

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM