住所と電話番号を収集
モバイルアプリで住所と電話番号を収集する方法をご紹介します。
請求先や配送先の詳細な住所を収集するには、Address Element を使用します。
Address Element は次の目的でも使用できます。
- 顧客の電話番号を収集する
- オートコンプリートを利用する (iOS ではデフォルトで有効になっています)
- 配送先住所を渡して Payment Element に請求先情報を事前入力する
Stripe は、収集した住所情報と決済手段を組み合わせて、PaymentIntent を作成します。

Stripe をセットアップするサーバー側クライアント側
まず、Stripe アカウントが必要です。今すぐ登録してください。
Stripe iOS SDK はオープンソースです。詳細なドキュメントが提供されており、iOS 13 以降をサポートするアプリと互換性があります。
注
For details on the latest SDK release and past versions, see the Releases page on GitHub. To receive notifications when a new release is published, watch releases for the repository.
アプリの起動時に Stripe 公開可能キーを使用して SDK を設定します。これにより、アプリが Stripe API にリクエストを送信できるようになります。
住所のオートコンプリートの入力候補を設定する
iOS ではオートコンプリートがデフォルトで有効になっています。
Address Element を設定する
You can configure the Address Element with details such as displaying default values, setting allowed countries, customizing the appearance, and so on. Refer to AddressViewController.Configuration for the complete list of configuration options.
let addressConfiguration = AddressViewController.Configuration( additionalFields: .init(phone: .required), allowedCountries: ["US", "CA", "GB"], title: "Shipping Address" )
住所の詳細を取得する
Retrieve the address details by conforming to AddressViewControllerDelegate
and then using addressViewControllerDidFinish to dismiss the view controller. The address value is either a valid address or nil.
extension MyViewController: AddressViewControllerDelegate { func addressViewControllerDidFinish(_ addressViewController: AddressViewController, with address: AddressViewController.AddressDetails?) { addressViewController.dismiss(animated: true) self.addressDetails = address } }
Address Element を表示する
Create an AddressViewController using the address configuration and delegate from the previous steps. You can either present it in a navigation controller or push it onto a navigation controller.
self.addressViewController = AddressViewController(configuration: addressConfiguration, delegate: self) let navigationController = UINavigationController(rootViewController: addressViewController) present(navigationController, animated: true)