node.js - Stripe PaymentIntent.create 导致 TypeError : Cannot read property 'create' of undefined (google cloud functions)

标签 node.js firebase google-cloud-firestore google-cloud-functions stripe-payments

我在 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/

相关文章:

node.js - 用于多个 apache 虚拟主机的 Node api

javascript - 使 Stripe 不适用于测试信用卡号

android - 如何将音频从 Firebase 加载到应用程序?

firebase - 在 Firestore 中引用 Firebase 用户对象

javascript - React JS 上的 Firebase Firestore 双循环数据

javascript - Vuejs - 如何使用单个表单添加和编辑

node.js - Amazon EC2 Linux 上的 NPM 安装错误 MEAN.js 示例应用程序?

node.js - 如何使用适用于 Visual Studio 的 Node JS 工具在 Visual Studio 中调试 Yeoman 生成器 KO(使用 TypeScript 和 Gulp)Node JS 项目

android - Firebase 云消息传递 : How to set the notification icon on android?

ios - 标题 Collection View 中的分组数据