You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

集成Stripe支付API时遇Cannot POST错误,寻求技术协助

Stripe API集成问题求助

各位开发者好:

我在项目中集成Stripe API时遇到问题,访问http://localhost:5005/create-checkout-session时出现错误提示Cannot POST /create-checkout-session。

同时还有以下疑问和问题:

  • 是否需要为SuccessPage创建额外路由及客户端页面?
  • 此前严格遵循Stripe文档复制代码并启动服务器,预期客户端会渲染Checkout页面,但并未实现。
  • 已创建success路由,也添加了ProductDisplay页面,但无法访问http://localhost:3000/checkout路由。

代码片段

server.js

const app = require("./app");
const stripe = require('stripe')('');
const express = require('express');
app.use(express.static('public'));

const YOUR_DOMAIN = 'http://localhost:4242';

// ℹ️ Sets the PORT for our app to have access to it. If no env has been set, we hard code it to 5005
const PORT = process.env.PORT || 3000;

app.post('/create-checkout-session', async (req, res) => {
const session = await stripe.checkout.sessions.create({
  line_items: [
    {
      // Provide the exact Price ID (for example, pr_1234) of the product you want to sell
      price: '{price_1NPSQzLOzeaAZPUpKuWqEfFf}',
      quantity: 1,
    },
    {
      price: '{price_1NTqf0LOzeaAZPUp6UJIr4nB}',
      quantity: 1,
    },
    {
      price: '{price_1NTqgBLOzeaAZPUpc6euz95b}',
      quantity: 1,
    },
  ],
  mode: 'payment',
  success_url: "https://sunshine-wine.netlify.app/order/success?session_id={CHECKOUT_SESSION_ID}",
  cancel_url: `${"https://sunshine-wine.netlify.app/"}?canceled=true`,
});

res.redirect(303, session.url);

});

app.listen(4242, () => console.log('Running on port 4242'));

app.js

// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/apikeys
const stripe = require('stripe')('');

app.get('/order/success', async (req, res) => {
  const session = await stripe.checkout.sessions.retrieve(req.query.session_id);
  const customer = await stripe.customers.retrieve(session.customer);

  res.send(`<html><body><h1>Thanks for your order, ${customer.name}!</h1></body></html>`);
});

app.listen(4242, () => console.log(`Listening on port ${4242}!`));


module.exports = app;

客户端App.js

<section>
  <div className="product">
    <img
      src="https://i.imgur.com/EHyR2nP.png"
      alt="The cover of Stubborn Attachments"
    />
    <div className="description">
      <h3>Stubborn Attachments</h3>
      <h5>$20.00</h5>
    </div>
  </div>
  <form action="/create-checkout-session" method="POST">
    <button type="submit">
      Checkout
    </button>
  </form>
</section>

截图说明

  • 页面无法访问提示(Die Webseite ist nicht erreichbar)
  • Wine列表页面(WineListPage)
  • Checkout页面(CheckoutPage)
  • POST请求错误提示(POST-Request Error Message)

提前感谢各位的帮助!
此致,
Lukas


内容的提问来源于stack exchange,提问作者LeFreakALeak93

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 05:37:09