Stripe Setup Intent集成Google Pay时弹窗显示0美元的问题咨询
问题
我正在使用Stripe的Setup Intents,在后续确认客户信息后再进行收费,提前收集支付信息。测试Google Pay时,收费功能正常,但客户确认支付的弹窗显示0美元,存在误导性。我们已有预计收费金额,希望在此处显示该金额(或至少不显示数值)。请问这是否仅因测试环境导致?若不是,是否支持自定义?
以下是我们使用的代码(clientSecret为创建SetupIntent时返回的密钥):
const options = { clientSecret, // Fully customizable with appearance API. appearance: {}, loader: 'always' } elements = stripe.elements(options) ({ error } = await stripe.confirmSetup({ elements, confirmParams: { return_url: window.location.href + '/purchase/' + props.purchase.uuid + '/confirmation' } }))

回答
1. 0美元显示的原因
这不是测试环境导致的问题。Setup Intent的核心作用是提前收集客户支付方式,而非立即发起扣款,因此Google Pay弹窗默认会显示0美元,这是Stripe的标准行为,和环境无关。
2. 自定义优化方案
你可以通过以下方式调整弹窗显示,降低误导性:
- 补充交易描述:在后端创建Setup Intent时,添加
description参数(例如"预计后续收费$XX.XX"),Google Pay弹窗会展示该描述,明确告知用户未来的收费金额。 - 明确未来使用场景:创建Setup Intent时指定
setup_future_usage为off_session(后续自动扣款)或on_session(后续用户在场时扣款),弹窗会自动添加“用于未来付款”类的提示,帮助用户理解交易目的。 - 隐藏0金额显示:通过配置Google Pay元素的
transactionInfo,设置totalPriceStatus为NOT_CURRENTLY_KNOWN,并自定义totalPriceLabel,这样弹窗不会显示0美元,而是展示你设置的标签。示例前端代码调整如下:
const options = { clientSecret, appearance: {}, loader: 'always' } elements = stripe.elements(options) // 创建Google Pay元素时配置交易信息 const googlePayElement = elements.create('googlePay', { transactionInfo: { totalPriceStatus: 'NOT_CURRENTLY_KNOWN', totalPriceLabel: '预计后续收费', currencyCode: 'USD' // 替换为你的币种 } }) // 挂载元素到页面容器 googlePayElement.mount('#google-pay-button') // 确认Setup Intent ({ error } = await stripe.confirmSetup({ elements, confirmParams: { return_url: window.location.href + '/purchase/' + props.purchase.uuid + '/confirmation' } }))
内容的提问来源于stack exchange,提问作者puelo
相关产品推荐
相关产品推荐

