调至内容部分
创建账户或登录
Stripe 文档徽标
/
询问人工智能
创建账户登录
开始
付款
销售收入
平台和交易市场
资金管理
开发人员资源
API 和 SDK帮助
概览
关于 Stripe 支付
升级您的集成
支付分析
线上付款
概览查找您的用例Use Managed Payments
使用 Payment Link
Use a prebuilt checkout page
Build a custom integration with Elements
构建应用内集成
    概览
    支付表单
    Payment Element
    Address Element
      收集地址
    应用内购买外部链接
    在设置中管理支付方式
    迁移到 Confirmation Token
    美国和加拿大卡
线下支付
Terminal
支付方式
添加支付方式
管理支付方式
用 Link 更快结账
支付场景
处理多种货币
自定义支付流程
灵活收单
编排
超越支付功能
成立公司
加密货币
智能体商务 (Agentic Commerce)
Financial Connections
Climate
了解欺诈
Radar 欺诈保护
管理争议
验证身份
美国
简体中文
首页付款Build an in-app integrationAddress Element

收集物理地址和电话号码

了解如何使用 Address Element 在移动端应用中收集客户地址和电话号码。

要收集完整的地址以进行计费或送货,请使用 Address Element。

还可以使用 Address Element 执行以下作:

  • 收集客户电话号码
  • 启用自动完成功能
  • 通过传入收货地址在 Payment Element 中预填充账单信息

Stripe 将收集的地址信息和支付方式合在一起来创建 PaymentIntent。

用户选择“添加收货地址”选项的结账流程示例。然后,他们被带到一个新的界面,将他们的收货地址添加到一个表单中(他们会在键入地址时看到自动完成建议)。

设置 Stripe
服务器端
客户端

首先,您需要有 Stripe 账户。立即注册。

Stripe Android SDK 是开源的,且有完整的文档。

安装 SDK 时,将 stripe-android 添加到您的 app/build.gradle 文件的 dependencies 块中:

build.gradle.kts
Kotlin
Groovy
No results
plugins { id("com.android.application") } android { ... } dependencies { // ... // Stripe Android SDK implementation("com.stripe:stripe-android:22.0.0") // Include the financial connections SDK to support US bank account as a payment method implementation("com.stripe:financial-connections:22.0.0") }

注意

有关最新 SDK 发布及过往版本的详细信息,请查看 GitHub 上的发布页面。要想在新版本发布时接收通知,请查看仓库的发布情况。

用您的 Stripe 公钥配置 SDK,以便它可以向 Stripe API 发送请求,例如在您的 Application 子类中:

Kotlin
Java
No results
import com.stripe.android.PaymentConfiguration class MyApp : Application() { override fun onCreate() { super.onCreate() PaymentConfiguration.init( applicationContext,
"pk_test_TYooMQauvdEDq54NiTphI7jx"
) } }

注意

测试时使用您的测试密钥,发布应用时使用真实模式密钥。

设置地址自动完成建议

Address Element 使用 Google Places SDK 来获取地址自动完成建议。要启用自动完成建议,您需要在应用的 build.gradle 中包含 Google Places SDK 依赖项。

build.gradle
Groovy
Kotlin
No results
dependencies { implementation 'com.google.android.libraries.places:places:2.6.0' }

地址自动完成建议需要 Google Places API 密钥。请按照 Google Places SDK 设置指南生成您的 API 密钥。

配置 Address Element

可以使用显示默认值、设置允许的国家/地区、自定义外观等详细信息来配置 Address Element。有关配置选项的完整列表,请参阅 AddressLauncher.Configuration。

val addressConfiguration = AddressLauncher.Configuration( additionalFields: AddressLauncher.AdditionalFieldsConfiguration( phone: AdditionalFieldsConfiguration.FieldConfiguration.Required ), allowedCountries: setOf("US", "CA", "GB"), title: "Shipping Address", googlePlacesApiKey = "(optional) YOUR KEY HERE" )

检索地址详情

通过在 Activity 或 Fragment 的 onCreate 生命周期方法中创建 AddressLauncher 实例,并创建实现 AddressLauncherResultCallback 接口的回调方法来检索地址详细信息。

private lateinit var addressLauncher: AddressLauncher private var shippingDetails: AddressDetails? = null override fun onCreate(savedInstanceState: Bundle?) { addressLauncher = AddressLauncher(this, ::onAddressLauncherResult) } private fun onAddressLauncherResult(result: AddressLauncherResult) { // TODO: Handle result and update your UI when (result) { is AddressLauncherResult.Succeeded -> { shippingDetails = result.address } is AddressLauncherResult.Canceled -> { // TODO: Handle cancel } } }

AddressLauncherResult 可以是 Succeeded 或 Canceled。请参阅更多实现细节。

注意

Stripe 要求您在 onCreate 生命周期事件期间(而不是之后)实例化 AddressLauncher。否则,回调无法正确注册,您的应用将崩溃。

显示 Address Element

使用地址启动器和先前步骤中的配置来展示 Address Element。

addressLauncher.present( publishableKey = publishableKey, configuration = addressConfiguration )

可选在 Payment Element 中预填充收货地址

如果使用移动端 Payment Element,请将PaymentSheet.Configuration.shippingDetails 设置为地址元素收集的地址。当 shippingDetails 被填入时,用户的账单地址会被预填,他们会看到一个账单地址与收货地址相同的复选框。当确认 PaymentIntent 时,已填充 shippingDetails 的已确认 PaymentIntents 也会填充 shipping intent 属性

val configuration = PaymentSheet.Configuration.Builder("Example, Inc.") // ... .shippingDetails(shippingDetails) .build()

可选自定义外观

您已向您的应用程序中添加了 Address Element,现在可以自定义它的外观,使其适合您的应用程序其他部分的设计了。您可以使用 AddressLauncher.Configuration.appearance 通过Appearance API 配置外观。

可选设置默认账单详情

要为支付表单中收集的账单详情设置默认值,请配置 defaultBillingDetails 属性。paymentSheet 会用您提供的值预先填充其字段。

Kotlin
Java
No results
val address = PaymentSheet.Address(country = "US") val billingDetails = PaymentSheet.BillingDetails( address = address, email = "foo@bar.com" ) val configuration = PaymentSheet.Configuration.Builder(merchantDisplayName = "Merchant, Inc.") .defaultBillingDetails(billingDetails) .build()

可选自定义账单地址信息的收集

配置账单详情的收集

使用 BillingDetailsCollectionConfiguration 指定您希望如何在 PaymentSheet 中收集账单详情。

可以收集客户的姓名、邮件地址、电话号码和地址。

如果希望将默认账单详情关联到 PaymentMethod 对象(即使 UI 中未收集这些字段),请将 billingDetailsCollectionConfiguration.attachDefaultsToPaymentMethod 设置为 true。

Kotlin
Java
No results
val billingDetails = PaymentSheet.BillingDetails( email = "foo@bar.com" ) val billingDetailsCollectionConfiguration = BillingDetailsCollectionConfiguration( attachDefaultsToPaymentMethod = true, name = BillingDetailsCollectionConfiguration.CollectionMode.Always, email = BillingDetailsCollectionConfiguration.CollectionMode.Never, address = BillingDetailsCollectionConfiguration.AddressCollectionMode.Full, ) val configuration = PaymentSheet.Configuration.Builder(merchantDisplayName = "Merchant, Inc.") .defaultBillingDetails(billingDetails) .billingDetailsCollectionConfiguration(billingDetailsCollectionConfiguration) .build()

注意

请咨询律师,了解与收集信息有关的法律。仅在需要收集号码来完成交易时,才收集手机号码。

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