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

如何在NodeJS中通过Stripe Checkout Session添加UPI、Google Pay等非卡支付方式

在Node.js中为Stripe集成UPI、Google Pay及其他非银行卡支付方式

前置要求

  • 安装Stripe Node.js SDK:npm install stripe
  • 拥有Stripe API密钥(从Stripe后台获取,测试环境用测试密钥,生产用live密钥)
  • 在Stripe Dashboard的「支付方式」设置中,启用UPI、Google Pay等你需要的支付方式

一、直接通过Payment Intent集成UPI/Google Pay

如果不需要预构建的Checkout页面,可以直接创建Payment Intent并指定支付方式类型:

1. 集成Google Pay

创建Payment Intent时,将payment_method_types数组包含google_pay,注意货币支持(Google Pay兼容多数主流货币,如USD、INR等):

const stripe = require('stripe')('sk_test_你的测试密钥');

async function createGooglePayPaymentIntent() {
  const paymentIntent = await stripe.paymentIntents.create({
    amount: 5000, // 金额以最小单位计算,如5000 = 50.00 INR/USD
    currency: 'inr',
    payment_method_types: ['google_pay'],
    description: '测试Google Pay支付',
  });

  // 返回客户端密钥给前端,用于完成支付流程
  return { clientSecret: paymentIntent.client_secret };
}

2. 集成UPI

UPI仅支持印度卢比(INR),创建Payment Intent时指定payment_method_types: ['upi'],还可可选预先填入用户的VPA(虚拟支付地址):

async function createUpiPaymentIntent() {
  const paymentIntent = await stripe.paymentIntents.create({
    amount: 3000, // 30.00 INR
    currency: 'inr',
    payment_method_types: ['upi'],
    payment_method_options: {
      upi: {
        vpa: 'user@exampleupi', // 可选:预先填入用户的VPA
      },
    },
    description: '测试UPI支付',
  });

  return { clientSecret: paymentIntent.client_secret };
}

二、通过Stripe Checkout Session添加非银行卡支付方式

Stripe Checkout是预构建的支付页面,集成更快捷,只需在创建Session时指定支持的支付方式:

创建包含多支付方式的Checkout Session

async function createCheckoutSession() {
  const session = await stripe.checkout.sessions.create({
    payment_method_types: ['card', 'google_pay', 'upi'], // 同时支持银行卡、Google Pay、UPI
    mode: 'payment',
    line_items: [
      {
        price_data: {
          currency: 'inr',
          product_data: {
            name: '测试商品',
          },
          unit_amount: 2000, // 20.00 INR
        },
        quantity: 1,
      },
    ],
    success_url: 'https://your-domain.com/success', // 支付成功跳转地址
    cancel_url: 'https://your-domain.com/cancel', // 取消支付跳转地址
  });

  // 返回Session URL给前端,引导用户跳转至Checkout页面
  return { url: session.url };
}

关键注意事项

  • 支付方式可用性:UPI仅支持INR且仅限印度地区用户;Google Pay的支持地区和货币需根据Stripe账号所在区域确认,可在后台查看可用选项
  • 测试环境:测试UPI可使用Stripe提供的测试VPA(如success@upi模拟支付成功,failure@upi模拟失败);测试Google Pay遵循Stripe测试卡片规则即可
  • Webhook配置:无论用Payment Intent还是Checkout Session,都需要配置Webhook监听payment_intent.succeeded、checkout.session.completed等事件,用于处理支付完成后的业务逻辑(如更新订单状态、触发发货流程)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 03:47:47