我在 Google 云函数中遇到此错误:
创建StripePaymentIntent tc5h001dke76 TypeError:无法在 cloudFunction (/srv/node_modules) 处的导出.createStripePaymentIntent.functions.https.onRequest (/srv/index.js:50:5) 处读取未定义的属性“创建”/srv/index.js:45:55/firebase-functions/lib/providers/https.js:49:9) 在/worker/worker.js:783:7 在/worker/worker.js:766:11 在 _combinedTickCallback (internal/process/next_tick.js: 132:7) 在 process._tickDomainCallback (内部/process/next_tick.js:219:9)
这是我的代码:
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const logging = require('@google-cloud/logging');
const stripe = require('stripe')(functions.config().stripe.token);
const currency = functions.config().stripe.currency || 'USD';
const express = require('express');
const app = express();
exports.createStripePaymentIntent = functions.https.onRequest(async (req, res) => {
const paymentIntent = await stripe.paymentIntents.create({
amount: 1099,
currency: 'gbp',
payment_method_types: ['card'],
});
return res.send('testResponse');
});
我已经尝试了此代码的许多排列,但为了清楚起见,我在这里保持简单。
我确实设法从“testResponse”获得响应,因为它正在被调用并以其他方式运行。
问题是我通常编写 Swift 代码,只是想在这里实现一个非常简单的 Stripe 实现,所以不可避免地会出现一些我看不到的简单问题。因此,如果答案可以保持非常简单,那将会很有帮助!
编辑使代码更清晰 - 谢谢Doug
最佳答案
所以最后我需要将 package.json 中的 stripe 更新为 "stripe": "^7.3.0"。
我将保留这个答案,因为这是 stipe 包中最近的更改,也许其他人会发现它有用。
关于node.js - Stripe PaymentIntent.create 导致 TypeError : Cannot read property 'create' of undefined (google cloud functions),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56905207/