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

如何在Stripe Payment Element中显示邮政编码字段

解决Stripe Payment Element不显示邮政编码字段的问题

Stripe的Payment Element默认会根据付款方式、用户所在地区自动调整显示的字段,但你可以通过显式配置强制显示邮政编码字段。只需要在创建Payment Element时添加fields选项,指定billingDetails.postalCode为"always"即可。

修改后的代码如下:

<script src="https://js.stripe.com/v3/"></script>

<script>
const stripe = Stripe('PUBLIC_KEY');

const elements = stripe.elements({
                     clientSecret: clientSecret,
                     theme: 'stripe',
                 });

// 添加fields配置强制显示邮政编码
const element = elements.create("payment", {
  fields: {
    billingDetails: {
      postalCode: "always"
    }
  }
});

element.mount('#card-stripe');
</script>

补充说明

  • postalCode的可选值有三个:
    • "auto":默认行为,Stripe自动判断是否显示
    • "always":始终显示该字段
    • "never":强制隐藏该字段

内容的提问来源于stack exchange,提问作者Quang Hà Đặng

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 20:07:39