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

如何在Node.js的Stripe Checkout Session中添加Google Pay与Apple Pay

为Stripe Checkout Session添加Google Pay和Apple Pay支付方式

要在你的Node.js后端代码中添加Google Pay和Apple Pay作为支付方式,只需修改payment_method_types数组,并可选择性配置支付方式的额外选项,以下是修改后的完整代码:

app.post('/create-checkout-session', async (req, res) => {
  const session = await stripe.checkout.sessions.create({
    // 添加Google Pay和Apple Pay到支付方式列表
    payment_method_types: ['card', 'google_pay', 'apple_pay'],
    // 可选:配置支付方式的显示和验证规则
    payment_method_options: {
      google_pay: {
        gateway: 'stripe',
        currency: 'usd',
        country: 'US'
      },
      apple_pay: {
        country: 'US'
      }
    },
    line_items: [
      {
        price_data: {
          currency: 'usd',
          product_data: {
            name: 'My Product'
          },
          unit_amount: req.body.amount
        },
        quantity: 1
      }
    ],
    mode: 'payment',
    success_url: 'http://localhost:4200/success',
    cancel_url: 'http://localhost:4200/cancel'
  });

  res.json({ id: session.id });
});

关键说明

  • 支付方式列表:把google_pay和apple_pay加入payment_method_types,Stripe会根据用户的设备和地区自动显示可用的支付方式
  • 支付方式配置:payment_method_options里的配置可以指定支付方式的地区、货币等规则,确保支付流程符合当地要求
  • 启用权限:需先在Stripe控制台的「支付方式」设置中开启Google Pay和Apple Pay
  • HTTPS要求:这两种支付方式仅在HTTPS环境下生效,本地开发可使用ngrok生成HTTPS代理地址进行测试
  • 地区与货币:确认所选货币(如示例中的usd)和地区(如US)支持对应支付方式

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 19:22:37