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