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

Stripe是否存在与confirmCardPayment等价的服务器端函数?

Stripe服务器端等价于confirmCardPayment的实现方法

Stripe提供了与前端confirmCardPayment功能完全等价的服务器端API,核心是通过Payment Intents API的paymentIntents.confirm()方法实现支付确认逻辑。

基本服务器端实现代码

对应你提供的前端代码,服务器端的Node.js实现如下:

const stripe = require('stripe')('你的Stripe Secret Key');

// data为Payment Intent的ID
const confirmPayment = await stripe.paymentIntents.confirm(
  data,
  {
    payment_method: paymentMethodReq.paymentMethod.id
  }
);

关键说明

  • 服务器端调用必须使用Stripe Secret Key(而非前端用的Publishable Key),确保密钥安全。
  • 如果需要将创建Payment Intent和确认操作合并执行,可在创建时设置confirm: true:
const paymentIntent = await stripe.paymentIntents.create({
  amount: 1000, // 金额单位为最小货币单位(如美元分)
  currency: 'usd',
  payment_method: paymentMethodReq.paymentMethod.id,
  confirm: true,
  // 若需处理3DS等验证流程,需指定return_url
  return_url: 'https://你的域名.com/payment-complete'
});
  • 服务器端处理时需注意捕获requires_action状态,这类情况需要前端引导用户完成额外验证步骤(如3DS认证)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 12:37:00