# Get started with Connect embedded components Learn how to embed dashboard functionality into your website. Use Connect embedded components to add connected account dashboard functionality to your website. These libraries and their supporting API allow you to grant your users access to Stripe products directly in your dashboard and mobile applications. - **Add integrated UI**: Use embedded components to add integrated UI to your Dashboard. See [all available components](https://docs.stripe.com/connect/supported-embedded-components.md). - **Customize appearance**: Adjust the [appearance](https://docs.stripe.com/connect/customize-connect-embedded-components.md) to match your brand. - **Stay current**: Connect embedded components stay in sync with Stripe APIs, which helps keep your integration up to date. ## Set up StripeConnect [Client-side] [Server-side] Stripe uses an [AccountSession](https://docs.stripe.com/api/account_sessions.md) to express your intent to delegate API access to your connected account. The AccountSessions API returns a *client secret* (The client secret is a unique string returned from Stripe as part of an AccountSession. This string lets the client access a specific Stripe account with Connect embedded components) that allows an embedded component to access a connected account’s resources as if you were making the API calls for them. ### Create an AccountSession (Server) Your app must initiate a request to your server to obtain the account session. You can create a new endpoint on your server that returns the client secret to the app: #### Ruby ```ruby require 'sinatra' require 'stripe' # This is a placeholder - it should be replaced with your API key. # Sign in to see your own test API key embedded in code samples. # Don't put any keys in code. We recommend using a restricted API key with access only to the account sessions resource. See https://docs.stripe.com/keys-best-practices client = Stripe::StripeClient.new('<>') post '/account_session' do content_type 'application/json' # Create an AccountSession begin account_session = client.v1.account_sessions.create({ account: {{CONNECTED_ACCOUNT_ID}}, components: { account_onboarding: { enabled: true, features: { # We recommend disabling authentication for a better user experience when possible disable_stripe_user_authentication: true, } } } }) { client_secret: account_session[:client_secret] }.to_json rescue => error puts "An error occurred when calling the Stripe API to create an account session: #{error.message}"; return [500, { error: error.message }.to_json] end end ``` ### Create Account Session API The [Create Account Session API](https://docs.stripe.com/api/account_sessions/create.md) 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](https://docs.stripe.com/api/account_sessions/create.md#create_account_session-components-payments-features-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. ### Install the StripeConnect SDK (Client) The [Stripe iOS SDK](https://github.com/stripe/stripe-ios) is open source, [fully documented](https://stripe.dev/stripe-ios/index.html), and compatible with apps supporting iOS 15 or above. #### Swift Package Manager To install the SDK, follow these steps: 1. In Xcode, select **File** > **Add Package Dependencies…** and enter `https://github.com/stripe/stripe-ios-spm` as the repository URL. 2. Select the latest version number from our [releases page](https://github.com/stripe/stripe-ios/releases). 3. Add the **StripeConnect** product to the [target of your app](https://developer.apple.com/documentation/swift_packages/adding_package_dependencies_to_your_app). #### CocoaPods 1. If you haven’t already, install the latest version of [CocoaPods](https://guides.cocoapods.org/using/getting-started.html). 2. If you don’t have an existing [Podfile](https://guides.cocoapods.org/syntax/podfile.html), run the following command to create one: ```bash pod init ``` 3. Add this line to your `Podfile`: ```podfile pod 'StripeConnect' ``` 4. Run the following command: ```bash pod install ``` 5. Don’t forget to use the `.xcworkspace` file to open your project in Xcode, instead of the `.xcodeproj` file, from here on out. 6. In the future, to update to the latest version of the SDK, run: ```bash pod update StripeConnect ``` #### Carthage 1. If you haven’t already, install the latest version of [Carthage](https://github.com/Carthage/Carthage#installing-carthage). 2. Add this line to your `Cartfile`: ```cartfile github "stripe/stripe-ios" ``` 3. Follow the [Carthage installation instructions](https://github.com/Carthage/Carthage#if-youre-building-for-ios-tvos-or-watchos). Make sure to embed all of the required frameworks listed [here](https://github.com/stripe/stripe-ios/tree/master/StripeConnect#manual-linking). 4. In the future, to update to the latest version of the SDK, run the following command: ```bash carthage update stripe-ios --platform ios ``` #### Manual Framework 1. Head to our [GitHub releases page](https://github.com/stripe/stripe-ios/releases/latest) and download and unzip **Stripe.xcframework.zip**. 2. Drag **StripeConnect.xcframework** to the **Embedded Binaries** section of the **General** settings in your Xcode project. Make sure to select **Copy items if needed**. 3. Repeat step 2 for all required frameworks listed [here](https://github.com/stripe/stripe-ios/tree/master/StripeConnect#manual-linking). 4. In the future, to update to the latest version of our SDK, repeat steps 1–3. > For details on the latest SDK release and past versions, see the [Releases](https://github.com/stripe/stripe-ios/releases) page on GitHub. To receive notifications when a new release is published, [watch releases](https://help.github.com/en/articles/watching-and-unwatching-releases-for-a-repository#watching-releases-for-a-repository) for the repository. ### Set up camera authorization (Client-side) The Stripe Connect iOS SDK requires access to the device’s camera to capture identity documents. To enable your app to request camera permissions: 1. Open your project’s **Info.plist** in Xcode. 2. Add the `NSCameraUsageDescription` key. 3. Add a string value that explains to your users why your app requires camera permissions, something such as: > This app uses the camera to take a picture of your identity documents. See [Apple’s documentation](https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/requesting_authorization_for_media_capture_on_ios) to learn more about requesting camera authorization. ### Initialize EmbeddedComponentManager (Client) Set your publishable key using `StripeAPI.shared` and instantiate an [EmbeddedComponentManager](https://stripe.dev/stripe-ios/stripeconnect/documentation/stripeconnect/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. [Account onboarding](https://docs.stripe.com/connect/supported-embedded-components/account-onboarding.md) returns a controller which manages its own presentation. Other components, such as [Payments](https://docs.stripe.com/connect/supported-embedded-components/payments.md) returns a [UIViewController](https://developer.apple.com/documentation/uikit/uiviewcontroller) that you can display in your app with more flexibility. #### UIKit ```swift 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 ) // Account onboarding presents modally and fullscreen let controller = embeddedComponentManager.createAccountOnboardingController() controller.title = "Onboard with Stripe" controller.present(from: self) // All other components can be flexibly presented let paymentsViewController = embeddedComponentManager.createPaymentsViewController() present(paymentsViewController) } } ``` ## Configure the Embedded Component Manager [Client-side] [See the reference documentation :external:](https://stripe.dev/stripe-ios/stripeconnect/documentation/stripeconnect/embeddedcomponentmanager/init\(apiClient:appearance:fonts:fetchClientSecret:\)). ### Customize the look of Connect embedded components The [embedded components Figma UI toolkit](https://www.figma.com/community/file/1438614134095442934) contains every component, common patterns, and an example application. You can use it to visualize and design embedded UIs on your website. We offer a [set of options](https://docs.stripe.com/connect/embedded-appearance-options.md) to customize the look and feel of Connect embedded components. These customizations affect buttons, icons, and other accents in our design system. > #### Necessary popups > > Some behavior in embedded components, such as [user authentication](https://docs.stripe.com/connect/get-started-connect-embedded-components.md#user-authentication-in-connect-embedded-components), must be presented in an authenticated WebView. You can’t customize the embedded component to eliminate such WebViews. You can set these options using [EmbeddedComponentManager.Appearance](https://stripe.dev/stripe-ios/stripeconnect/documentation/stripeconnect/embeddedcomponentmanager/appearance) when initializing `EmbeddedComponentManager`. ```swift 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.font.base = myFont appearance.typography.fontSizeBase = 16 // Unscaled font size appearance.colors.primary = UIColor { traitCollection in if traitCollection.userInterfaceStyle == .dark { return UIColor(red: 0.455, green: 0.424, blue: 1.000, alpha: 1.0) } else { return 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 ) ``` Appearance colors that use [dynamic providers](https://developer.apple.com/documentation/uikit/uicolor/3238041-init) are automatically applied to the Connect embedded component when its [UITraitCollection](https://developer.apple.com/documentation/uikit/uitraitcollection) is updated, including [Dark Mode](https://developer.apple.com/design/human-interface-guidelines/dark-mode) and [accessibility contrast](https://developer.apple.com/documentation/uikit/uiaccessibilitycontrast). The default appearance doesn’t include dark mode colors, so you must specify an appearance with dynamic colors to the `EmbeddedComponentManager` to support dark mode in your app. 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](https://developer.apple.com/documentation/uikit/uitraitcollection). See the [full list of appearance options](https://docs.stripe.com/connect/embedded-appearance-options.md) on iOS. ### Use custom fonts If you use custom fonts in your app (for example, from `.otf` or `.tff` files embedded in your app binary), you must specify the font files in a [CustomFontSource](https://stripe.dev/stripe-ios/stripeconnect/documentation/stripeconnect/embeddedcomponentmanager/customfontsource) passed to the `fonts` argument when initializing `EmbeddedComponentManager`. This gives Connect embedded components access to the font files to properly render the fonts. Fonts specified in `appearance` must use either a [supported system font](https://developer.apple.com/fonts/system-fonts/) or a [CustomFontSource](https://stripe.dev/stripe-ios/stripeconnect/documentation/stripeconnect/embeddedcomponentmanager/customfontsource) passed to the `EmbeddedComponentManager` on initialization to properly render. [See the reference documentation :external:](https://stripe.dev/stripe-ios/stripeconnect/documentation/stripeconnect/embeddedcomponentmanager/customfontsource). ### Update Connect embedded components after initialization Call the `update` method to change the appearance of the embedded components after initialization: ```swift var appearance = EmbeddedComponentManager.Appearance() appearance.colors.primary = UIColor.red manager.update(appearance: appearance) ``` ## Authentication We offer a set of APIs to manage account sessions and user credentials in Connect embedded components. ### Refresh the client secret On long running sessions, the session from the initially provided *client secret* (The client secret is a unique string returned from Stripe as part of an AccountSession. This string lets the client access a specific Stripe account with Connect embedded components) might expire. When it expires, we automatically use `fetchClientSecret` to retrieve a new client secret and refresh the session. You don’t need to pass in any additional parameters. ```swift 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 ) ``` ## Localization Connect embedded components support the following locales: | Language | Locale code | | --------------------------------- | ------------ | | Bulgarian (Bulgaria) | `bg-BG` | | Chinese (Simplified) | `zh-Hans` | | Chinese (Traditional - Hong Kong) | `zh-Hant-HK` | | Chinese (Traditional - Taiwan) | `zh-Hant-TW` | | Croatian (Croatia) | `hr-HR` | | Czech (Czechia) | `cs-CZ` | | Danish (Denmark) | `da-DK` | | Dutch (Netherlands) | `nl-NL` | | English (Australia) | `en-AU` | | English (India) | `en-IN` | | English (Ireland) | `en-IE` | | English (New Zealand) | `en-NZ` | | English (Singapore) | `en-SG` | | English (United Kingdom) | `en-GB` | | English (United States) | `en-US` | | Estonian (Estonia) | `et-EE` | | Filipino (Philippines) | `fil-PH` | | Finnish (Finland) | `fi-FI` | | French (Canada) | `fr-CA` | | French (France) | `fr-FR` | | German (Germany) | `de-DE` | | Greek (Greece) | `el-GR` | | Hungarian (Hungary) | `hu-HU` | | Indonesian (Indonesia) | `id-ID` | | Italian (Italy) | `it-IT` | | Japanese (Japan) | `ja-JP` | | Korean (South Korea) | `ko-KR` | | Latvian (Latvia) | `lv-LV` | | Lithuanian (Lithuania) | `lt-LT` | | Malay (Malaysia) | `ms-MY` | | Maltese (Malta) | `mt-MT` | | Norwegian Bokmål (Norway) | `nb-NO` | | Polish (Poland) | `pl-PL` | | Portuguese (Brazil) | `pt-BR` | | Portuguese (Portugal) | `pt-PT` | | Romanian (Romania) | `ro-RO` | | Slovak (Slovakia) | `sk-SK` | | Slovenian (Slovenia) | `sl-SI` | | Spanish (Argentina) | `es-AR` | | Spanish (Brazil) | `es-BR` | | Spanish (Latin America) | `es-419` | | Spanish (Mexico) | `es-MX` | | Spanish (Spain) | `es-ES` | | Swedish (Sweden) | `sv-SE` | | Thai (Thailand) | `th-TH` | | Turkish (Türkiye) | `tr-TR` | | Vietnamese (Vietnam) | `vi-VN` | ## User authentication in Connect embedded components Connect embedded components typically don’t require user authentication. In some scenarios, Connect embedded components require the connected account to sign in with their Stripe account before accessing the component to provide the necessary functionality (for example, writing information to the account legal entity in the case of the [account onboarding](https://docs.stripe.com/connect/supported-embedded-components/account-onboarding.md) component). Other components might require authentication within the component after they initially render. Authentication is required for connected accounts where Stripe is responsible for collecting updated information when requirements change. For connected accounts where you’re responsible for collecting updated information when requirements are due or change, such as Custom accounts, Stripe authentication is controlled by the [disable_stripe_user_authentication](https://docs.stripe.com/api/account_sessions/create.md#create_account_session-components-account_onboarding-features-disable_stripe_user_authentication) Account Session feature. We recommend implementing 2FA or equivalent security measures as a [best practice](https://docs.stripe.com/connect/risk-management/best-practices.md#prevent-account-take-overs). For account configurations that support this feature, like Custom, you assume liability for connected accounts if they can’t pay back [negative balances](https://docs.stripe.com/connect/risk-management/best-practices.md#decide-your-approach-to-negative-balance-liability). ### Components requiring authentication Connected accounts will be shown an authenticated [WebView](https://developer.apple.com/documentation/authenticationservices/aswebauthenticationsession) within your application. The connected account must authenticate before they can continue their workflow within the WebView. The Stripe-hosted authentication flow shows your brand’s name, color, and icon as set in your [Connect settings](https://dashboard.stripe.com/account/applications/settings) and doesn’t use your custom appearance and fonts from the [Embedded Component Manager](https://docs.stripe.com/connect/get-started-connect-embedded-components.md#configuring-connect) until authentication completes. The following component requires connected accounts to authenticate in certain scenarios: - [Account Onboarding](https://docs.stripe.com/connect/supported-embedded-components/account-onboarding.md) - [Payouts](https://docs.stripe.com/connect/supported-embedded-components/payouts.md) ## Handle load errors [Client-side] Respond to component load failures by implementing the component’s `onLoadError` listener method. Different failure causes might call the `onLoadError` method multiple times, so any logic triggered by the `onLoadError` must be idempotent. #### Swift ```swift // 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)'") } } ```