【问题标题】:Trouble deploying cloud function -- stripe payment intentTrouble deploying cloud function -- stripe payment intent
【发布时间】:2022-12-01 22:04:44
【问题描述】:

I have been looking at this and rewriting, and I don't know where I've gone wrong, but I cannot get this to deploy to firebase. I have been through a "Access to fetch at ... from origin ... has been blocked by CORS policy" error.

When I follow the google docs to address the cors issue (https://cloud.google.com/functions/docs/samples/functions-http-cors), I get a failing to deploy error: Function failed on loading user code. This is likely due to a bug in the user code.

const functions = require("firebase-functions");

const stripe = require("stripe")("sk_test");

exports.stripePaymentIntentRequest = functions.https.onRequest(
  async (req, res) => {
    //set JSON content type and CORS headers for the response
    res.set("Access-Control-Allow-Origin", "*");

    if (req.method === "OPTIONS") {
      // Send response to OPTIONS requests
      res.set("Access-Control-Allow-Methods", "GET");
      res.set("Access-Control-Allow-Headers", "Content-Type");
      res.set("Access-Control-Max-Age", "3600");
      res.status(204).send("");
    }

  try {
    const { codeItem } = req.body;

  //Creates a new payment intent with amount passed in from the client
  
 const paymentIntent = await stripe.paymentIntents.create({
    amount: codeItem.num * codeItem.price * 100,
    currency: "usd",
    automatic_payment_methods: {
      enabled: true,
    },
  });

  res.send({
    paymentIntent: paymentIntent.client_secret,

    success: true,
  });
} catch (error) {
  res.send({ success: false, error: error.message });
}
}
);

【问题讨论】:

    标签: javascript node.js vue.js google-cloud-functions


    【解决方案1】:

    It looks like you are not escaping all the text from your notation in the middle.

    Try to replace it with:

    /*Creates a new payment intent with amount passed in from the 
        client */

    【讨论】:

    • Sorry -- that is just a stackoverflow thing. It is correct in the code. ill clarify in an edit
    猜你喜欢
    • 2020-12-09
    • 2020-10-05
    • 1970-01-01
    • 2020-03-14
    • 2021-01-20
    • 2021-06-12
    • 2021-05-11
    • 2020-09-07
    • 2020-02-19
    相关资源
    最近更新 更多