调至内容部分
创建账户
或
登录
Stripe 文档徽标
/
询问人工智能
创建账户
登录
开始
付款
Revenue
平台和交易市场
资金管理
开发人员工具
概览
关于 Stripe 支付
升级您的集成
支付分析
线上付款
概览查找您的用例Managed Payments
使用 Payment Link
构建结账页面
构建高级集成
构建应用内集成
支付方式
添加支付方式
管理支付方式
用 Link 更快结账
支付接口
Payment Links
结账
Web Elements
    概览
    Payment Element
    Express Checkout Element
    Address Element
    货币选择器组件
    Link Authentication Element
    Payment Method Messaging Element
应用内 Element
支付场景
自定义支付流程
灵活收单
编排
线下支付
Terminal
其他 Stripe 产品
Financial Connections
加密货币
Climate
首页付款Web Elements

Address Element

Use the Address Element to collect complete billing and shipping addresses.

复制页面

The Address Element is an embeddable UI component for accepting complete addresses. Use it to collect shipping addresses, or when you need a complete billing address, such as for tax purposes.

主题
尺寸
客户所在地
OptionDescription
ThemeUse the dropdown to choose a theme or customize the theme with the Elements Appearance API.
Desktop and mobile sizeUse the dropdown to set the max pixel width of the parent element that the Address Element is mounted to. You can set it to 750px (Desktop) or 320px (Mobile).
Customer locationUse the dropdown to choose a location for accepting complete addresses. Changing the location localizes the UI language and displays locally relevant payment methods.
Phone numberEnable this option to allow phone number collection when the address form is expanded or using a contact.
AutocompleteEnable this option to decrease checkout time, reduce validation errors, and increase checkout conversion with built-in address autocomplete. Stripe supports 236 regional address formats, including right-to-left address formats.
ContactsEnable this option to add a new address or change an existing address or phone number.

Start with examples

To see the Address Element in action, start with one of these examples:

Collect customer addresses

Code and instructions for saving an address using the Address Element.

Clone a sample app on GitHub
HTML · React

Create an Address Element

When you create an Address Element, specify whether to use it in shipping or billing mode.

In shipping mode, the element does two things:

  • Collect a shipping address.
  • Offer the customer the option to use it as a billing address too.
index.js
查看完整示例
const stripe = Stripe(
'pk_test_TYooMQauvdEDq54NiTphI7jx'
); const appearance = { /* appearance */ }; const options = { mode: 'shipping' }; const elements = stripe.elements({
clientSecret
, appearance }); const addressElement = elements.create('address', options); addressElement.mount('#address-element');

Use Address Element with other elements

You can collect both shipping and billing addresses by using multiple Address Elements, one of each mode, on your page.

If you need to collect both shipping and billing addresses and only want to use one Address Element, use the Address Element in Shipping mode and use the Payment Element to collect only the necessary billing address details.

When you use the Address Element with other elements, you can expect some automatic behavior when confirming the PaymentIntent or SetupIntent. The Address Element validates completeness upon confirming the PaymentIntent or SetupIntent and then displays errors for each field if there are any validation errors.

Use an address

The Address Element automatically works with the Payment or Express Checkout Element. When a customer provides an address and a payment method, Stripe combines them into a single PaymentIntent with the address in the correct field.

Automatic behavior

The element’s default behavior depends on its mode.

In shipping mode, the address is stored in these fields:

  • It appears in the shipping field.
  • If the customer indicates it is also the billing address, it also appears in the billing_details field.

To enable combining information, create all elements from the same Elements object, as in this example:

index.js
查看完整示例
const stripe = Stripe(
'pk_test_TYooMQauvdEDq54NiTphI7jx'
); const appearance = { /* appearance */ }; const options = { mode: 'shipping' }; const paymentElementOptions = { layout: 'accordion'}; const elements = stripe.elements({
clientSecret
}); const addressElement = elements.create('address', options); const paymentElement = elements.create('payment', paymentElementOptions); addressElement.mount('#address-element'); paymentElement.mount('#payment-element');

Custom behavior

Normally, the Address Element’s default behavior is enough. But in a complex payment flow, you might need to write custom responses to the customer’s input. For information, see Listen for address input.

Autocomplete

If your customer selects a supported country for their address, then they see the autocomplete options. The Address Element can autocomplete addresses for the following countries:

俄罗斯
加拿大
南非
印度
土耳其
巴西
德国
意大利
挪威
新加坡
新西兰
日本
比利时
法国
波兰
澳大利亚
爱尔兰
瑞典
瑞士
美国
英国
荷兰
菲律宾
西班牙
马来西亚
墨西哥

If you use the Address Element and the Payment Element together, Stripe enables autocomplete with no configuration required. This is done using a Stripe-provided Google Maps API key.

注意

By using autocomplete, you agree to comply with the Google Maps Platform Acceptable Use Policy. If you violate this policy, we might disable autocomplete, or take any other action as necessary.

If you use the Address Element alone, you must use your own Google Maps API Places Library key, which is managed separately from your Stripe account. Pass the key in the autocomplete.apiKey option.

Autofill with Link

Link saves and autofills payment and shipping information for the options you’ve enabled. For example, if the Link customer has a saved phone number, Stripe autofills the phone number only if phone number collection is enabled. When a returning Link customer authenticates, Stripe autofills their shipping information in the Address element.

Create a payment form using multiple Elements

Create a payment form using multiple Elements

To enable autofill, create all elements from the same Elements object, as in this example:

index.js
查看完整示例
const stripe = Stripe(
'pk_test_TYooMQauvdEDq54NiTphI7jx'
); const appearance = { /* appearance */ }; const options = { mode: 'shipping' }; const paymentElementOptions = { layout: 'accordion'}; const elements = stripe.elements({
clientSecret
}); const linkAuthElement = elements.create('linkAuthentication'); const addressElement = elements.create('address', options); const paymentElement = elements.create('payment', paymentElementOptions); linkAuthElement.mount('#link-auth-element'); addressElement.mount('#address-element'); paymentElement.mount('#payment-element');

Appearance

You can use the Appearance API to control the style of all elements. Choose a theme or update specific details.

Examples of light and dark modes for the address element.

For instance, choose the “flat” theme and override the primary text color.

index.js
查看完整示例
const stripe = Stripe(
'pk_test_TYooMQauvdEDq54NiTphI7jx'
); const appearance = { theme: 'flat', variables: { colorPrimaryText: '#262626' } };

See the Appearance API documentation for a full list of themes and variables.

此页面的内容有帮助吗?
是否
需要帮助?联系支持。
加入我们的早期使用计划。
查看我们的更改日志。
有问题?联系销售。
LLM? Read llms.txt.
Powered by Markdoc