1
votes

Im getting this error in google cloud functions:

createStripePaymentIntent tc5h001dke76 TypeError: Cannot read property 'create' of undefined at /srv/index.js:45:55 at exports.createStripePaymentIntent.functions.https.onRequest (/srv/index.js:50:5) at cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:49:9) at /worker/worker.js:783:7 at /worker/worker.js:766:11 at _combinedTickCallback (internal/process/next_tick.js:132:7) at process._tickDomainCallback (internal/process/next_tick.js:219:9)

Here is my code:

'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');
});

I have tried many permutations of this code, but for clarity ive kept it simple here.

I do manage to get a response from 'testResponse' to it is being called and functioning otherwise.

The problem is i usually write Swift code and am just trying to get a very simple Stripe implementation going here so inevitably there will be some simple problems i dont see. Therefore if answers could be kept extremely simple that would be helpful!

edit made code clearer - thanks Doug

1
Embedding an anonymous async function inside another async function is not helpful. You can remove that anonymous function wrapper.Doug Stevenson

1 Answers

11
votes

So all it was in the end was i needed to update stripe in my package.json to "stripe": "^7.3.0".

I will leave this answer up as it is a recent change in the stipe package and maybe someone else will find it useful.