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

收集物理地址和电话号码

了解如何在移动应用中收集地址和电话号码。

To collect complete addresses for billing or shipping, use the Address Element.

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

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

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

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

设置 Stripe
服务器端
客户端

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

Stripe iOS SDK 是开源的,有完整的文档,并且与支持 iOS 13 或更高版本操作系统的应用程序兼容。

要安装 SDK,按这些步骤进行:

  1. 在 Xcode 中,选择文件 > **添加工具包依赖…**并输入 https://github.com/stripe/stripe-ios-spm 作为仓库 URL。
  2. 从我们的发布页面选择最新的版本号。
  3. 将 StripePaymentSheet 产品添加到您的目标应用程序。

注意

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

在应用程序启动时使用您的 Stripe 公钥 配置 SDK。这样可使您的应用程序向 Stripe API 发出请求。

AppDelegate.swift
Swift
No results
import UIKit import StripePaymentSheet @main class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { StripeAPI.defaultPublishableKey =
"pk_test_TYooMQauvdEDq54NiTphI7jx"
// do any other necessary launch configuration return true } }

注意

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

设置地址自动完成建议

iOS 系统会默认启用自动完成功能。

配置 Address Element

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

let addressConfiguration = AddressViewController.Configuration( additionalFields: .init(phone: .required), allowedCountries: ["US", "CA", "GB"], title: "Shipping Address" )

检索地址详情

通过满足 AddressViewControllerDelegate 并使用 addressViewControllerDidFinish 关闭视图控制器来检索地址详细信息。地址的值是有效的地址或空。

extension MyViewController: AddressViewControllerDelegate { func addressViewControllerDidFinish(_ addressViewController: AddressViewController, with address: AddressViewController.AddressDetails?) { addressViewController.dismiss(animated: true) self.addressDetails = address } }

显示 Address Element

使用以上步骤中的地址配置和委托创建 AddressViewController。您可以将其显示在导航控制器中,也可以将其推送到导航控制器上。

self.addressViewController = AddressViewController(configuration: addressConfiguration, delegate: self) let navigationController = UINavigationController(rootViewController: addressViewController) present(navigationController, animated: true)

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

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

var configuration = PaymentSheet.Configuration() // ... configuration.shippingDetails = { [weak self] in return self?.addressDetails }

可选自定义外观

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

可选设置默认账单详情

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

var configuration = PaymentSheet.Configuration() configuration.defaultBillingDetails.address.country = "US" configuration.defaultBillingDetails.email = "foo@bar.com"

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

用 billingDetailsCollectionConfiguration 来指定您希望如何在支付表单中收集账单详情。

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

如果您只想通过支付方式获得所需的账单详情,请将 billingDetailsCollectionConfiguration.attachDefaultsToPaymentMethod 设置为 true。在这种情况下,PaymentSheet.Configuration.defaultBillingDetails 被设置为支付方式的 billing details。

如果您希望收集支付方式非必需的额外账单详情,请将 billingDetailsCollectionConfiguration.attachDefaultsToPaymentMethod 设置为 false。在这种情况下,通过 PaymentSheet 收集的账单详情被设置为支付方式的账单详情。

var configuration = PaymentSheet.Configuration() configuration.defaultBillingDetails.email = "foo@bar.com" configuration.billingDetailsCollectionConfiguration.name = .always configuration.billingDetailsCollectionConfiguration.email = .never configuration.billingDetailsCollectionConfiguration.address = .full configuration.billingDetailsCollectionConfiguration.attachDefaultsToPaymentMethod = true

注意

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

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