# ユーザーの本人確認書類を確認する セッションを作成して、本人確認書類を収集します。 このガイドでは、Stripe Identity を使用して、身分証明書を安全に収集し、確認する方法について説明します。 自社のウェブサイト内で書類のアップロードモーダルを表示します。手順は以下のとおりです。 1. Web ページに、書類のアップロードモーダルを表示する確認ボタンを追加します。 1. 身分証明書が送信されたら、確認ページを表示します。 1. 本人確認の結果を処理します。 ## Before you begin 1. [本番環境利用の申請](https://dashboard.stripe.com/account/onboarding)を行う。 1. [Stripe Identity 申請書](https://dashboard.stripe.com/identity/application)にご記入ください。 1. (オプション) [ブランディング設定ページ](https://dashboard.stripe.com/settings/branding)でブランド設定をカスタマイズする。 ## Stripe を設定する [サーバ側] まず、Stripe アカウントを[登録](https://dashboard.stripe.com/register)します。 次に、アプリケーションから Stripe API へアクセスするためにライブラリをインストールします。 #### Ruby ```bash # Available as a gem sudo gem install stripe ``` ```ruby # If you use bundler, you can add this line to your Gemfile gem 'stripe' ``` ## Web サイトにボタンを追加する [クライアント側] 確認を開始するためのボタンを Web サイトに作成します。 #### HTML + JS ### ボタンを追加する まずは、ページに確認ボタンを追加します。 ```html Verify your identity ``` ### ページに Stripe.js ライブラリを追加する スクリプトタグを HTML ドキュメントに追加することで、ページに [Stripe.js](https://docs.stripe.com/payments/elements.md) を追加します。 ```html Verify your identity ``` > **Stripe.js** は常に `https://js.stripe.com` から直接を読み込んでください。バンドルに含めたり、お客様自身でホストしたりすることはできません。 ### Stripe.js を初期化する ページに以下の JavaScript を渡し、公開可能な [API キー](https://docs.stripe.com/keys.md)を使用して Stripe.js を初期化します。 ```html Verify your identity ``` #### React ### ボタンを追加する まずは、ページに確認ボタンを追加します。 ```jsx import React from 'react'; class VerifyButton extends React.Component { render() { return ( ); } } const App = () => { return ( ); }; export default App; ``` ### Stripe.js をインストールする [Stripe.js ES モジュール](https://www.npmjs.com/package/@stripe/stripe-js) をインストールします。 ```bash npm install @stripe/stripe-js ``` > サーバーで Node.js を使用している場合は、[stripe](https://www.npmjs.com/package/stripe) パッケージと [@stripe/stripe-js](https://www.npmjs.com/package/@stripe/stripe-js) パッケージの両方をインストールする必要があります。`stripe` はサーバー側で Stripe API へのリクエストを行うために使用され、`@stripe/stripe-js` はクライアント側のコードに [Stripe.js](https://docs.stripe.com/js.md) を組み込むためのメソッドを提供します。 ### Stripe.js を初期化する 公開可能な [API キー](https://docs.stripe.com/keys.md)を使用して `loadStripe` を呼び出します。これにより、Stripe.js が読み込まれるとすぐに Stripe オブジェクトによって解決される Promise が返されます。 ```jsx import React from 'react';import {loadStripe} from '@stripe/stripe-js'; class VerifyButton extends React.Component {constructor(props) { super(props); this.state = {}; } async componentDidMount() { this.setState({ stripe: await this.props.stripePromise }); } render() {const { stripe } = this.state; return ( ); } } // Make sure to call `loadStripe` outside of a component’s render to avoid // recreating the `Stripe` object on every render. const stripePromise = loadStripe('<>'); const App = () => { return ( ); }; export default App; ``` ## 書類のアップロードモーダルを表示する [クライアント側] [サーバ側] 書類のアップロードモーダルを表示する新しいボタンをセットアップします。このボタンをクリックすると、ユーザはパスポート、運転免許証、または国際 ID をキャプチャしてアップロードできます。 このモーダルにより、開発時間とメンテナンス時間を節約できるだけでなく、既存のフローの一環として身分証明書を収集できます。さらに、自社のサイトで顧客の個人情報を処理する量が減り、さまざまなプラットフォームと言語のユーザをサポートすることができ、ブランディングに合わせてスタイルをカスタマイズすることも可能です。 ### VerificationSession を作成する [VerificationSession](https://docs.stripe.com/api/identity/verification_sessions.md) は、本人確認をプログラムで示したものです。確認のタイプに関する詳細 (実行する[チェック](https://docs.stripe.com/identity/verification-checks.md)の内容など) が含まれています。[確認済みの出力](https://docs.stripe.com/api/identity/verification_sessions/object.md#identity_verification_session_object-verified_outputs)フィールドを[拡張](https://docs.stripe.com/api/expanding_objects.md)して、確認済みのデータの詳細を表示できます。 `VerificationSession` を作成したら、フロントエンドに [client secret](https://docs.stripe.com/api/identity/verification_sessions/object.md#identity_verification_session_object-client_secret) を送信して、書類のアップロードモーダルを表示します。 ![](https://b.stripecdn.com/docs-statics-srv/assets/modal_integration_diagram.4c9ef035ee7fcb8b8f58a99fcad27202.svg) 本人確認フローには、再利用可能な設定を使用できます。この設定は、[verification_flow](https://docs.stripe.com/api/identity/verification_sessions/create.md#create_identity_verification_session-verification_flow) パラメーターに渡されます。詳しくは、[本人確認フローガイド](https://docs.stripe.com/identity/verification-flows.md)をご確認ください。 [VerificationSession を作成](https://docs.stripe.com/api/identity/verification_sessions/create.md)するには、サーバー側のエンドポイントが必要です。サーバー側で `VerificationSession` を作成することにより、悪意のあるユーザーによる確認オプションの上書き、およびお客様のアカウントでの支払いの処理の偽装を防止できます。セッションのメタデータにユーザー参照を含めるか、データベースにセッション ID を保存することで、このエンドポイントに認証を追加します。 #### Node.js ```javascript // Don't put any keys in code. See https://docs.stripe.com/keys-best-practices. // Find your keys at https://dashboard.stripe.com/apikeys. const stripe = require('stripe')('<>'); // In the route handler for /create-verification-session: // Authenticate your user. // Create the session. const verificationSession = await stripe.identity.verificationSessions.create({ type: 'document', provided_details: { email: 'user@example.com', }, metadata: { user_id: '{{USER_ID}}', }, }); // Return only the client secret to the frontend. const clientSecret = verificationSession.client_secret; ``` > client secret を使用することで、フロントエンドで機密データである本人確認書類を収集できるようになります。使用できるのは 1 回限りで、24 時間後に有効期限が切れます。client secret は、記録したり、URL に埋め込んだり、対象のユーザ以外に公開することがないようにしてください。client secret が含まれるすべてのページで必ず TLS を有効化してください。フロントエンドに client secret のみを送信することで、本人確認の設定や結果の漏洩を回避できます。 Web サーバー (`localhost:4242` など) を起動し、curl で VerificationSession を作成する POST リクエストを送信して、エンドポイントをテストします。 ```bash curl -X POST -is "http://localhost:4242/create-verification-session" -d "" ``` 端末に次のようなレスポンスが表示されます。 ```bash HTTP/1.1 200 OK Content-Type: application/json { id: "vs_QdfQQ6xfGNJR7ogV6", client_secret: "vs_QdfQQ6xfGNJR7ogV6_secret_live_..." } ``` ### 確認ボタンにイベントハンドラを追加する VerificationSession を作成するためのボタンとエンドポイントが用意されています。ボタンを変更してクリックすると、ドキュメントのアップロードモーダルが表示されます。client secret を使用して [verifyIdentity](https://docs.stripe.com/js/identity/modal) にコールを追加します。 #### HTML + JS ```html Verify your identity ``` #### React ```jsx import React from 'react'; import {loadStripe} from '@stripe/stripe-js'; class VerifyButton extends React.Component { constructor(props) { super(props); this.state = {};this.handleClick = this.handleClick.bind(this); } async componentDidMount() { this.setState({ stripe: await this.props.stripePromise }); } async handleClick(event) { // Block native event handling. event.preventDefault(); const { stripe } = this.state; if (!stripe) { // Stripe.js hasn't loaded yet. Make sure to disable // the button until Stripe.js has loaded. return; } // Call your backend to create the VerificationSession. const response = await fetch('/create-verification-session', { method: 'POST' }); const session = await response.json(); // Show the verification modal. const { error } = await stripe.verifyIdentity(session.client_secret); if (error) { console.log('[error]', error); } else { console.log('Verification submitted!'); } } render() { const { stripe } = this.state; return ( ); } } // Make sure to call `loadStripe` outside of a component’s render to avoid // recreating the `Stripe` object on every render. const stripePromise = loadStripe('<>'); const App = () => { return ( ); }; export default App; ``` ### イベントエラーコード | エラーコード | 説明 | | ----------------------------- | -------------------------------------------------------------------------------- | | `consent_declined` | ユーザーが Stripe の本人確認を拒否しました。法律顧問に問い合わせて、手動審査など、生体認証以外の本人確認方法を提供する義務があるかどうかご確認ください。 | | `device_unsupported` | 本人確認にはカメラが必要ですが、ユーザーがカメラのないデバイスを使用しています。 | | `under_supported_age` | Stripe は未成年のユーザーの本人確認を行いません。 | | `phone_otp_declined` | ユーザーは提供された電話番号を確認できません。 | | `email_verification_declined` | ユーザーは提供されたメールアドレスを確認できません。 | ### アップロードモーダルをテストする 確認ボタンが書類のアップロードモーダルを表示するかどうかテストします。 - 確認ボタンをクリックします。すると、Stripe の文書のアップロードモーダルが表示されます。 - エラーメッセージが表示されないことを確認します。 構築したシステムが機能しない場合: 1. ブラウザの開発者ツールでネットワークタブを開きます。 1. 確認ボタンをクリックし、サーバ側エンドポイントに対して XHR リクエストが作成されるかどうか確認します (`POST /create-verification-session`)。 1. リクエストが 200 ステータスを返すことを確認します。 1. ボタンクリックリスナー内で `console.log(session)` を使用して、正しいデータが返されることを確認します。 ## 確認ページを表示する [クライアント側] ユーザフレンドリーな体験を提供するため、ユーザが身分証明書を送信したら、確認のページを表示します。確認が進行中であることをユーザに知らせるために、自社のサイトでページをホストします。 #### HTML + JS 以下のように、最小限の確認ページを作成します。 ```html Your document was submitted

Thanks for submitting your identity document.

We are processing your verification.

``` 次に、ボタンハンドラを更新し、このページにリダイレクトします。 ```html Verify your identity ``` #### React ボタンハンドラを更新し、確認メッセージを表示します。 ```jsx import React from 'react'; import {loadStripe} from '@stripe/stripe-js'; class VerifyButton extends React.Component { constructor(props) { super(props);this.state = { submitted: false }; this.handleClick = this.handleClick.bind(this); } async componentDidMount() { this.setState({ stripe: await this.props.stripePromise }); } async handleClick(event) { // Block native event handling. event.preventDefault(); const { stripe } = this.state; if (!stripe) { // Stripe.js hasn't loaded yet. Make sure to disable // the button until Stripe.js has loaded. return; } // Call your backend to create the VerificationSession. const response = await fetch('/create-verification-session', { method: 'POST' }); const session = await response.json(); // Show the verification modal. const { error } = await stripe.verifyIdentity(session.client_secret); if (error) { console.log('[error]', error.message); } else { console.log('Verification submitted!');this.setState({ submitted: true }); } } render() {const { stripe, submitted } = this.state; if (submitted) { return ( <>

Thanks for submitting your identity document

We are processing your verification.

); } return ( ); } } // Make sure to call `loadStripe` outside of a component’s render to avoid // recreating the `Stripe` object on every render. const stripePromise = loadStripe('<>'); const App = () => { return ( ); }; export default App; ``` ### 確認ページをテストする 確認ページが機能することをテストする - 確認ボタンをクリックします。 - 事前設定されたテストケースを選択してセッションを送信します。 - 新しい確認ページが表示されることを確認します。 - 失敗のケース (同意の拒否やカメラの使用拒否など) のフロー全体をテストし、アプリがこれらのケースに問題なく対応できることを確認します。 次に、Stripe ダッシュボードで確認セッションを見つけます。本人確認セッションは、ダッシュボードの [VerificationSessions の一覧](https://dashboard.stripe.com/identity)に表示されます。セッションをクリックすると、セッションの詳細ページに移動します。サマリーセクションには確認結果が含まれ、これをアプリで使用できます。 ## 確認イベントを処理する [書類確認](https://docs.stripe.com/identity/verification-checks.md#document-availability)は通常、ユーザーがサイトにリダイレクトするとすぐに完了し、API からすぐに結果を取得できます。まれに、ドキュメント検証の準備ができておらず、非同期的に続行する必要があります。このような場合、検証結果の準備ができたときに Webhook を通じて通知されます。処理が完了すると、VerificationSession のステータスが `processing` から `verified` に変わります。 セッションのステータスに変化があると、Stripe は以下のイベントを送信します。 | イベント名 | 説明 | 次のステップ | | ---------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | [identity.verification_session.verified](https://docs.stripe.com/api/events/types.md#event_types-identity.verification_session.verified) | すべての[本人確認チェック](https://docs.stripe.com/identity/verification-checks.md)の処理が完了し、確認のすべてが成功しました。 | アプリケーションで関連するアクションをトリガーします。 | | [identity.verification_session.requires_input](https://docs.stripe.com/api/events/types.md#event_types-identity.verification_session.requires_input) | すべての[本人確認チェック](https://docs.stripe.com/identity/verification-checks.md)の処理が完了し、少なくとも 1 つの確認が失敗しました。 | アプリケーションで関連するアクションをトリガーするとともに、ユーザーに本人確認の再試行を許可できます。 | [Webhook ハンドラ](https://docs.stripe.com/identity/handle-verification-outcomes.md)を使用してこれらのイベントを受信し、確定メールの送信、自社データベース内の確認結果の更新、アカウント登録ステップの完了などのアクションを自動化します。[ダッシュボードに確認イベント](https://dashboard.stripe.com/events?type=identity.%2A)を表示することもできます。 ## イベントを受信して、ビジネスアクションを実行する ### コード使用 Webhook ハンドラを構築してイベントをリッスンし、非同期型のカスタムの確認フローを作成します。Stripe CLI を使用して、ローカルで Webhook の組み込みのテストとデバッグを行います。 [カスタム Webhook を作成する](https://docs.stripe.com/identity/handle-verification-outcomes.md) ### コードなし ダッシュボードを使用してすべての本人確認を表示し、収集されたデータを調査して、確認の失敗について把握します。 [ダッシュボードでテストの確認を表示する](https://dashboard.stripe.com/test/identity/verification-sessions) ## See also - [本人確認の結果を処理する](https://docs.stripe.com/identity/handle-verification-outcomes.md) - [VerificationSessions について](https://docs.stripe.com/identity/verification-sessions.md) - [Stripe.js について](https://docs.stripe.com/payments/elements.md) ユーザーを Stripe に移動して、本人確認書類をアップロードできるようにします。手順は以下のとおりです。 1. Stripe Identity にリダイレクトする確認ボタンを Web ページに追加します。 1. 身分証明書が送信されたら、確認ページを表示します。 1. 本人確認の結果を処理します。 ## Before you begin 1. [本番環境利用の申請](https://dashboard.stripe.com/account/onboarding)を行う。 1. [Stripe Identity 申請書](https://dashboard.stripe.com/identity/application)にご記入ください。 1. (オプション) [ブランディング設定ページ](https://dashboard.stripe.com/settings/branding)でブランド設定をカスタマイズする。 ## Stripe を設定する [サーバ側] まず、Stripe アカウントを[登録](https://dashboard.stripe.com/register)します。 次に、アプリケーションから Stripe API へアクセスするためにライブラリをインストールします。 #### Ruby ```bash # Available as a gem sudo gem install stripe ``` ```ruby # If you use bundler, you can add this line to your Gemfile gem 'stripe' ``` ## Web サイトにボタンを追加する [クライアント側] 確認を開始するためのボタンを Web サイトに作成します。 #### HTML + JS ### ボタンを追加する まずは、ページに確認ボタンを追加します。 ```html Verify your identity ``` #### React ### ボタンを追加する まずは、ページに確認ボタンを追加します。 ```jsx import React from 'react'; class VerifyButton extends React.Component { render() { return ( ); } } const App = () => { return ( ); }; export default App; ``` ## Stripe Identity にリダイレクトする [クライアント側] [サーバー側] Stripe Identity にリダイレクトするボタンをセットアップします。このボタンをクリックすると、フロントエンドは、Stripe がオンラインで提供するページにリダイレクトされ、ここでユーザはパスポート、運転免許証、国際 ID をキャプチャしてアップロードできます。 Stripe Identity にリダイレクトすることにより、開発時間とメンテナンス時間を節約できるだけでなく、セキュリティを強化することもできます。さらに、自社のサイトで顧客の個人情報を処理する量が減り、さまざまなプラットフォームと言語のユーザをサポートすることができ、ブランディングに合わせてスタイルをカスタマイズすることも可能です。 ### VerificationSession を作成する [VerificationSession](https://docs.stripe.com/api/identity/verification_sessions.md) は、本人確認をプログラムで示したものです。確認のタイプに関する詳細 (実行する[チェック](https://docs.stripe.com/identity/verification-checks.md)の内容など) が含まれています。[確認済みの出力](https://docs.stripe.com/api/identity/verification_sessions/object.md#identity_verification_session_object-verified_outputs)フィールドを[拡張](https://docs.stripe.com/api/expanding_objects.md)して、確認済みのデータの詳細を表示できます。 `VerificationSession` を作成したら、フロントエンドに[セッション URL](https://docs.stripe.com/api/identity/verification_sessions/object.md#identity_verification_session_object-url) を送信して、Stripe Identity にリダイレクトします。 ![](https://b.stripecdn.com/docs-statics-srv/assets/modal_integration_diagram.4c9ef035ee7fcb8b8f58a99fcad27202.svg) 本人確認フローには、再利用可能な設定を使用できます。この設定は、[verification_flow](https://docs.stripe.com/api/identity/verification_sessions/create.md#create_identity_verification_session-verification_flow) パラメーターに渡されます。詳しくは、[本人確認フローガイド](https://docs.stripe.com/identity/verification-flows.md)をご確認ください。 [VerificationSession を作成](https://docs.stripe.com/api/identity/verification_sessions/create.md)するには、サーバー側のエンドポイントが必要です。サーバー側で `VerificationSession` を作成することにより、悪意のあるユーザーによる確認オプションの上書き、およびお客様のアカウントでの支払いの処理の偽装を防止できます。セッションのメタデータにユーザー参照を含めるか、データベースにセッション ID を保存することで、このエンドポイントに認証を追加します。 #### Node.js ```javascript // Don't put any keys in code. See https://docs.stripe.com/keys-best-practices. // Find your keys at https://dashboard.stripe.com/apikeys. const stripe = require('stripe')('<>'); // In the route handler for /create-verification-session: // Authenticate your user. // Create the session. const verificationSession = await stripe.identity.verificationSessions.create({ type: 'document', provided_details: { email: 'user@example.com', }, metadata: { user_id: '{{USER_ID}}', }, }); // Return only the session URL to the frontend. const url = verificationSession.url; ``` > セッション URL を使用できるのは 1 回限りで、48 時間後に有効期限が切れます。セッション URL は、保存したり、記録したり、URL に埋め込んだり、対象のユーザー以外に公開したりしないようにしてください。フロントエンドにセッション URL のみを送信することにより、本人確認の設定や結果の漏洩を回避できます。 Web サーバー (`localhost:4242` など) を起動し、curl で VerificationSession を作成する POST リクエストを送信して、エンドポイントをテストします。 ```bash curl -X POST -is "http://localhost:4242/create-verification-session" -d "" ``` 端末に次のようなレスポンスが表示されます。 ```bash HTTP/1.1 200 OK Content-Type: application/json { id: "vs_QdfQQ6xfGNJR7ogV6", url: "https://verify.stripe.com/start/QdfQQ6xfxNJR7ogV6Z6Wp..." } ``` ### 確認ボタンにイベントハンドラを追加する VerificationSession を作成するためのボタンとエンドポイントが準備できています。次にボタンを変更して、クリックするとセッション URL にリダイレクトようにします。 #### HTML + JS ```html Verify your identity ``` #### React ```jsx import React from 'react'; import {loadStripe} from '@stripe/stripe-js'; class VerifyButton extends React.Component {async handleClick(event) { // Block native event handling. event.preventDefault(); // Call your backend to create the VerificationSession. const response = await fetch('/create-verification-session', { method: 'POST' }); const session = await response.json(); // When the user clicks on the button, redirect to the session URL. window.location.href = session.url; } render() { return ( ); } } // Make sure to call `loadStripe` outside of a component’s render to avoid // recreating the `Stripe` object on every render. const stripePromise = loadStripe('<>'); const App = () => { return ( ); }; export default App; ``` ### リダイレクトをテストする 確認ボタンが Stripe Identity にリダイレクトするかどうかテストします。 - 確認ボタンをクリックします。 - ブラウザが Stripe Identity にリダイレクトすることを確認します。 構築したシステムが機能しない場合: 1. ブラウザの開発者ツールでネットワークタブを開きます。 1. 確認ボタンをクリックし、サーバ側エンドポイントに対して XHR リクエストが作成されるかどうか確認します (`POST /create-verification-session`)。 1. リクエストが 200 ステータスを返すことを確認します。 1. ボタンクリックリスナー内で `console.log(session)` を使用して、正しいデータが返されることを確認します。 ## 確認イベントを処理する [書類確認](https://docs.stripe.com/identity/verification-checks.md#document-availability)は通常、ユーザーがサイトにリダイレクトするとすぐに完了し、API からすぐに結果を取得できます。まれに、ドキュメント検証の準備ができておらず、非同期的に続行する必要があります。このような場合、検証結果の準備ができたときに Webhook を通じて通知されます。処理が完了すると、VerificationSession のステータスが `processing` から `verified` に変わります。 セッションのステータスに変化があると、Stripe は以下のイベントを送信します。 | イベント名 | 説明 | 次のステップ | | ---------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | [identity.verification_session.verified](https://docs.stripe.com/api/events/types.md#event_types-identity.verification_session.verified) | すべての[本人確認チェック](https://docs.stripe.com/identity/verification-checks.md)の処理が完了し、確認のすべてが成功しました。 | アプリケーションで関連するアクションをトリガーします。 | | [identity.verification_session.requires_input](https://docs.stripe.com/api/events/types.md#event_types-identity.verification_session.requires_input) | すべての[本人確認チェック](https://docs.stripe.com/identity/verification-checks.md)の処理が完了し、少なくとも 1 つの確認が失敗しました。 | アプリケーションで関連するアクションをトリガーするとともに、ユーザーに本人確認の再試行を許可できます。 | [Webhook ハンドラ](https://docs.stripe.com/identity/handle-verification-outcomes.md)を使用してこれらのイベントを受信し、確定メールの送信、自社データベース内の確認結果の更新、アカウント登録ステップの完了などのアクションを自動化します。[ダッシュボードに確認イベント](https://dashboard.stripe.com/events?type=identity.%2A)を表示することもできます。 ## イベントを受信して、ビジネスアクションを実行する ### コード使用 Webhook ハンドラを構築してイベントをリッスンし、非同期型のカスタムの確認フローを作成します。Stripe CLI を使用して、ローカルで Webhook の組み込みのテストとデバッグを行います。 [カスタム Webhook を作成する](https://docs.stripe.com/identity/handle-verification-outcomes.md) ### コードなし ダッシュボードを使用してすべての本人確認を表示し、収集されたデータを調査して、確認の失敗について把握します。 [ダッシュボードでテストの確認を表示する](https://dashboard.stripe.com/test/identity/verification-sessions) ## Optional: 確認ページを表示する [クライアント側] ユーザフレンドリーな体験を提供するため、ユーザが身分証明書を送信した後、Identity はお客様の Web サイト上のページにユーザをリダイレクトできます。 以下のように、最小限の確認ページを作成します。 ```html Your document was submitted

Thanks for submitting your identity document.

We are processing your verification.

``` 次に、 `return_url` パラメータでこのページの URL を使用して、VerificationSession 作成コールを更新します。 #### Node.js ```javascript const verificationSession = await stripe.identity.verificationSessions.create({ type: 'document',return_url: 'https://{{ YOUR_DOMAIN }}/submitted.html', metadata: { user_id: '{{USER_ID}}' }, }); ``` ### 確認ページをテストする 確認ページが機能することをテストする - 確認ボタンをクリックします。 - 事前設定されたテストケースを選択してセッションを送信します。 - 新しい確認ページが表示されることを確認します。 - 失敗のケース (同意の拒否やカメラの使用拒否など) のフロー全体をテストし、アプリがこれらのケースに問題なく対応できることを確認します。 次に、Stripe ダッシュボードで確認セッションを見つけます。本人確認セッションは、ダッシュボードの [VerificationSessions の一覧](https://dashboard.stripe.com/identity)に表示されます。セッションをクリックすると、セッションの詳細ページに移動します。サマリーセクションには確認結果が含まれ、これをアプリで使用できます。 ## See also - [本人確認の結果を処理する](https://docs.stripe.com/identity/handle-verification-outcomes.md) - [VerificationSessions について](https://docs.stripe.com/identity/verification-sessions.md) - [Stripe.js について](https://docs.stripe.com/payments/elements.md) > Identity iOS SDK を利用するには、[Identity 設定](https://dashboard.stripe.com/settings/identity)ページにアクセスして、**有効にする**をクリックします。 iOS でユーザーの本人確認を行うには、自社のアプリケーションに確認画面を表示します。このガイドでは、以下の手順を説明します。 1. Stripe を設定します。 1. サーバーエンドポイントを追加します。 1. 確認画面を表示します。 1. 確認イベントを処理します。 ## Before you begin 1. [本番環境利用の申請](https://dashboard.stripe.com/account/onboarding)を行う。 1. [Stripe Identity 申請書](https://dashboard.stripe.com/identity/application)にご記入ください。 このガイドの手順は、[サンプルアプリ](https://github.com/stripe/stripe-ios/tree/master/Example/IdentityVerification%20Example) と [サンプルバックエンドサーバー](https://codesandbox.io/p/devbox/compassionate-violet-gshhgf) で完全に実装されています。 ## 設定 [サーバー側] [クライアント側] > この SDK を Stripe Identity サービスで使用する場合、この SDK を改変してはいけません。Stripe の書面による承認を得ずに、改変された SDK を Stripe Identity サービスで使用することは Stripe との契約に違反することになり、Stripe アカウントが閉鎖される場合があります。 ### SDK をインストールする (クライアント側) [Stripe iOS SDK](https://github.com/stripe/stripe-ios) はオープンソースです。[詳細なドキュメントが提供されており](https://stripe.dev/stripe-ios/index.html)、iOS 13.0 以降をサポートするアプリと互換性があります。 #### Swift Package Manager SDK をインストールするには、以下のステップに従います。 1. Xcode で、**File (ファイル)** > **Add Package Dependencies… (パッケージ依存関係を追加)** を選択し、リポジトリー URL として `https://github.com/stripe/stripe-ios-spm` を入力します。 1. [リリースページ](https://github.com/stripe/stripe-ios/releases)から最新のバージョン番号を選択します。 1. **StripeIdentity** 製品を[アプリのターゲット](https://developer.apple.com/documentation/swift_packages/adding_package_dependencies_to_your_app)に追加します。 #### CocoaPods 1. まだインストールしていない場合は、[CocoaPods](https://guides.cocoapods.org/using/getting-started.html) の最新バージョンをインストールします。 1. 既存の [Podfile](https://guides.cocoapods.org/syntax/podfile.html) がない場合は、以下のコマンドを実行して作成します。 ```bash pod init ``` 1. この行を `Podfile` に追加します。 ```podfile pod 'StripeIdentity' ``` 1. 以下のコマンドを実行します。 ```bash pod install ``` 1. これ以降は、Xcode でプロジェクトを開く際に、`.xcodeproj` ファイルではなく、必ず `.xcworkspace` ファイルを使用するということを忘れないでください。 1. 今後、SDK の最新バージョンに更新するには、以下を実行します。 ```bash pod update StripeIdentity ``` #### Carthage 1. まだインストールしていない場合は、[Carthage](https://github.com/Carthage/Carthage#installing-carthage) の最新バージョンをインストールします。 1. この行を `Cartfile` に追加します。 ```cartfile github "stripe/stripe-ios" ``` 1. [Carthage のインストール手順](https://github.com/Carthage/Carthage#if-youre-building-for-ios-tvos-or-watchos)に従います。必ず、[こちら](https://github.com/stripe/stripe-ios/tree/master/StripeIdentity#manual-linking)にリストされている必要なフレームワークのすべてを埋め込んでください。 1. 今後、SDK の最新バージョンに更新するには、以下のコマンドを実行します。 ```bash carthage update stripe-ios --platform ios ``` #### 手動のフレームワーク 1. Stripe の [GitHub リリースページ](https://github.com/stripe/stripe-ios/releases/latest)に移動して、**Stripe.xcframework.zip** をダウンロードして解凍します。 1. **StripeIdentity.xcframework** を、Xcode プロジェクトの **General (一般) ** 設定の **Embedded Binaries (埋め込みバイナリー)** セクションにドラッグします。**Copy items if needed (必要に応じてアイテムをコピーする)** を必ず選択してください。 1. [こちら](https://github.com/stripe/stripe-ios/tree/master/StripeIdentity#manual-linking)にリストされている必要なフレームワークのすべてに対して、ステップ 2 を繰り返します。 1. 今後、Stripe の SDK の最新バージョンに更新するには、ステップ 1 から 3 を繰り返します。 > SDK の最新リリースおよび過去バージョンの詳細については、GitHub の [Releases (リリース)](https://github.com/stripe/stripe-ios/releases) ページをご覧ください。リポジトリの[リリースをウォッチ](https://help.github.com/en/articles/watching-and-unwatching-releases-for-a-repository#watching-releases-for-a-repository)して、新しいリリースの公開時に通知を受け取ることも可能です。 ### カメラの使用許可を設定する (クライアント側) Stripe Identity iOS SDK では、デバイスのカメラにアクセスして本人確認書類をキャプチャーする必要があります。アプリがカメラの使用許可をリクエストできるようにするには、以下の手順に従います。 1. Xcode で、プロジェクトの **Info.plist** を開きます。 1. `NSCameraUsageDescription` キーを追加します。 1. アプリにカメラへのアクセスの許可が必要な理由をユーザーに説明する文字列値を追加します。 > このアプリは、カメラを使用して本人確認書類の写真を撮影します。 カメラ認証のリクエストについて、詳細は [Apple のドキュメント](https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/requesting_authorization_for_media_capture_on_ios)を参照してください。 ### サーバーに Stripe をインストールする (サーバー側) まず、Stripe アカウントを[登録](https://dashboard.stripe.com/register)します。 次に、アプリケーションから Stripe API へアクセスするためにライブラリをインストールします。 #### Ruby ```bash # Available as a gem sudo gem install stripe ``` ```ruby # If you use bundler, you can add this line to your Gemfile gem 'stripe' ``` ## サーバーエンドポイントを追加する [サーバー側] ### VerificationSession を作成する [VerificationSession](https://docs.stripe.com/api/identity/verification_sessions.md) は、本人確認をプログラムで示したものです。確認のタイプに関する詳細 (実行する[チェック](https://docs.stripe.com/identity/verification-checks.md)の内容など) が含まれています。[確認済みの出力](https://docs.stripe.com/api/identity/verification_sessions/object.md#identity_verification_session_object-verified_outputs)フィールドを[拡張](https://docs.stripe.com/api/expanding_objects.md)して、確認済みのデータの詳細を表示できます。 本人確認フローには、再利用可能な設定を使用できます。この設定は、[verification_flow](https://docs.stripe.com/api/identity/verification_sessions/create.md#create_identity_verification_session-verification_flow) パラメーターに渡されます。詳しくは、[本人確認フローガイド](https://docs.stripe.com/identity/verification-flows.md)をご確認ください。 [VerificationSession を作成](https://docs.stripe.com/api/identity/verification_sessions/create.md)するには、サーバー側のエンドポイントが必要です。サーバー側で `VerificationSession` を作成することにより、悪意のあるユーザーによる確認オプションの上書き、およびお客様のアカウントでの支払いの処理の偽装を防止できます。セッションのメタデータにユーザー参照を含めるか、データベースにセッション ID を保存することで、このエンドポイントに認証を追加します。 セキュリティ上の理由から、モバイルクライアントから直接アクセス可能な `VerificationSession` オブジェクトを作成しないでください。代わりに、サーバーが SDK に一時キーを提供します。このキーは、[VerificationSession](https://docs.stripe.com/api/identity/verification_sessions.md) への制限付きアクセス権が付与された一時的な API キーです。一時キーは、セッションとして考えることができ、そのセッションの間は SDK が特定の `VerificationSession` オブジェクトを取得して更新することが許可されます。 `VerificationSession` と一時キーを作成したら、その `VerificationSession` の [ID](https://docs.stripe.com/api/identity/verification_sessions/object.md#identity_verification_session_object-id) と一時キーシークレットをクライアントに送信し、書類のアップロード画面を表示します。 > このエンドポイントの実行中の実装を [こちら](https://codesandbox.io/p/devbox/compassionate-violet-gshhgf) で迅速なテスト用に見つけることができます。 #### Node.js ```javascript // Don't put any keys in code. See https://docs.stripe.com/keys-best-practices. // Find your keys at https://dashboard.stripe.com/apikeys. const stripe = require('stripe')('<>'); // In the route handler for /create-verification-session: // Authenticate your user. // Create the session. const verificationSession = await stripe.identity.verificationSessions.create({ type: 'document', provided_details: { email: 'user@example.com', }, metadata: { user_id: '{{USER_ID}}', }, }); // Create an ephemeral key for the VerificationSession const ephemeralKey = await stripe.ephemeralKeys.create( {verification_session: verificationSession.id}, {apiVersion: '2026-03-25.dahlia'} ); // Return only the ID and ephemeral key secret to the frontend. const verificationSessionId = verificationSession.id; const ephemeralKeySecret = ephemeralKey.secret; ``` > 一時キーシークレットは `VerificationSession` にバインドされており、これによりアプリは機密データである本人確認情報 (書類や顔写真のファイルなど) を収集できるようになります。使用できるのは 1 回限りで、1 時間後に有効期限が切れます。一時キーシークレットは、記録したり、URL に埋め込んだり、対象のユーザー以外に公開したりしないでください。一時キーシークレットを返すエンドポイントで必ず TLS を有効化します。本人確認の設定や結果の漏洩を防止するため、一時キーシークレットのみをアプリに送信してください。 Web サーバー (`localhost:4242` など) を起動し、curl で VerificationSession を作成する POST リクエストを送信して、エンドポイントをテストします。 ```bash curl -X POST -is "http://localhost:4242/create-verification-session" -d "" ``` 端末に次のようなレスポンスが表示されます。 ```bash HTTP/1.1 200 OK Content-Type: application/json { id: "vs_QdfQQ6xfGNJR7ogV6", ephemeral_key_secret: "ek_YWNjdF8xRm..." } ``` ## 確認画面を表示する [クライアント側] 確認画面を表示するボタンをセットアップします。このボタンをタップすると、ユーザーはパスポート、運転免許証、または国民 ID をキャプチャーしてアップロードできます。 開始する前に、確認ページで以下を行う必要があります。 - 本人確認が必要な理由をユーザーに説明します。 - Stripe の UI を表示する本人確認ボタンを含めます。 ### ボタンを追加する まず、タップアクションと読み込みインジケータを持つ、ボタン付きのビューコントローラーを作成します。 ```swift import UIKit class VerifyViewController: UIViewController { @IBOutlet weak var verifyButton: UIButton! @IBOutlet weak var activityIndicator: UIActivityIndicatorView! } ``` ### StripeIdentity SDK をインポートする `StripeIdentity` をビューコントローラーに追加します。 ```swift import UIKitimport StripeIdentity class VerifyViewController: UIViewController { @IBOutlet weak var verifyButton: UIButton! @IBOutlet weak var activityIndicator: UIActivityIndicatorView! } ``` ### 確認ボタンにアクションを追加する `VerificationSession` を作成するためのボタンとエンドポイントが準備できたため、次にボタンを変更して、ボタンがタップされたら、書類のアップロード画面が表示されるようにします。 次のためのコールを追加します。 - エンドポイントから、`VerificationSession` ID と一時キーシークレットを取得します。 - ブランドロゴで `IdentityVerificationSheet` をインスタンス化し、ユーザーに提示します。 - `VerificationResult` で、顧客が本人確認フローを完了したかを把握できます。 ```swift import UIKit import StripeIdentity class VerifyViewController: UIViewController { @IBOutlet weak var verifyButton: UIButton! @IBOutlet weak var activityIndicator: UIActivityIndicatorView! override func viewDidLoad() { super.viewDidLoad() verifyButton.addTarget(self, action: #selector(didTapVerifyButton), for: .touchUpInside) } @objc func didTapVerifyButton() { // Disable the button while the request is made verifyButton.isEnabled = false activityIndicator.startAnimating() // Make request to your verification endpoint var urlRequest = URLRequest(url: URL(string: "https://{{YOUR_SERVER_BASE_URL}}/create-verification-session")!) urlRequest.httpMethod = "POST" let task = URLSession.shared.dataTask(with: urlRequest) { [weak self] data, response, error in DispatchQueue.main.async { [weak self] in // Re-enable button self?.verifyButton.isEnabled = true self?.activityIndicator.stopAnimating() guard error == nil, let data = data, let responseJson = try? JSONDecoder().decode([String: String].self, from: data), let verificationSessionId = responseJson["id"], let ephemeralKeySecret = responseJson["ephemeral_key_secret"] else { // Handle error print(error as Any) return } self?.presentVerificationSheet(verificationSessionId: verificationSessionId, ephemeralKeySecret: ephemeralKeySecret) } } task.resume() } func presentVerificationSheet(verificationSessionId: String, ephemeralKeySecret: String) { // Configure a square brand logo. Recommended image size is 32 x 32 points. let configuration = IdentityVerificationSheet.Configuration( brandLogo: UIImage(named: "{{YOUR_BRAND_LOGO}}")! ) // Instantiate and present the sheet let verificationSheet = IdentityVerificationSheet( verificationSessionId: verificationSessionId, ephemeralKeySecret: ephemeralKeySecret, configuration: configuration ) verificationSheet.present(from: self, completion: { result in switch result { case .flowCompleted: // The user has completed uploading their documents. // Let them know that the verification is processing. print("Verification Completed!") case .flowCanceled: // The user did not complete uploading their documents. // You should allow them to try again. print("Verification Canceled!") case .flowFailed(let error): // If the flow fails, you should display the localized error // message to your user using error.localizedDescription print("Verification Failed!") print(error.localizedDescription) } }) } } ``` ### 確認画面をテストする 確認ボタンで書類のアップロード画面が表示されるかどうかテストします。 - **本人確認**ボタンをタップします。 - エラーメッセージが表示されないことを確認します。 構築したシステムが機能しない場合: 1. `VerificationSession` ID と一時キーシークレットを取得する場所にブレークポイントを配置します。 1. ネットワークエラーがないこと、およびエンドポイントが `VerificationSession` ID と一時キーシークレットを返すことを確認します。 ## 確認イベントを処理する [書類確認](https://docs.stripe.com/identity/verification-checks.md#document-availability)は通常、ユーザーがサイトにリダイレクトするとすぐに完了し、API からすぐに結果を取得できます。まれに、ドキュメント検証の準備ができておらず、非同期的に続行する必要があります。このような場合、検証結果の準備ができたときに Webhook を通じて通知されます。処理が完了すると、VerificationSession のステータスが `processing` から `verified` に変わります。 セッションのステータスに変化があると、Stripe は以下のイベントを送信します。 | イベント名 | 説明 | 次のステップ | | ---------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | [identity.verification_session.verified](https://docs.stripe.com/api/events/types.md#event_types-identity.verification_session.verified) | すべての[本人確認チェック](https://docs.stripe.com/identity/verification-checks.md)の処理が完了し、確認のすべてが成功しました。 | アプリケーションで関連するアクションをトリガーします。 | | [identity.verification_session.requires_input](https://docs.stripe.com/api/events/types.md#event_types-identity.verification_session.requires_input) | すべての[本人確認チェック](https://docs.stripe.com/identity/verification-checks.md)の処理が完了し、少なくとも 1 つの確認が失敗しました。 | アプリケーションで関連するアクションをトリガーするとともに、ユーザーに本人確認の再試行を許可できます。 | [Webhook ハンドラ](https://docs.stripe.com/identity/handle-verification-outcomes.md)を使用してこれらのイベントを受信し、確定メールの送信、自社データベース内の確認結果の更新、アカウント登録ステップの完了などのアクションを自動化します。[ダッシュボードに確認イベント](https://dashboard.stripe.com/events?type=identity.%2A)を表示することもできます。 ## イベントを受信して、ビジネスアクションを実行する ### コード使用 Webhook ハンドラを構築してイベントをリッスンし、非同期型のカスタムの確認フローを作成します。Stripe CLI を使用して、ローカルで Webhook の組み込みのテストとデバッグを行います。 [カスタム Webhook を作成する](https://docs.stripe.com/identity/handle-verification-outcomes.md) ### コードなし ダッシュボードを使用してすべての本人確認を表示し、収集されたデータを調査して、確認の失敗について把握します。 [ダッシュボードでテストの確認を表示する](https://dashboard.stripe.com/test/identity/verification-sessions) > Identity iOS SDK を利用するには、[Identity 設定](https://dashboard.stripe.com/settings/identity)ページにアクセスして、**有効にする**をクリックします。 このガイドでは、Stripe Identity のシステムを[ウェブ版の Redirect](https://docs.stripe.com/identity/verify-identity-documents.md?platform=web&type=redirect) からモバイルアプリのネイティブの iOS SDK に移行する方法を説明します。このガイドでは、以下の手順を説明します。 1. Stripe を設定します。 1. サーバーエンドポイントを更新します。 1. 確認画面を表示します。 1. 確認イベントを処理します。 ## Before you begin 1. [本番環境利用の申請](https://dashboard.stripe.com/account/onboarding)を行う。 1. [Stripe Identity 申請書](https://dashboard.stripe.com/identity/application)にご記入ください。 このガイドの手順は、[サンプルアプリ](https://github.com/stripe/stripe-ios/tree/master/Example/IdentityVerification%20Example) と [サンプルバックエンドサーバー](https://codesandbox.io/p/devbox/compassionate-violet-gshhgf) で完全に実装されています。 ## 設定 [サーバー側] [クライアント側] > この SDK を Stripe Identity サービスで使用する場合、この SDK を改変してはいけません。Stripe の書面による承認を得ずに、改変された SDK を Stripe Identity サービスで使用することは Stripe との契約に違反することになり、Stripe アカウントが閉鎖される場合があります。 ### SDK をインストールする (クライアント側) [Stripe iOS SDK](https://github.com/stripe/stripe-ios) はオープンソースです。[詳細なドキュメントが提供されており](https://stripe.dev/stripe-ios/index.html)、iOS 13.0 以降をサポートするアプリと互換性があります。 #### Swift Package Manager SDK をインストールするには、以下のステップに従います。 1. Xcode で、**File (ファイル)** > **Add Package Dependencies… (パッケージ依存関係を追加)** を選択し、リポジトリー URL として `https://github.com/stripe/stripe-ios-spm` を入力します。 1. [リリースページ](https://github.com/stripe/stripe-ios/releases)から最新のバージョン番号を選択します。 1. **StripeIdentity** 製品を[アプリのターゲット](https://developer.apple.com/documentation/swift_packages/adding_package_dependencies_to_your_app)に追加します。 #### CocoaPods 1. まだインストールしていない場合は、[CocoaPods](https://guides.cocoapods.org/using/getting-started.html) の最新バージョンをインストールします。 1. 既存の [Podfile](https://guides.cocoapods.org/syntax/podfile.html) がない場合は、以下のコマンドを実行して作成します。 ```bash pod init ``` 1. この行を `Podfile` に追加します。 ```podfile pod 'StripeIdentity' ``` 1. 以下のコマンドを実行します。 ```bash pod install ``` 1. これ以降は、Xcode でプロジェクトを開く際に、`.xcodeproj` ファイルではなく、必ず `.xcworkspace` ファイルを使用するということを忘れないでください。 1. 今後、SDK の最新バージョンに更新するには、以下を実行します。 ```bash pod update StripeIdentity ``` #### Carthage 1. まだインストールしていない場合は、[Carthage](https://github.com/Carthage/Carthage#installing-carthage) の最新バージョンをインストールします。 1. この行を `Cartfile` に追加します。 ```cartfile github "stripe/stripe-ios" ``` 1. [Carthage のインストール手順](https://github.com/Carthage/Carthage#if-youre-building-for-ios-tvos-or-watchos)に従います。必ず、[こちら](https://github.com/stripe/stripe-ios/tree/master/StripeIdentity#manual-linking)にリストされている必要なフレームワークのすべてを埋め込んでください。 1. 今後、SDK の最新バージョンに更新するには、以下のコマンドを実行します。 ```bash carthage update stripe-ios --platform ios ``` #### 手動のフレームワーク 1. Stripe の [GitHub リリースページ](https://github.com/stripe/stripe-ios/releases/latest)に移動して、**Stripe.xcframework.zip** をダウンロードして解凍します。 1. **StripeIdentity.xcframework** を、Xcode プロジェクトの **General (一般) ** 設定の **Embedded Binaries (埋め込みバイナリー)** セクションにドラッグします。**Copy items if needed (必要に応じてアイテムをコピーする)** を必ず選択してください。 1. [こちら](https://github.com/stripe/stripe-ios/tree/master/StripeIdentity#manual-linking)にリストされている必要なフレームワークのすべてに対して、ステップ 2 を繰り返します。 1. 今後、Stripe の SDK の最新バージョンに更新するには、ステップ 1 から 3 を繰り返します。 > SDK の最新リリースおよび過去バージョンの詳細については、GitHub の [Releases (リリース)](https://github.com/stripe/stripe-ios/releases) ページをご覧ください。リポジトリの[リリースをウォッチ](https://help.github.com/en/articles/watching-and-unwatching-releases-for-a-repository#watching-releases-for-a-repository)して、新しいリリースの公開時に通知を受け取ることも可能です。 ### カメラの使用許可を設定する (クライアント側) Stripe Identity iOS SDK では、デバイスのカメラにアクセスして本人確認書類をキャプチャーする必要があります。アプリがカメラの使用許可をリクエストできるようにするには、以下の手順に従います。 1. Xcode で、プロジェクトの **Info.plist** を開きます。 1. `NSCameraUsageDescription` キーを追加します。 1. アプリにカメラへのアクセスの許可が必要な理由をユーザーに説明する文字列値を追加します。 > このアプリは、カメラを使用して本人確認書類の写真を撮影します。 カメラ認証のリクエストについて、詳細は [Apple のドキュメント](https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/requesting_authorization_for_media_capture_on_ios)を参照してください。 ### サーバーに Stripe をインストールする (サーバー側) まず、Stripe アカウントを[登録](https://dashboard.stripe.com/register)します。 次に、アプリケーションから Stripe API へアクセスするためにライブラリをインストールします。 #### Ruby ```bash # Available as a gem sudo gem install stripe ``` ```ruby # If you use bundler, you can add this line to your Gemfile gem 'stripe' ``` ## サーバーエンドポイントを更新する [サーバー側] ### 既存のウェブ版の実装 [モーダル](https://docs.stripe.com/identity/verify-identity-documents.md?platform=web&type=modal) の実装を使用していた場合は、[VerificationSession](https://docs.stripe.com/api/identity/verification_sessions.md) が作成され、`VerificationSession` [client_secret](https://docs.stripe.com/api/identity/verification_sessions/object.md#identity_verification_session_object-client_secret) が Stripe API オブジェクトに渡されています。 #### Node.js ```javascript // Don't put any keys in code. See https://docs.stripe.com/keys-best-practices. // Find your keys at https://dashboard.stripe.com/apikeys. const stripe = require('stripe')('<>'); // In the route handler for /create-verification-session: // Authenticate your user. // Create the session. const verificationSession = await stripe.identity.verificationSessions.create({ type: 'document', provided_details: { email: 'user@example.com', }, metadata: { user_id: '{{USER_ID}}', }, }); // Return only the client secret to the frontend. const clientSecret = verificationSession.client_secret; ``` [リダイレクト](https://docs.stripe.com/identity/verify-identity-documents.md?platform=web&type=redirect) の実装を使用していた場合は、[VerificationSession](https://docs.stripe.com/api/identity/verification_sessions.md) が作成され、`VerificationSession` [url](https://docs.stripe.com/api/identity/verification_sessions/object.md#identity_verification_session_object-url) がクライアントのモバイルアプリに送信され、アプリ内のブラウザーに表示されています。 #### Node.js ```javascript // Don't put any keys in code. See https://docs.stripe.com/keys-best-practices. // Find your keys at https://dashboard.stripe.com/apikeys. const stripe = require('stripe')('<>'); // In the route handler for /create-verification-session: // Authenticate your user. // Create the session. const verificationSession = await stripe.identity.verificationSessions.create({ type: 'document', provided_details: { email: 'user@example.com', }, metadata: { user_id: '{{USER_ID}}', }, }); // Return only the session URL to the frontend. const url = verificationSession.url; ``` ### SDK の実装に移行する ネイティブ SDK を使用するには、同じ [VerificationSession](https://docs.stripe.com/api/identity/verification_sessions.md) を作成して、一時キーシークレットを作成します。 #### Node.js ```javascript // Don't put any keys in code. See https://docs.stripe.com/keys-best-practices. // Find your keys at https://dashboard.stripe.com/apikeys. const stripe = require('stripe')('<>'); // In the route handler for /create-verification-session: // Authenticate your user. // Create the session. const verificationSession = await stripe.identity.verificationSessions.create({ type: 'document', provided_details: { email: 'user@example.com', }, metadata: { user_id: '{{USER_ID}}', }, }); // Create an ephemeral key for the VerificationSession const ephemeralKey = await stripe.ephemeralKeys.create( {verification_session: verificationSession.id}, {apiVersion: '2026-03-25.dahlia'} ); // Return only the ID and ephemeral key secret to the frontend. const verificationSessionId = verificationSession.id; const ephemeralKeySecret = ephemeralKey.secret; ``` `VerificationSession` と一時キーを作成したら、その `VerificationSession` [ID](https://docs.stripe.com/api/identity/verification_sessions/object.md#identity_verification_session_object-id) と `ephemeral key secret` をクライアントのモバイルアプリに送信します。 > このエンドポイントの実行中の実装を [こちら](https://codesandbox.io/p/devbox/compassionate-violet-gshhgf) で迅速なテスト用に見つけることができます。 > 一時キーシークレットを使用することで、アプリは機密データである本人確認情報を収集できるようになります。使用できるのは 1 回限りで、1 時間後に有効期限が切れます。一時キーシークレットは、記録したり、URL に埋め込んだり、対象のユーザー以外に公開したりしないでください。一時キーシークレットを返すエンドポイントで必ず TLS を有効化します。本人確認の設定や結果の漏洩を防止するため、一時キーシークレットのみをアプリに送信してください。 ## 確認画面を表示する [クライアント側] 確認画面を表示するボタンをセットアップします。このボタンをタップすると、ユーザーはパスポート、運転免許証、または国民 ID をキャプチャーしてアップロードできます。 開始する前に、確認ページで以下を行う必要があります。 - 本人確認が必要な理由をユーザーに説明します。 - Stripe の UI を表示する本人確認ボタンを含めます。 ### ボタンを追加する まず、タップアクションと読み込みインジケータを持つ、ボタン付きのビューコントローラーを作成します。 ```swift import UIKit class VerifyViewController: UIViewController { @IBOutlet weak var verifyButton: UIButton! @IBOutlet weak var activityIndicator: UIActivityIndicatorView! } ``` ### StripeIdentity SDK をインポートする `StripeIdentity` をビューコントローラーに追加します。 ```swift import UIKitimport StripeIdentity class VerifyViewController: UIViewController { @IBOutlet weak var verifyButton: UIButton! @IBOutlet weak var activityIndicator: UIActivityIndicatorView! } ``` ### 確認ボタンにアクションを追加する `VerificationSession` を作成するためのボタンとエンドポイントが準備できたため、次にボタンを変更して、ボタンがタップされたら、書類のアップロード画面が表示されるようにします。 次のためのコールを追加します。 - エンドポイントから、`VerificationSession` ID と一時キーシークレットを取得します。 - ブランドロゴで `IdentityVerificationSheet` をインスタンス化し、ユーザーに提示します。 - `VerificationResult` で、顧客が本人確認フローを完了したかを把握できます。 ```swift import UIKit import StripeIdentity class VerifyViewController: UIViewController { @IBOutlet weak var verifyButton: UIButton! @IBOutlet weak var activityIndicator: UIActivityIndicatorView! override func viewDidLoad() { super.viewDidLoad() verifyButton.addTarget(self, action: #selector(didTapVerifyButton), for: .touchUpInside) } @objc func didTapVerifyButton() { // Disable the button while the request is made verifyButton.isEnabled = false activityIndicator.startAnimating() // Make request to your verification endpoint var urlRequest = URLRequest(url: URL(string: "https://{{YOUR_SERVER_BASE_URL}}/create-verification-session")!) urlRequest.httpMethod = "POST" let task = URLSession.shared.dataTask(with: urlRequest) { [weak self] data, response, error in DispatchQueue.main.async { [weak self] in // Re-enable button self?.verifyButton.isEnabled = true self?.activityIndicator.stopAnimating() guard error == nil, let data = data, let responseJson = try? JSONDecoder().decode([String: String].self, from: data), let verificationSessionId = responseJson["id"], let ephemeralKeySecret = responseJson["ephemeral_key_secret"] else { // Handle error print(error as Any) return } self?.presentVerificationSheet(verificationSessionId: verificationSessionId, ephemeralKeySecret: ephemeralKeySecret) } } task.resume() } func presentVerificationSheet(verificationSessionId: String, ephemeralKeySecret: String) { // Configure a square brand logo. Recommended image size is 32 x 32 points. let configuration = IdentityVerificationSheet.Configuration( brandLogo: UIImage(named: "{{YOUR_BRAND_LOGO}}")! ) // Instantiate and present the sheet let verificationSheet = IdentityVerificationSheet( verificationSessionId: verificationSessionId, ephemeralKeySecret: ephemeralKeySecret, configuration: configuration ) verificationSheet.present(from: self, completion: { result in switch result { case .flowCompleted: // The user has completed uploading their documents. // Let them know that the verification is processing. print("Verification Completed!") case .flowCanceled: // The user did not complete uploading their documents. // You should allow them to try again. print("Verification Canceled!") case .flowFailed(let error): // If the flow fails, you should display the localized error // message to your user using error.localizedDescription print("Verification Failed!") print(error.localizedDescription) } }) } } ``` ### 確認画面をテストする 確認ボタンで書類のアップロード画面が表示されるかどうかテストします。 - **本人確認**ボタンをタップします。 - エラーメッセージが表示されないことを確認します。 構築したシステムが機能しない場合: 1. `VerificationSession` ID と一時キーシークレットを取得する場所にブレークポイントを配置します。 1. ネットワークエラーがないこと、およびエンドポイントが `VerificationSession` ID と一時キーシークレットを返すことを確認します。 ## 確認イベントを処理する [書類確認](https://docs.stripe.com/identity/verification-checks.md#document-availability)は通常、ユーザーがサイトにリダイレクトするとすぐに完了し、API からすぐに結果を取得できます。まれに、ドキュメント検証の準備ができておらず、非同期的に続行する必要があります。このような場合、検証結果の準備ができたときに Webhook を通じて通知されます。処理が完了すると、VerificationSession のステータスが `processing` から `verified` に変わります。 セッションのステータスに変化があると、Stripe は以下のイベントを送信します。 | イベント名 | 説明 | 次のステップ | | ---------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | [identity.verification_session.verified](https://docs.stripe.com/api/events/types.md#event_types-identity.verification_session.verified) | すべての[本人確認チェック](https://docs.stripe.com/identity/verification-checks.md)の処理が完了し、確認のすべてが成功しました。 | アプリケーションで関連するアクションをトリガーします。 | | [identity.verification_session.requires_input](https://docs.stripe.com/api/events/types.md#event_types-identity.verification_session.requires_input) | すべての[本人確認チェック](https://docs.stripe.com/identity/verification-checks.md)の処理が完了し、少なくとも 1 つの確認が失敗しました。 | アプリケーションで関連するアクションをトリガーするとともに、ユーザーに本人確認の再試行を許可できます。 | [Webhook ハンドラ](https://docs.stripe.com/identity/handle-verification-outcomes.md)を使用してこれらのイベントを受信し、確定メールの送信、自社データベース内の確認結果の更新、アカウント登録ステップの完了などのアクションを自動化します。[ダッシュボードに確認イベント](https://dashboard.stripe.com/events?type=identity.%2A)を表示することもできます。 ## イベントを受信して、ビジネスアクションを実行する ### コード使用 Webhook ハンドラを構築してイベントをリッスンし、非同期型のカスタムの確認フローを作成します。Stripe CLI を使用して、ローカルで Webhook の組み込みのテストとデバッグを行います。 [カスタム Webhook を作成する](https://docs.stripe.com/identity/handle-verification-outcomes.md) ### コードなし ダッシュボードを使用してすべての本人確認を表示し、収集されたデータを調査して、確認の失敗について把握します。 [ダッシュボードでテストの確認を表示する](https://dashboard.stripe.com/test/identity/verification-sessions) > Identity Android SDK を利用するには、[Identity 設定](https://dashboard.stripe.com/settings/identity)ページにアクセスして、**有効にする**をクリックします。 Android でユーザーの本人確認を行うには、自社のアプリケーションに確認画面を表示します。このガイドでは、以下の手順を説明します。 1. Stripe を設定します。 1. サーバーエンドポイントを追加します。 1. 確認画面を表示します。 1. 確認イベントを処理します。 ## Before you begin 1. [本番環境利用の申請](https://dashboard.stripe.com/account/onboarding)を行う。 1. [Stripe Identity 申請書](https://dashboard.stripe.com/identity/application)にご記入ください。 このガイドの手順は、[サンプルアプリ](https://github.com/stripe/stripe-android/tree/master/identity-example) と [サンプルバックエンドサーバー](https://codesandbox.io/p/devbox/compassionate-violet-gshhgf) で完全に実装されています。 ## 設定 [サーバー側] [クライアント側] > この SDK を Stripe Identity サービスで使用する場合、この SDK を改変してはいけません。Stripe の書面による承認を得ずに、改変された SDK を Stripe Identity サービスで使用することは Stripe との契約に違反することになり、Stripe アカウントが閉鎖される場合があります。 ### SDK をインストールする (クライアント側) [Stripe Android SDK](https://github.com/stripe/stripe-android) はオープンソースであり、[詳細なドキュメントが提供されています](https://stripe.dev/stripe-android/)。 SDK をインストールするには、[app/build.gradle](https://developer.android.com/studio/build/dependencies) ファイルの `dependencies` ブロックに `identity` を追加します。 #### Kotlin ```kotlin plugins { id("com.android.application") } android { ... } dependencies { // ... // Stripe Identity Android SDK implementation("com.stripe:identity:23.2.0") } ``` > SDK の最新リリースおよび過去バージョンの詳細については、GitHub の [Releases](https://github.com/stripe/stripe-android/releases) ページをご覧ください。新しいリリースの公開時に通知を受け取るには、[リポジトリのリリースを確認](https://docs.github.com/en/github/managing-subscriptions-and-notifications-on-github/configuring-notifications#configuring-your-watch-settings-for-an-individual-repository)してください。 ### Google Play にある TFLite を利用してバイナリサイズを縮小する (クライアント側) Identity Android SDK は、ポータブルな TFLite ランタイムを使用して AI モデルを実行します。アプリケーションが Google Play を通じてリリースされている場合は、Google Play ランタイムを使用して SDK サイズを約 1.2 MB 削減できます。 #### Groovy ```groovy dependencies { // ... // Stripe Identity Android SDK implementation('com.stripe:identity:23.2.0') { exclude group: 'com.stripe', module: 'ml-core-default' // exclude the default TFLite runtime } implementation('com.stripe:ml-core-googleplay:23.2.0') // include the Google Play TFLite runtime } ``` ### マテリアルのテーマを設定する (クライアント側) Stripe Identity Android SDK には、[マテリアルのテーマ](https://material.io/develop/android/theming/dark)を使用するためのホスティングアクティビティーが必要です。マテリアルのテーマを有効にするには、以下のようにします。 1. プロジェクトの `app/src/main/AndroidManifest.xml` を開きます。 1. `application` に適用されている `android:theme` がいずれかのマテリアルのテーマ (例: `Theme.MaterialComponents.DayNight`) のいずれかを継承したものであることを確認してください。 ### サーバーに Stripe をインストールする (サーバー側) まず、Stripe アカウントを[登録](https://dashboard.stripe.com/register)します。 次に、アプリケーションから Stripe API へアクセスするためにライブラリをインストールします。 #### Ruby ```bash # Available as a gem sudo gem install stripe ``` ```ruby # If you use bundler, you can add this line to your Gemfile gem 'stripe' ``` ## サーバーエンドポイントを追加する [サーバー側] ### VerificationSession を作成する [VerificationSession](https://docs.stripe.com/api/identity/verification_sessions.md) は、本人確認をプログラムで示したものです。確認のタイプに関する詳細 (実行する[チェック](https://docs.stripe.com/identity/verification-checks.md)の内容など) が含まれています。[確認済みの出力](https://docs.stripe.com/api/identity/verification_sessions/object.md#identity_verification_session_object-verified_outputs)フィールドを[拡張](https://docs.stripe.com/api/expanding_objects.md)して、確認済みのデータの詳細を表示できます。 本人確認フローには、再利用可能な設定を使用できます。この設定は、[verification_flow](https://docs.stripe.com/api/identity/verification_sessions/create.md#create_identity_verification_session-verification_flow) パラメーターに渡されます。詳しくは、[本人確認フローガイド](https://docs.stripe.com/identity/verification-flows.md)をご確認ください。 [VerificationSession を作成](https://docs.stripe.com/api/identity/verification_sessions/create.md)するには、サーバー側のエンドポイントが必要です。サーバー側で `VerificationSession` を作成することにより、悪意のあるユーザーによる確認オプションの上書き、およびお客様のアカウントでの支払いの処理の偽装を防止できます。セッションのメタデータにユーザー参照を含めるか、データベースにセッション ID を保存することで、このエンドポイントに認証を追加します。 セキュリティ上の理由から、モバイルクライアントから直接アクセス可能な `VerificationSession` オブジェクトを作成しないでください。代わりに、サーバーが SDK に一時キーを提供します。このキーは、[VerificationSession](https://docs.stripe.com/api/identity/verification_sessions.md) への制限付きアクセス権が付与された一時的な API キーです。一時キーは、セッションとして考えることができ、そのセッションの間は SDK が特定の `VerificationSession` オブジェクトを取得して更新することが許可されます。 `VerificationSession` と一時キーを作成したら、その `VerificationSession` の [ID](https://docs.stripe.com/api/identity/verification_sessions/object.md#identity_verification_session_object-id) と一時キーシークレットをクライアントに送信し、書類のアップロード画面を表示します。 > このエンドポイントの実行中の実装を [こちら](https://codesandbox.io/p/devbox/compassionate-violet-gshhgf) で迅速なテスト用に見つけることができます。 #### Node.js ```javascript // Don't put any keys in code. See https://docs.stripe.com/keys-best-practices. // Find your keys at https://dashboard.stripe.com/apikeys. const stripe = require('stripe')('<>'); // In the route handler for /create-verification-session: // Authenticate your user. // Create the session. const verificationSession = await stripe.identity.verificationSessions.create({ type: 'document', provided_details: { email: 'user@example.com', }, metadata: { user_id: '{{USER_ID}}', }, }); // Create an ephemeral key for the VerificationSession const ephemeralKey = await stripe.ephemeralKeys.create( {verification_session: verificationSession.id}, {apiVersion: '2026-03-25.dahlia'} ); // Return only the ID and ephemeral key secret to the frontend. const verificationSessionId = verificationSession.id; const ephemeralKeySecret = ephemeralKey.secret; ``` > 一時キーシークレットは `VerificationSession` にバインドされており、これによりアプリは機密データである本人確認情報 (書類や顔写真のファイルなど) を収集できるようになります。使用できるのは 1 回限りで、1 時間後に有効期限が切れます。一時キーシークレットは、記録したり、URL に埋め込んだり、対象のユーザー以外に公開したりしないでください。一時キーシークレットを返すエンドポイントで必ず TLS を有効化します。本人確認の設定や結果の漏洩を防止するため、一時キーシークレットのみをアプリに送信してください。 Web サーバー (`localhost:4242` など) を起動し、curl で VerificationSession を作成する POST リクエストを送信して、エンドポイントをテストします。 ```bash curl -X POST -is "http://localhost:4242/create-verification-session" -d "" ``` 端末に次のようなレスポンスが表示されます。 ```bash HTTP/1.1 200 OK Content-Type: application/json { id: "vs_QdfQQ6xfGNJR7ogV6", ephemeral_key_secret: "ek_YWNjdF8xRm..." } ``` ## 確認画面を表示する [クライアント側] 確認画面を表示するボタンをセットアップします。このボタンをタップすると、ユーザーはパスポート、運転免許証、または国民 ID をキャプチャーしてアップロードできます。 開始する前に、確認ページで以下を行う必要があります。 - 本人確認が必要な理由をユーザーに説明します。 - Stripe の UI を表示する本人確認ボタンを含めます。 ### ボタンを追加する まず、タップアクションと読み込みインジケータを持つ、ボタン付きの `Activity` を作成します。`MyHostingActivity` が `AppCompatActivity` を継承し、`Theme.MaterialComponents` を継承したテーマを使用するようにします。 #### Kotlin ```kotlin class MyHostingActivity : AppCompatActivity() { // binding has a button and a loading indicator private val binding by lazy { MyHostingActivityBinding.inflate(layoutInflater) } } ``` ### Stripe Identity SDK をインポートする Identity SDK をアクティビティーにインポートし、`onCreate` メソッドでそれを初期化します (これにより、この `AppCompatActivity` または `Fragment` に [ActivityResultLauncher](https://developer.android.com/reference/androidx/activity/result/ActivityResultLauncher) が登録されます)。 #### Kotlin ```kotlin import com.stripe.android.identity.IdentityVerificationSheet class MyHostingActivity : AppCompatActivity() { // binding has a button and a loading indicator private val binding by lazy { MyHostingActivityBinding.inflate(layoutInflater) } lateinit var identityVerificationSheet: IdentityVerificationSheet override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(binding.root) identityVerificationSheet = IdentityVerificationSheet.create( this, IdentityVerificationSheet.Configuration( // Pass your square brand logo by creating it from local resource or // Uri.parse("https://path/to/your/brandlogo.jpg") brandLogo = logoUri ) ) { verificationResult -> when (verificationResult) { is Completed -> { // The user has completed uploading their documents. // Let them know that the verification is processing. ... Log.d(TAG, "Verification Completed!") } is Canceled -> { // The user did not complete uploading their documents. // You should allow them to try again. ... Log.d(TAG, "Verification Canceled!") } is Failed -> { // If the flow fails, you should display the localized error // message to your user using throwable.getLocalizedMessage() ... Log.d(TAG, "Verification Failed!") } } } } } ``` ### 確認ボタンにアクションを追加する `VerificationSession` を作成するためのボタンとエンドポイントが準備できたため、次にボタンを変更して、ボタンがタップされたら、書類のアップロード画面が表示されるようにします。 次のためのコールを追加します。 - エンドポイントから、`VerificationSession` ID と一時キーシークレットを取得します。 - ブランドロゴで `IdentityVerificationSheet` をインスタンス化し、ユーザーに提示します。 - `VerificationFlowResult` を処理し、ユーザーが確認フローを完了したかを知ることができるようにします。 #### Kotlin ```kotlin import com.stripe.android.identity.* class MyHostingActivity : AppCompatActivity() { // binding has a button and a loading indicator private val binding by lazy { MyHostingActivityBinding.inflate(layoutInflater) } lateinit var identityVerificationSheet: IdentityVerificationSheet override fun onCreate(savedInstanceState: Bundle?) { ...binding.button.setOnClickListener(::onButtonClick) } fun onButtonClick() { // show loading UI // Request the session ID with Fuel or other network libraries Fuel.post("https://{{YOUR_SERVER_BASE_URL}}/create-verification-session") .responseString { _, _, result -> when (result) { is Result.Failure -> { // show error UI } is Result.Success -> { val responseJson = JSONObject(result.value) try { // start verification session identityVerificationSheet.present( verificationSessionId = responseJson.getString("id"), ephemeralKeySecret = responseJson.getString("ephemeral_key_secret") ) } catch (t: Throwable) { // show error UI } } } } } } ``` ### 確認画面をテストする 確認ボタンで書類のアップロード画面が表示されるかどうかテストします。 - **本人確認**ボタンをタップします。 - エラーメッセージが表示されないことを確認します。 構築したシステムが機能しない場合: 1. `VerificationSession` ID と一時キーシークレットを取得する場所にブレークポイントを配置します。 1. ネットワークエラーがないこと、およびエンドポイントが `VerificationSession` ID と一時キーシークレットを返すことを確認します。 ## 確認イベントを処理する [書類確認](https://docs.stripe.com/identity/verification-checks.md#document-availability)は通常、ユーザーがサイトにリダイレクトするとすぐに完了し、API からすぐに結果を取得できます。まれに、ドキュメント検証の準備ができておらず、非同期的に続行する必要があります。このような場合、検証結果の準備ができたときに Webhook を通じて通知されます。処理が完了すると、VerificationSession のステータスが `processing` から `verified` に変わります。 セッションのステータスに変化があると、Stripe は以下のイベントを送信します。 | イベント名 | 説明 | 次のステップ | | ---------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | [identity.verification_session.verified](https://docs.stripe.com/api/events/types.md#event_types-identity.verification_session.verified) | すべての[本人確認チェック](https://docs.stripe.com/identity/verification-checks.md)の処理が完了し、確認のすべてが成功しました。 | アプリケーションで関連するアクションをトリガーします。 | | [identity.verification_session.requires_input](https://docs.stripe.com/api/events/types.md#event_types-identity.verification_session.requires_input) | すべての[本人確認チェック](https://docs.stripe.com/identity/verification-checks.md)の処理が完了し、少なくとも 1 つの確認が失敗しました。 | アプリケーションで関連するアクションをトリガーするとともに、ユーザーに本人確認の再試行を許可できます。 | [Webhook ハンドラ](https://docs.stripe.com/identity/handle-verification-outcomes.md)を使用してこれらのイベントを受信し、確定メールの送信、自社データベース内の確認結果の更新、アカウント登録ステップの完了などのアクションを自動化します。[ダッシュボードに確認イベント](https://dashboard.stripe.com/events?type=identity.%2A)を表示することもできます。 ## イベントを受信して、ビジネスアクションを実行する ### コード使用 Webhook ハンドラを構築してイベントをリッスンし、非同期型のカスタムの確認フローを作成します。Stripe CLI を使用して、ローカルで Webhook の組み込みのテストとデバッグを行います。 [カスタム Webhook を作成する](https://docs.stripe.com/identity/handle-verification-outcomes.md) ### コードなし ダッシュボードを使用してすべての本人確認を表示し、収集されたデータを調査して、確認の失敗について把握します。 [ダッシュボードでテストの確認を表示する](https://dashboard.stripe.com/test/identity/verification-sessions) > Identity Android SDK を利用するには、[Identity 設定](https://dashboard.stripe.com/settings/identity)ページにアクセスして、**有効にする**をクリックします。 このガイドでは、Stripe Identity のシステムを[ウェブ版の Redirect](https://docs.stripe.com/identity/verify-identity-documents.md?platform=web&type=redirect) からモバイルアプリのネイティブの Android SDK に移行する方法を説明します。このガイドでは、以下の手順を説明します。 1. Stripe を設定します。 1. サーバーエンドポイントを更新します。 1. 確認画面を表示します。 1. 確認イベントを処理します。 ## Before you begin 1. [本番環境利用の申請](https://dashboard.stripe.com/account/onboarding)を行う。 1. [Stripe Identity 申請書](https://dashboard.stripe.com/identity/application)にご記入ください。 このガイドの手順は、[サンプルアプリ](https://github.com/stripe/stripe-android/tree/master/identity-example) と [サンプルバックエンドサーバー](https://codesandbox.io/p/devbox/compassionate-violet-gshhgf) で完全に実装されています。 ## 設定 [サーバー側] [クライアント側] > この SDK を Stripe Identity サービスで使用する場合、この SDK を改変してはいけません。Stripe の書面による承認を得ずに、改変された SDK を Stripe Identity サービスで使用することは Stripe との契約に違反することになり、Stripe アカウントが閉鎖される場合があります。 ### SDK をインストールする (クライアント側) [Stripe Android SDK](https://github.com/stripe/stripe-android) はオープンソースであり、[詳細なドキュメントが提供されています](https://stripe.dev/stripe-android/)。 SDK をインストールするには、[app/build.gradle](https://developer.android.com/studio/build/dependencies) ファイルの `dependencies` ブロックに `identity` を追加します。 #### Kotlin ```kotlin plugins { id("com.android.application") } android { ... } dependencies { // ... // Stripe Identity Android SDK implementation("com.stripe:identity:23.2.0") } ``` > SDK の最新リリースおよび過去バージョンの詳細については、GitHub の [Releases](https://github.com/stripe/stripe-android/releases) ページをご覧ください。新しいリリースの公開時に通知を受け取るには、[リポジトリのリリースを確認](https://docs.github.com/en/github/managing-subscriptions-and-notifications-on-github/configuring-notifications#configuring-your-watch-settings-for-an-individual-repository)してください。 ### Google Play にある TFLite を利用してバイナリサイズを縮小する (クライアント側) Identity Android SDK は、ポータブルな TFLite ランタイムを使用して AI モデルを実行します。アプリケーションが Google Play を通じてリリースされている場合は、Google Play ランタイムを使用して SDK サイズを約 1.2 MB 削減できます。 #### Groovy ```groovy dependencies { // ... // Stripe Identity Android SDK implementation('com.stripe:identity:23.2.0') { exclude group: 'com.stripe', module: 'ml-core-default' // exclude the default TFLite runtime } implementation('com.stripe:ml-core-googleplay:23.2.0') // include the Google Play TFLite runtime } ``` ### マテリアルのテーマを設定する (クライアント側) Stripe Identity Android SDK には、[マテリアルのテーマ](https://material.io/develop/android/theming/dark)を使用するためのホスティングアクティビティーが必要です。マテリアルのテーマを有効にするには、以下のようにします。 1. プロジェクトの `app/src/main/AndroidManifest.xml` を開きます。 1. `application` に適用されている `android:theme` がいずれかのマテリアルのテーマ (例: `Theme.MaterialComponents.DayNight`) のいずれかを継承したものであることを確認してください。 ### サーバーに Stripe をインストールする (サーバー側) まず、Stripe アカウントを[登録](https://dashboard.stripe.com/register)します。 次に、アプリケーションから Stripe API へアクセスするためにライブラリをインストールします。 #### Ruby ```bash # Available as a gem sudo gem install stripe ``` ```ruby # If you use bundler, you can add this line to your Gemfile gem 'stripe' ``` ## サーバーエンドポイントを更新する [サーバー側] ### 既存のウェブ版の実装 [モーダル](https://docs.stripe.com/identity/verify-identity-documents.md?platform=web&type=modal) の実装を使用していた場合は、[VerificationSession](https://docs.stripe.com/api/identity/verification_sessions.md) が作成され、`VerificationSession` [client_secret](https://docs.stripe.com/api/identity/verification_sessions/object.md#identity_verification_session_object-client_secret) が Stripe API オブジェクトに渡されています。 #### Node.js ```javascript // Don't put any keys in code. See https://docs.stripe.com/keys-best-practices. // Find your keys at https://dashboard.stripe.com/apikeys. const stripe = require('stripe')('<>'); // In the route handler for /create-verification-session: // Authenticate your user. // Create the session. const verificationSession = await stripe.identity.verificationSessions.create({ type: 'document', provided_details: { email: 'user@example.com', }, metadata: { user_id: '{{USER_ID}}', }, }); // Return only the client secret to the frontend. const clientSecret = verificationSession.client_secret; ``` [リダイレクト](https://docs.stripe.com/identity/verify-identity-documents.md?platform=web&type=redirect) の実装を使用していた場合は、[VerificationSession](https://docs.stripe.com/api/identity/verification_sessions.md) が作成され、`VerificationSession` [url](https://docs.stripe.com/api/identity/verification_sessions/object.md#identity_verification_session_object-url) がクライアントのモバイルアプリに送信され、アプリ内のブラウザーに表示されています。 #### Node.js ```javascript // Don't put any keys in code. See https://docs.stripe.com/keys-best-practices. // Find your keys at https://dashboard.stripe.com/apikeys. const stripe = require('stripe')('<>'); // In the route handler for /create-verification-session: // Authenticate your user. // Create the session. const verificationSession = await stripe.identity.verificationSessions.create({ type: 'document', provided_details: { email: 'user@example.com', }, metadata: { user_id: '{{USER_ID}}', }, }); // Return only the session URL to the frontend. const url = verificationSession.url; ``` ### SDK の実装に移行する ネイティブ SDK を使用するには、同じ [VerificationSession](https://docs.stripe.com/api/identity/verification_sessions.md) を作成して、一時キーシークレットを作成します。 #### Node.js ```javascript // Don't put any keys in code. See https://docs.stripe.com/keys-best-practices. // Find your keys at https://dashboard.stripe.com/apikeys. const stripe = require('stripe')('<>'); // In the route handler for /create-verification-session: // Authenticate your user. // Create the session. const verificationSession = await stripe.identity.verificationSessions.create({ type: 'document', provided_details: { email: 'user@example.com', }, metadata: { user_id: '{{USER_ID}}', }, }); // Create an ephemeral key for the VerificationSession const ephemeralKey = await stripe.ephemeralKeys.create( {verification_session: verificationSession.id}, {apiVersion: '2026-03-25.dahlia'} ); // Return only the ID and ephemeral key secret to the frontend. const verificationSessionId = verificationSession.id; const ephemeralKeySecret = ephemeralKey.secret; ``` `VerificationSession` と一時キーを作成したら、その `VerificationSession` [ID](https://docs.stripe.com/api/identity/verification_sessions/object.md#identity_verification_session_object-id) と `ephemeral key secret` をクライアントのモバイルアプリに送信します。 > このエンドポイントの実行中の実装を [こちら](https://codesandbox.io/p/devbox/compassionate-violet-gshhgf) で迅速なテスト用に見つけることができます。 > 一時キーシークレットを使用することで、アプリは機密データである本人確認情報を収集できるようになります。使用できるのは 1 回限りで、1 時間後に有効期限が切れます。一時キーシークレットは、記録したり、URL に埋め込んだり、対象のユーザー以外に公開したりしないでください。一時キーシークレットを返すエンドポイントで必ず TLS を有効化します。本人確認の設定や結果の漏洩を防止するため、一時キーシークレットのみをアプリに送信してください。 ## 確認画面を表示する [クライアント側] 確認画面を表示するボタンをセットアップします。このボタンをタップすると、ユーザーはパスポート、運転免許証、または国民 ID をキャプチャーしてアップロードできます。 開始する前に、確認ページで以下を行う必要があります。 - 本人確認が必要な理由をユーザーに説明します。 - Stripe の UI を表示する本人確認ボタンを含めます。 ### ボタンを追加する まず、タップアクションと読み込みインジケータを持つ、ボタン付きの `Activity` を作成します。`MyHostingActivity` が `AppCompatActivity` を継承し、`Theme.MaterialComponents` を継承したテーマを使用するようにします。 #### Kotlin ```kotlin class MyHostingActivity : AppCompatActivity() { // binding has a button and a loading indicator private val binding by lazy { MyHostingActivityBinding.inflate(layoutInflater) } } ``` ### Stripe Identity SDK をインポートする Identity SDK をアクティビティーにインポートし、`onCreate` メソッドでそれを初期化します (これにより、この `AppCompatActivity` または `Fragment` に [ActivityResultLauncher](https://developer.android.com/reference/androidx/activity/result/ActivityResultLauncher) が登録されます)。 #### Kotlin ```kotlin import com.stripe.android.identity.IdentityVerificationSheet class MyHostingActivity : AppCompatActivity() { // binding has a button and a loading indicator private val binding by lazy { MyHostingActivityBinding.inflate(layoutInflater) } lateinit var identityVerificationSheet: IdentityVerificationSheet override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(binding.root) identityVerificationSheet = IdentityVerificationSheet.create( this, IdentityVerificationSheet.Configuration( // Pass your square brand logo by creating it from local resource or // Uri.parse("https://path/to/your/brandlogo.jpg") brandLogo = logoUri ) ) { verificationResult -> when (verificationResult) { is Completed -> { // The user has completed uploading their documents. // Let them know that the verification is processing. ... Log.d(TAG, "Verification Completed!") } is Canceled -> { // The user did not complete uploading their documents. // You should allow them to try again. ... Log.d(TAG, "Verification Canceled!") } is Failed -> { // If the flow fails, you should display the localized error // message to your user using throwable.getLocalizedMessage() ... Log.d(TAG, "Verification Failed!") } } } } } ``` ### 確認ボタンにアクションを追加する `VerificationSession` を作成するためのボタンとエンドポイントが準備できたため、次にボタンを変更して、ボタンがタップされたら、書類のアップロード画面が表示されるようにします。 次のためのコールを追加します。 - エンドポイントから、`VerificationSession` ID と一時キーシークレットを取得します。 - ブランドロゴで `IdentityVerificationSheet` をインスタンス化し、ユーザーに提示します。 - `VerificationFlowResult` を処理し、ユーザーが確認フローを完了したかを知ることができるようにします。 #### Kotlin ```kotlin import com.stripe.android.identity.* class MyHostingActivity : AppCompatActivity() { // binding has a button and a loading indicator private val binding by lazy { MyHostingActivityBinding.inflate(layoutInflater) } lateinit var identityVerificationSheet: IdentityVerificationSheet override fun onCreate(savedInstanceState: Bundle?) { ...binding.button.setOnClickListener(::onButtonClick) } fun onButtonClick() { // show loading UI // Request the session ID with Fuel or other network libraries Fuel.post("https://{{YOUR_SERVER_BASE_URL}}/create-verification-session") .responseString { _, _, result -> when (result) { is Result.Failure -> { // show error UI } is Result.Success -> { val responseJson = JSONObject(result.value) try { // start verification session identityVerificationSheet.present( verificationSessionId = responseJson.getString("id"), ephemeralKeySecret = responseJson.getString("ephemeral_key_secret") ) } catch (t: Throwable) { // show error UI } } } } } } ``` ### 確認画面をテストする 確認ボタンで書類のアップロード画面が表示されるかどうかテストします。 - **本人確認**ボタンをタップします。 - エラーメッセージが表示されないことを確認します。 構築したシステムが機能しない場合: 1. `VerificationSession` ID と一時キーシークレットを取得する場所にブレークポイントを配置します。 1. ネットワークエラーがないこと、およびエンドポイントが `VerificationSession` ID と一時キーシークレットを返すことを確認します。 ## 確認イベントを処理する [書類確認](https://docs.stripe.com/identity/verification-checks.md#document-availability)は通常、ユーザーがサイトにリダイレクトするとすぐに完了し、API からすぐに結果を取得できます。まれに、ドキュメント検証の準備ができておらず、非同期的に続行する必要があります。このような場合、検証結果の準備ができたときに Webhook を通じて通知されます。処理が完了すると、VerificationSession のステータスが `processing` から `verified` に変わります。 セッションのステータスに変化があると、Stripe は以下のイベントを送信します。 | イベント名 | 説明 | 次のステップ | | ---------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------- | | [identity.verification_session.verified](https://docs.stripe.com/api/events/types.md#event_types-identity.verification_session.verified) | すべての[本人確認チェック](https://docs.stripe.com/identity/verification-checks.md)の処理が完了し、確認のすべてが成功しました。 | アプリケーションで関連するアクションをトリガーします。 | | [identity.verification_session.requires_input](https://docs.stripe.com/api/events/types.md#event_types-identity.verification_session.requires_input) | すべての[本人確認チェック](https://docs.stripe.com/identity/verification-checks.md)の処理が完了し、少なくとも 1 つの確認が失敗しました。 | アプリケーションで関連するアクションをトリガーするとともに、ユーザーに本人確認の再試行を許可できます。 | [Webhook ハンドラ](https://docs.stripe.com/identity/handle-verification-outcomes.md)を使用してこれらのイベントを受信し、確定メールの送信、自社データベース内の確認結果の更新、アカウント登録ステップの完了などのアクションを自動化します。[ダッシュボードに確認イベント](https://dashboard.stripe.com/events?type=identity.%2A)を表示することもできます。 ## イベントを受信して、ビジネスアクションを実行する ### コード使用 Webhook ハンドラを構築してイベントをリッスンし、非同期型のカスタムの確認フローを作成します。Stripe CLI を使用して、ローカルで Webhook の組み込みのテストとデバッグを行います。 [カスタム Webhook を作成する](https://docs.stripe.com/identity/handle-verification-outcomes.md) ### コードなし ダッシュボードを使用してすべての本人確認を表示し、収集されたデータを調査して、確認の失敗について把握します。 [ダッシュボードでテストの確認を表示する](https://dashboard.stripe.com/test/identity/verification-sessions) > Identity React Native SDK を利用するには、[Identity 設定](https://dashboard.stripe.com/settings/identity)ページにアクセスして、**有効にする**をクリックします。 React Native でユーザーの本人確認を行うには、自社のアプリケーションに確認画面を表示します。このガイドでは、以下の手順を説明します。 1. Stripe を設定します。 1. サーバーエンドポイントを追加します。 1. 確認画面を表示します。 1. 確認イベントを処理します。 ## Before you begin 1. [本番環境利用の申請](https://dashboard.stripe.com/account/onboarding)を行う。 1. [Stripe Identity 申請書](https://dashboard.stripe.com/identity/application)にご記入ください。 このガイドの手順は、[サンプルアプリ](https://github.com/stripe/stripe-identity-react-native/tree/main/example) と [サンプルバックエンドサーバー](https://codesandbox.io/p/devbox/compassionate-violet-gshhgf) で完全に実装されています。 ## 設定 [サーバー側] [クライアント側] ### SDK をインストールする (クライアント側) [React Native SDK](https://github.com/stripe/stripe-identity-react-native) はオープンソースです。[詳細なドキュメントが提供されており](https://stripe.dev/stripe-identity-react-native)、iOS 13.0 または Android 5.0 (API レベル 21) 以降をサポートするアプリと互換性を持ちます。内部的には、ネイティブの [iOS](https://github.com/stripe/stripe-ios/tree/master/StripeIdentity) および [Android](https://github.com/stripe/stripe-android/tree/master/identity) SDK を使用します。 SDK をインストールするには、以下を実行します。 #### Yarn ```bash yarn add @stripe/stripe-identity-react-native ``` > 最新の SDK リリースと過去のバージョンの詳細については、GitHub の[リリース](https://github.com/stripe/stripe-identity-react-native/releases) ページをご覧ください。新しいリリースの公開時に通知を受け取るには、[リポジトリーのリリースを確認してください](https://help.github.com/en/articles/watching-and-unwatching-releases-for-a-repository#watching-releases-for-a-repository)。 iOS の場合は、`ios` ディレクトリーの `pod install` を実行して、必要なネイティブ依存関係もインストールします。Android では必要な追加手順はありません。 ### iOS のカメラの使用許可を設定する (クライアント側) Stripe Identity iOS SDK では、デバイスのカメラにアクセスして本人確認書類をキャプチャーする必要があります。アプリがカメラの使用許可をリクエストできるようにするには、以下の手順に従います。 1. Xcode で、プロジェクトの **Info.plist** を開きます。 1. `NSCameraUsageDescription` キーを追加します。 1. アプリにカメラへのアクセスの許可が必要な理由をユーザーに説明する文字列値を追加します。 > このアプリは、カメラを使用して本人確認書類の写真を撮影します。 カメラ認証のリクエストについて、詳細は [Apple のドキュメント](https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/requesting_authorization_for_media_capture_on_ios)を参照してください。 ### Android のマテリアルのテーマを設定する (クライアント側) Stripe Identity Android SDK には、[マテリアルのテーマ](https://material.io/develop/android/theming/dark)を使用するためのホスティングアクティビティーが必要です。マテリアルのテーマを有効にするには、以下のようにします。 1. プロジェクトの `app/src/main/AndroidManifest.xml` を開きます。 1. `application` に適用されている `android:theme` がいずれかのマテリアルのテーマ (例: `Theme.MaterialComponents.DayNight`) のいずれかを継承したものであることを確認してください。 ### サーバーに Stripe をインストールする (サーバー側) まず、Stripe アカウントを[登録](https://dashboard.stripe.com/register)します。 次に、アプリケーションから Stripe API へアクセスするためにライブラリをインストールします。 #### Ruby ```bash # Available as a gem sudo gem install stripe ``` ```ruby # If you use bundler, you can add this line to your Gemfile gem 'stripe' ``` ## サーバーエンドポイントを追加する [サーバー側] ### VerificationSession を作成する [VerificationSession](https://docs.stripe.com/api/identity/verification_sessions.md) は、本人確認をプログラムで示したものです。確認のタイプに関する詳細 (実行する[チェック](https://docs.stripe.com/identity/verification-checks.md)の内容など) が含まれています。[確認済みの出力](https://docs.stripe.com/api/identity/verification_sessions/object.md#identity_verification_session_object-verified_outputs)フィールドを[拡張](https://docs.stripe.com/api/expanding_objects.md)して、確認済みのデータの詳細を表示できます。 本人確認フローには、再利用可能な設定を使用できます。この設定は、[verification_flow](https://docs.stripe.com/api/identity/verification_sessions/create.md#create_identity_verification_session-verification_flow) パラメーターに渡されます。詳しくは、[本人確認フローガイド](https://docs.stripe.com/identity/verification-flows.md)をご確認ください。 [VerificationSession を作成](https://docs.stripe.com/api/identity/verification_sessions/create.md)するには、サーバー側のエンドポイントが必要です。サーバー側で `VerificationSession` を作成することにより、悪意のあるユーザーによる確認オプションの上書き、およびお客様のアカウントでの支払いの処理の偽装を防止できます。セッションのメタデータにユーザー参照を含めるか、データベースにセッション ID を保存することで、このエンドポイントに認証を追加します。 セキュリティ上の理由から、モバイルクライアントから直接アクセス可能な `VerificationSession` オブジェクトを作成しないでください。代わりに、サーバーが SDK に一時キーを提供します。このキーは、[VerificationSession](https://docs.stripe.com/api/identity/verification_sessions.md) への制限付きアクセス権が付与された一時的な API キーです。一時キーは、セッションとして考えることができ、そのセッションの間は SDK が特定の `VerificationSession` オブジェクトを取得して更新することが許可されます。 `VerificationSession` と一時キーを作成したら、その `VerificationSession` の [ID](https://docs.stripe.com/api/identity/verification_sessions/object.md#identity_verification_session_object-id) と一時キーシークレットをクライアントに送信し、書類のアップロード画面を表示します。 > このエンドポイントの実行中の実装を [こちら](https://codesandbox.io/p/devbox/compassionate-violet-gshhgf) で迅速なテスト用に見つけることができます。 #### Node.js ```javascript // Don't put any keys in code. See https://docs.stripe.com/keys-best-practices. // Find your keys at https://dashboard.stripe.com/apikeys. const stripe = require('stripe')('<>'); // In the route handler for /create-verification-session: // Authenticate your user. // Create the session. const verificationSession = await stripe.identity.verificationSessions.create({ type: 'document', provided_details: { email: 'user@example.com', }, metadata: { user_id: '{{USER_ID}}', }, }); // Create an ephemeral key for the VerificationSession const ephemeralKey = await stripe.ephemeralKeys.create( {verification_session: verificationSession.id}, {apiVersion: '2026-03-25.dahlia'} ); // Return only the ID and ephemeral key secret to the frontend. const verificationSessionId = verificationSession.id; const ephemeralKeySecret = ephemeralKey.secret; ``` > 一時キーシークレットは `VerificationSession` にバインドされており、これによりアプリは機密データである本人確認情報 (書類や顔写真のファイルなど) を収集できるようになります。使用できるのは 1 回限りで、1 時間後に有効期限が切れます。一時キーシークレットは、記録したり、URL に埋め込んだり、対象のユーザー以外に公開したりしないでください。一時キーシークレットを返すエンドポイントで必ず TLS を有効化します。本人確認の設定や結果の漏洩を防止するため、一時キーシークレットのみをアプリに送信してください。 Web サーバー (`localhost:4242` など) を起動し、curl で VerificationSession を作成する POST リクエストを送信して、エンドポイントをテストします。 ```bash curl -X POST -is "http://localhost:4242/create-verification-session" -d "" ``` 端末に次のようなレスポンスが表示されます。 ```bash HTTP/1.1 200 OK Content-Type: application/json { id: "vs_QdfQQ6xfGNJR7ogV6", ephemeral_key_secret: "ek_YWNjdF8xRm..." } ``` ## 確認画面を表示する [クライアント側] 確認画面を表示するボタンをセットアップします。このボタンをタップすると、ユーザーはパスポート、運転免許証、または国民 ID をキャプチャーしてアップロードできます。 開始する前に、確認ページで以下を行う必要があります。 - 本人確認が必要な理由をユーザーに説明します。 - Stripe の UI を表示する本人確認ボタンを含めます。 ### ボタンを追加する Button (ボタン) コンポーネントの作成から始めます。 ```javascript import React from 'react'; import { View, Button, } from 'react-native'; function VerifyScreen() { return (