我正在将Stripe与我的iOS项目集成到Firebase中,这是我尝试打开PaymentOptionsViewController(在我的iOS应用程序模拟器中(时收到的错误:
未处理的错误{错误:您没有提供API密钥。您需要在Authorization标头中使用Bearer auth提供API密钥(例如"Authorization:Bearer your_SECRET_key"(。请参阅https://stripe.com/docs/api#authentication有关详细信息,或者我们可以在https://support.stripe.com/.
这是我的nodejs index.js:中的代码
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const stripe = require("stripe")(functions.config().stripe.secret_test_key);
exports.createStripeCustomer = functions.firestore.document('users/{userId}').onCreate(async (snap, context) => {
const data = snap.data();
const email = data.email;
const customer = await stripe.customers.create({ email: email })
return admin.firestore().collection('users').doc(data.id).update({ stripeId : customer.id})
});
exports.createCharge = functions.https.onCall(async (data, context) => {
const customerId = data.customerId;
const totalAmount = data.total;
const idempotency = data.idempotency;
const uid = context.auth.uid
if (uid === null) {
console.log('Illegal access attempt due to unauthenticated user');
throw new functions.https.HttpsError('permission-denied', 'Illegal access attempt.')
}
return stripe.charges.create({
amount: totalAmount,
currency: 'usd',
customer: customerId
}, {
idempotency_key: idempotency
}).then( _ => {
return
}).catch( err => {
console.log(err);
throw new functions.https.HttpsError('internal', 'Unable to create charge')
});
})
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 user');
throw new functions.https.HttpsError('permission-denied', 'Illegal access attempt.')
}
let key = await stripe.ephemeralKeys.create(
{customer: '{{CUSTOMER_ID}}'},
{stripe_version: '{{2019-05-16}}'}
);
return stripe.ephemeralKeys.create(
{customer: customerId},
{stripe_version: stripeVersion}
).then((key) => {
return key
}).catch((err) => {
console.log(err)
throw new functions.https.HttpsError('internal', 'Unable to create ephemeral key.')
})
})
// exports.helloWorld = functions.https.onRequest((request, response) => {
// console.log('This is the console message.')
// response.send("Hello from JonnyB Codes!");
// });s
如何解决上述错误?如果需要更多信息才能得到答案,请告诉我。
在iOS中也收到了此错误消息。在我的情况下,在付款之前,应用程序启动时,我没有正确设置可发布密钥。斯威夫特就是这样。
Stripe.setDefaultPublishableKey("pk_test_....")
也许不能解决你的问题,但也许能给你一个线索。