无法在我的快递服务器中为条带支付结账创建 API

can not make an API in my express server for the strip payment checkout

我收到这个错误:

Uncaught (in promise) IntegrationError: Invalid value for stripe.confirmCardPayment intent secret: value should be a client secret of the form ${id}secret${secret}. You specified: client secret.

##“客户端密码是默认值”我需要更新它并且控制台需要显示实际客户端密码

后端代码

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

);

const app = express();

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

app.get("/", (request, response) => response.status(200).send("hello payment"));


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

    console.log("Payment Request Recieved >>> ", total);
    console.log(stripe)
    const paymentIntent = await stripe.paymentIntents.create({
        amount: total,
        currency: "usd",
    });


    response.status(201).send({
        clientSecret: paymentIntent.client_secret,
    });
});

// - Listen command
exports.api = functions.https.onRequest(app);

在支付js中调用api

useEffect(() => {

    const getClientSecret = async () => {
        const response = await axios({
            mehtod: 'post',


            url: `/payments/create?total=${totoalItemPrice(basket) * 100}`
        })


        setClientSecret(response.data.clientSecret)

    }
    getClientSecret();

}, [basket])

console.log('THE SECRET IS >>>', clientSecret)

确保您在前端确认卡支付:

const paymentConfirmation = await stripe.confirmCardPayment(
    client_secret,
);

您的服务器代码正在返回:

response.status(201).send({
    clientSecret: paymentIntent.client_secret,
});

但在客户端,您希望它的格式为:

setClientSecret(response.data.clientSecret)

当我将其记录到控制台时,响应对象看起来像:

{"clientSecret: "pi_someHashValueHere"}

要么修改服务端代码发送:

response.status(201).send({
    data: { clientSecret: paymentIntent.client_secret }
});

或者在客户端修改。目前您正在访问一个未定义的值,因此您会收到 IntegrationError。