0

My Code:

const functions = require("firebase-functions");
const express = require("express");
const cors = require("cors");
const stripe = require("stripe")(
  "sk_test"
);

const app = express();

app.use(cors({ origin: true }));
app.use(express.json());

app.post("/payments/create", async (request, response) => {
  const total = request.query.total;

  console.log("Payment Request Recieved for: ", total);

  const paymentIntent = await stripe.paymentIntents.create({
    amount: total, 
    currency: "usd",
  });

  response.status(201).send({
    clientSecret: paymentIntent.client_secret,
  });
});
exports.api = functions.https.onRequest(app);

The problem is in this line: Image of the source of issue

and the error message that comes up is: Parsing error: Unexpected token =>

I have tried reinstalling everything but nothing seems to work

Would appreciate any help I can get

Nolan H
  • 6,205
  • 1
  • 5
  • 19

1 Answers1

0

What version of Node are you using? It seems unlikely for a new server to use a version old enough that arrow functions aren't supported, but you should check by running node -v. Then check the compatibility chart.

If your version doesn't support arrow function and you cannot update, you can rewrite the function using function (request, response) { ... }, though I would expect you to then also have issues with the async/await pattern.

Related answer: https://stackoverflow.com/a/36843758/12474862

Nolan H
  • 6,205
  • 1
  • 5
  • 19