Connect の埋め込みコンポーネントの使用を開始する
ダッシュボードの機能をウェブサイトに埋め込む方法をご紹介します。
Connect の埋め込みコンポーネントを使用して、連結アカウントのダッシュボード機能をウェブサイトに追加します。これらのライブラリとサポートする API を使用することで、ダッシュボードから Stripe 製品に直接アクセスできる許可をユーザーに付与できます。
プライベートプレビュー
The iOS SDK is currently available with invite only and has the following limitations:
- Only accounts where
controller.
isrequirement_ collection application
, such as Custom connected accounts, are supported. - ユーザー認証はサポートされていないため、アカウントセッションの作成時にすべてのコンポーネントのサーバーエンドポイントで features.disable_stripe_user_authentication を
true
に設定する必要があります。
招待をご希望の場合は、以下のフォームにメールアドレスを入力してください。
StripeConnect を設定するクライアント側サーバー側
Stripe は AccountSession を使用して、API アクセスを連結アカウントに委任する意図を表します。
AccountSessions API は Client Secret を返し、ウェブクライアントの埋め込みコンポーネントが、まるでユーザーが API コールを行っているかのように連結アカウントのリソースにアクセスできるようにします。
AccountSession を作成する サーバー
アプリは、アカウントセッションを取得するリクエストをサーバーに対して開始する必要があります。Client Secret をアプリに返す新しいエンドポイントをサーバー上に作成できます。
注意
ユーザー認証はサポートされていないため、アカウントセッションの作成時にすべてのコンポーネントのサーバーエンドポイントで features.disable_stripe_user_authentication を true
に設定する必要があります。
Create Account Session API
The Create Account Session API determines component and feature access for Connect embedded components. Stripe enforces these parameters for any components that correspond to the account session. If your app supports multiple user roles, make sure components and features that are enabled for that account session correspond to the current user’s role. For example, you can enable refund management only for administrators of your site, but not for other users. To make sure user role access are enforced, you must map your site’s user role to account session components.
StripeConnect SDK をインストールする クライアント
Stripe iOS SDK はオープンソースです。詳細なドキュメントが提供されており、iOS 15 以降をサポートするアプリと互換性があります。
注
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 Connect iOS SDK では、本人確認書類をキャプチャーするためにデバイスのカメラにアクセスする必要があります。アプリからカメラへのアクセスの許可をリクエストできるようにするには、次の操作を行います。
- Xcode で、プロジェクトの Info.plist を開きます。
NSCameraUsageDescription
キーを追加します。- アプリにカメラへのアクセスの許可が必要な理由をユーザーに説明する文字列値を追加します。
このアプリは、カメラを使用して本人確認書類の写真を撮影します。
カメラ認証のリクエストについて、詳細は Apple のドキュメントを参照してください。
Initialize EmbeddedComponentManager クライアント
Set your publishable key using StripeAPI.
and instantiate an EmbeddedComponentManager with a closure that retrieves a client secret by calling the new endpoint you created on your server. To create a component, call the appropriate create method on the EmbeddedComponentManager
that you instantiated above. This returns a controller that you can use to present it in the app.
@_spi(PrivateBetaConnect) import StripeConnect import UIKit class MyViewController: UIViewController { let errorView: UIView func fetchClientSecret() async -> String? { let url = URL(string: "https://{{YOUR_SERVER}}/account_session")! var request = URLRequest(url: url) request.httpMethod = "POST" do { // Fetch the AccountSession client secret let (data, _) = try await URLSession.shared.data(for: request) let json = try JSONSerialization.jsonObject(with: data) as? [String : Any] errorView.isHidden = true return json?["client_secret"] as? String } catch let error { // Handle errors on the client side here print("An error occurred: \(error)") errorView.isHidden = false return nil } } override func viewDidLoad() { super.viewDidLoad() // This is your test publishable API key. STPAPIClient.shared.publishableKey = "{{PUBLISHABLE_KEY}}", let embeddedComponentManager = EmbeddedComponentManager( fetchClientSecret: fetchClientSecret ) let controller = embeddedComponentManager.createAccountOnboardingController() controller.present(from: self) } }
Configure the Embedded Component Managerクライアント側
Connect 埋め込みコンポーネントのデザインをカスタマイズする
埋め込みコンポーネント Figma UI ツールキットには、すべてのコンポーネント、一般的なパターン、サンプルアプリケーションが含まれています。これを使用して、ウェブサイトに埋め込まれた UI を可視化してデザインできます。
Stripe は、Connect 埋め込みコンポーネントのデザインをカスタマイズするための一連のオプションを提供しています。これらをカスタマイズすると、デザインシステムのボタン、アイコン、その他のアクセントに影響します。
Necessary popups
Some behavior in embedded components, such as user authentication, must be presented in a popup. You can’t customize the embedded component to eliminate such popups.
これらのオプションは、EmbeddedComponentManager
の初期化時に EmbeddedComponentManager.Appearance を使用して設定できます。
func fetchClientSecret() async -> String? { let url = URL(string: "https://{{YOUR_SERVER}}/account_session")! var request = URLRequest(url: url) request.httpMethod = "POST" do { let (data, _) = try await URLSession.shared.data(for: request) let json = try JSONSerialization.jsonObject(with: data) as? [String : Any] return json?["client_secret"] as? String } catch { return nil } } // Specify custom fonts var customFonts: [CustomFontSource] = [] let myFont = UIFont(name: "My Font", size: 16)! let fontUrl = Bundle.main.url(forResource: "my-font-2", withExtension: "woff")! do { let customFontSource = try CustomFontSource(font: myFont, fileUrl: fontUrl) customFonts.append(customFontSource) } catch { print("Error loading custom font: \(error)") } // Customize appearance var appearance = EmbeddedComponentManager.Appearance() appearance.typography.fontfont.base = myFont appearance.typography.fontSizeBase = 16 // Unscaled font size appearance.colors.primary = UIColor { traitCollection in if traitCollection.userInterfaceStyle == .dark { UIColor(red: 0.455, green: 0.424, blue: 1.000, alpha: 1.0) } else { UIColor(red: 0.404, green: 0.365, blue: 1.000, alpha: 1.0) } } STPAPIClient.shared.publishableKey = "{{PUBLISHABLE_KEY}}", let embeddedComponentManager = EmbeddedComponentManager( appearance: appearance, fonts: customFonts, fetchClientSecret: fetchClientSecret )
Use custom fonts 
アプリでカスタムフォントを使用する場合 (たとえば、アプリのバイナリに埋め込まれた .
ファイルや .
ファイルなど)、EmbeddedComponentManager
の初期化時に fonts
引数に渡される CustomFontSource でフォントファイルを指定する必要があります。そうすることで、Connect 埋め込みコンポーネントがフォントファイルにアクセスできるようになり、フォントを適切にレンダリングできます。
appearance
で指定されたフォントは、正しくレンダリングされるように、サポートされているシステムフォントか、初期化時に EmbeddedComponentManager
に渡される CustomFontSource のいずれかを使用する必要があります。
Configure appearance 
ダークモードやアクセシビリティコントラストなど、ダイナミックプロバイダーを使用したデザインの色は、UITraitCollection が更新されたときに Connect 埋め込みコンポーネントに自動的に適用されます。デフォルトのデザインにはダークモードの色は含まれていないため、アプリでダークモードを対応するには、EmbeddedComponentManager
にダイナミックカラーを使用したデザインを指定する必要があります。
When specifying font sizes, use the unscaled font size that displays for the device’s default size class. The embedded component automatically scales the font size based on its UITraitCollection.
See the full list of appearance options on iOS.
Update Connect embedded components after initialization
Call the update
method to change the appearance of the embedded components after initialization:
var appearance = EmbeddedComponentManager.Appearance() appearance.colors.primary = UIColor.red manager.update(appearance: appearance)
認証
Stripe は、Connect 埋め込みコンポーネントでアカウントセッションとユーザー認証情報を管理するための一連の API を提供しています。
Client Secret を更新する
長時間実行されるセッションでは、最初に提供された Client Secret によるセッションが期限切れになることがあります。有効期限が切れると、Stripe は自動的に fetchClientSecret
を使用して新しい Client Secret を取得し、セッションを更新します。貴社が追加のパラメーターを渡す必要はありません。
func fetchClientSecret() async -> String? { var request = URLRequest(url: URL(string: "https://{{YOUR_SERVER}}/account_session")!) request.httpMethod = "POST" do { let (data, _) = try await URLSession.shared.data(for: request) let json = try JSONSerialization.jsonObject(with: data) as? [String : Any] return json?["client_secret"] as? String } catch let error { return nil } } STPAPIClient.shared.publishableKey = "{{PUBLISHABLE_KEY}}", let embeddedComponentManager = EmbeddedComponentManager( fetchClientSecret: fetchClientSecret )
各地域への適応
Connect 埋め込みコンポーネントは、次のロケールに対応しています。
言語 | ロケールコード |
---|---|
ブルガリア語 (ブルガリア) | bg-BG |
中国語 (簡体字) | zh-Hans |
中国語 (繁体字 - 香港) | zh-Hant-HK |
中国語 (繁体字 - 台湾) | zh-Hant-TW |
クロアチア語 (クロアチア) | hr-HR |
チェコ語 (チェコ) | cs-CZ |
デンマーク語 (デンマーク) | da-DK |
オランダ語 (オランダ) | nl-NL |
英語 (オーストラリア) | en-AU |
英語 (インド) | en-IN |
英語 (アイルランド) | en-IE |
英語 (ニュージーランド) | en-NZ |
英語 (シンガポール) | en-SG |
英語 (イギリス) | en-GB |
英語 (アメリカ) | en-US |
エストニア語 (エストニア) | et-EE |
フィリピノ語 (フィリピン) | fil-PH |
フィンランド語 (フィンランド) | fi-FI |
フランス語 (カナダ) | fr-CA |
フランス語 (フランス) | fr-FR |
ドイツ語 (ドイツ) | de-DE |
ギリシャ語 (ギリシャ) | el-GR |
ハンガリー語 (ハンガリー) | hu-HU |
インドネシア語 (インドネシア) | id-ID |
イタリア語 (イタリア) | it-IT |
日本語 (日本) | ja-JP |
韓国語 (韓国) | ko-KR |
ラトビア語 (ラトビア) | lv-LV |
リトアニア語 (リトアニア) | lt-LT |
マレー語 (マレーシア) | ms-MY |
マルタ語 (マルタ) | mt-MT |
ノルウェーブークモール語 (ノルウェー) | nb-NO |
ポーランド語 (ポーランド) | pl-PL |
ポルトガル語 (ブラジル) | pt-BR |
ポルトガル語 (ポルトガル) | pt-PT |
ルーマニア語 (ルーマニア) | ro-RO |
スロバキア語 (スロバキア) | sk-SK |
スロベニア語 (スロベニア) | sl-SI |
スペイン語 (アルゼンチン) | es-AR |
スペイン語 (ブラジル) | es-BR |
スペイン語 (中南米) | es-419 |
スペイン語 (メキシコ) | es-MX |
スペイン語 (スペイン) | es-ES |
スウェーデン語 (スウェーデン) | sv-SE |
タイ語 (タイ) | th-TH |
トルコ語 (トルコ) | tr-TR |
ベトナム語 (ベトナム) | vi-VN |
読み込みエラーを処理する
コンポーネントが読み込まれない場合は、コンポーネントの didFailLoadWithError
デリゲートメソッドを実装することでエラーに対処できます。エラーの原因によっては、didFailLoadWithError
メソッドが複数回呼び出される場合があります。didFailLoadWithError
によってトリガーされるロジックは、べき等でなければなりません。
// All components emit load errors. This example uses AccountOnboarding. // All components support didFailLoadWithError. class MyViewController: UIViewController, AccountOnboardingControllerDelegate { func openAccountOnboarding() { let accountOnboardingController = embeddedComponentManager.createAccountOnboardingController(); accountOnboardingController.delegate = self accountOnboardingController.present(from: self) } // MARK: - AccountOnboardingControllerDelegate func accountOnboarding(_ accountOnboarding: AccountOnboardingController, didFailLoadWithError error: Error) { print("Account onboarding failed to load with error '\(error)'") } }
アクセスのリクエスト プライベートプレビュー版
サインインして、プレビュー版のこの Connect 埋め込みコンポーネントへのアクセスをリクエストします。
Stripe アカウントをお持ちでない場合は、今すぐ登録できます。