コンテンツにスキップ
アカウントを作成
または
サインイン
Stripe ドキュメントのロゴ
/
AI に質問する
アカウントを作成
サインイン
始める
支払い
財務の自動化
プラットフォームおよびマーケットプレイス
資金管理
開発者向けのツール
始める
支払い
財務の自動化
始める
支払い
財務の自動化
プラットフォームおよびマーケットプレイス
資金管理
概要すべての商品を確認する
構築を開始する
開発の開始
サンプルプロジェクト
API について
Build with LLMs
ノーコードで Stripe を使用する
Stripe を設定する
アカウントを作成する
ウェブダッシュボード
モバイルダッシュボード
Stripe に移行
不正利用のリスク管理
不正利用について
Radar の不正防止
不審請求の申請の管理
本人確認
    概要
    始める
    本人確認書類を確認
    確認結果を処理
    確認結果へのアクセス
    確認結果を表示
    確認フロー
    その他の本人確認チェック
    検証チェック
    顔写真チェックを追加する
    API について
    確認セッション
    本番環境へ移行
    本番環境への移行前
    サポートするユースケース
    Identity に関する説明
ホーム始めるVerify identities

注

このページはまだ日本語ではご利用いただけません。より多くの言語で文書が閲覧できるように現在取り組んでいます。準備が整い次第、翻訳版を提供いたしますので、もう少しお待ちください。

本人確認の結果を処理する

確認結果をリッスンし、構築済みの自社システムで自動的に対応をトリガできるようにします。

ページをコピー

本人確認書類を収集するモーダルを表示するコードを記述しました。次に、ユーザーが書類を送信したときに、確認結果をリッスンし、その対応をアプリケーションでトリガーできます。

このガイドでは、以下の方法について説明します。

  1. 本人確認の処理が終了したら、イベント通知を受け取る。
  2. 確認チェックの成功と失敗を処理する。
  3. 本番環境でイベントハンドラを有効にする。

本人確認チェックは非同期で行われるため、確認結果がすぐに出力されるわけではありません。処理が完了すると、VerificationSession ステータスが更新され、確認された情報の使用が可能になります。Stripe はセッションでステータスが変化するたびに、イベントを生成します。このガイドでは、Webhook を実装して、確認結果が使用可能になったときにアプリに通知します。

確認セッションのステータスとライフサイクルについは、セッションの仕組みをご覧ください。

Stripe を設定する
サーバー側

アプリケーションから Stripe API にアクセスするには、Stripe の公式ライブラリをインストールします。

Command Line
Ruby
# Available as a gem sudo gem install stripe
Gemfile
Ruby
# If you use bundler, you can add this line to your Gemfile gem 'stripe'

Webhook を作成して、VerificationSession イベントを処理する
サーバー側

Webhook エンドポイント作成の詳細な手順については、Webhook エンドポイントを構築するガイドをご覧ください。

A webhook is an endpoint on your server that receives requests from Stripe, notifying you about events that happen on your account. In this step, we’ll build an endpoint to receive events on VerificationSession status changes.

Stripe が未認証のリクエストを送信できるようにするため、Webhook エンドポイントはパブリックアクセスが可能なものである必要があります。Stripe ライブラリとリクエストヘッダーを使用し、イベントを送信したのが Stripe であることを確認する必要があります。

server.js
Node
// Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys const stripe = require('stripe')(
'sk_test_BQokikJOvBiI2HlWgH4olfQ2'
); // You can find your endpoint's secret in your webhook settings const endpointSecret = 'whsec_...'; // This example uses Express to receive webhooks const express = require('express'); // Use body-parser to retrieve the raw body as a buffer const bodyParser = require('body-parser'); const app = express(); // Use JSON parser for all non-webhook routes app.use((req, res, next) => { if (req.originalUrl === '/webhook') { next(); } else { bodyParser.json()(req, res, next); } }); app.post('/webhook', bodyParser.raw({type: 'application/json'}), (req, res) => { let event; // Verify the event came from Stripe try { const sig = req.headers['stripe-signature']; event = stripe.webhooks.constructEvent(req.body, sig, endpointSecret); } catch (err) { // On error, log and return the error message console.log(`❌ Error message: ${err.message}`); return res.status(400).send(`Webhook Error: ${err.message}`); } // Successfully constructed event res.json({received: true}); }); app.listen(4242, () => { console.log('Running on port 4242'); });

これで、Stripe からの通知をリッスンする基本的な構造とセキュリティが準備できています。次は、Webhook エンドポイントを更新して確認セッションイベントを処理します。

すべてのセッションイベントに、VerificationSession (確認セッション) オブジェクトが含まれます。これには、実行された本人確認チェックに関する詳細が含まれます。セッションイベントに含まれない確認済みの情報を取得する方法については、本人確認結果へのアクセスをご覧ください。

セッションのステータスに変化があると、Stripe は以下のイベントを送信します。

イベント名説明次のステップ
identity.verification_session.verifiedすべての本人確認チェックの処理が完了し、確認のすべてが成功しました。アプリケーションで対応するアクションをトリガします。
identity.verification_session.requires_inputすべての本人確認チェックの処理が完了し、少なくとも 1 つの確認が失敗しました。アプリケーションで関連するアクションをトリガーするとともに、ユーザーに本人確認の再試行を許可できます。

Webhook コードでは identity.verification_session.verified イベントおよび identity.verification_session.requires_input イベントを処理する必要があります。他のセッションイベントに登録して、アプリで追加の対応をトリガーすることもできます。

Handle VerificationSession verified status change

本人確認チェックが完了し、すべての確認が成功すると、identity.verification_session.verified イベントが送信されます。

イベントハンドラにコードを追加して、すべての確認チェック成功を処理します。

server.js
Node
// Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys const stripe = require('stripe')(
'sk_test_BQokikJOvBiI2HlWgH4olfQ2'
); // You can find your endpoint's secret in your webhook settings const endpointSecret = 'whsec_...'; // This example uses Express to receive webhooks const express = require('express'); // Use body-parser to retrieve the raw body as a buffer const bodyParser = require('body-parser'); const app = express(); // Use JSON parser for all non-webhook routes app.use((req, res, next) => { if (req.originalUrl === '/webhook') { next(); } else { bodyParser.json()(req, res, next); } }); app.post('/webhook', bodyParser.raw({type: 'application/json'}), (req, res) => { let event; // Verify the event came from Stripe try { const sig = req.headers['stripe-signature']; event = stripe.webhooks.constructEvent(req.body, sig, endpointSecret); } catch (err) { // On error, log and return the error message console.log(`❌ Error message: ${err.message}`); return res.status(400).send(`Webhook Error: ${err.message}`); } // Successfully constructed event switch (event.type) { case 'identity.verification_session.verified': { // All the verification checks passed const verificationSession = event.data.object; break; } } res.json({received: true}); }); app.listen(4242, () => { console.log('Running on port 4242'); });

このイベントを処理する際には、次のことも考慮してください。

  • 確認ステータスを独自のデータベースに保存する
  • 本人確認されたことをユーザーに知らせるメールを送信する
  • VerificationSession の確認された出力を拡張し、予測される値と比較します。

Handle VerificationSession requires_input status changes

1 つ以上のチェックが失敗した場合、identity.verification_session.requires_input イベントが送信されます。確認セッションの last_error ハッシュを調べて、特定の失敗の原因を確認して対処できます。

  • The last_error.code field can be used to programmatically handle verification failures.
  • The last_error.reason field contains a descriptive message explaining the failure reason and can be shown to your user.

イベントエラーコード

エラーコード説明
consent_declinedユーザーが Stripe による確認を拒否しました。法律顧問に問い合わせて、手動審査など、生体認証以外の本人確認方法を提供する義務があるかどうかご確認ください。
under_supported_ageStripe は未成年のユーザーの本人確認を行いません。
country_not_supportedStripe は、ご指定の国のユーザーの本人確認を行いません。

イベントハンドラにコードを追加して、確認チェック失敗を処理します。

server.js
Node
// Set your secret key. Remember to switch to your live secret key in production. // See your keys here: https://dashboard.stripe.com/apikeys const stripe = require('stripe')(
'sk_test_BQokikJOvBiI2HlWgH4olfQ2'
); // You can find your endpoint's secret in your webhook settings const endpointSecret = 'whsec_...'; // This example uses Express to receive webhooks const express = require('express'); // Use body-parser to retrieve the raw body as a buffer const bodyParser = require('body-parser'); const app = express(); // Use JSON parser for all non-webhook routes app.use((req, res, next) => { if (req.originalUrl === '/webhook') { next(); } else { bodyParser.json()(req, res, next); } }); app.post('/webhook', bodyParser.raw({type: 'application/json'}), (req, res) => { let event; // Verify the event came from Stripe try { const sig = req.headers['stripe-signature']; event = stripe.webhooks.constructEvent(req.body, sig, endpointSecret); } catch (err) { // On error, log and return the error message console.log(`❌ Error message: ${err.message}`); return res.status(400).send(`Webhook Error: ${err.message}`); } // Successfully constructed event switch (event.type) { case 'identity.verification_session.verified': { // All the verification checks passed const verificationSession = event.data.object; break; } case 'identity.verification_session.requires_input': { // At least one of the verification checks failed const verificationSession = event.data.object; console.log('Verification check failed: ' + verificationSession.last_error.reason); // Handle specific failure reasons switch (verificationSession.last_error.code) { case 'document_unverified_other': { // The document was invalid break; } case 'document_expired': { // The document was expired break; } case 'document_type_not_supported': { // document type not supported break; } default: { // ... } } } } res.json({received: true}); }); app.listen(4242, () => { console.log('Running on port 4242'); });

ユースケースによっては、本人確認に失敗した場合に、確認の再試行をユーザーに許可することが必要になります。その場合、送信試行回数を制限することをお勧めします。

このイベントを処理する際には、次のことも考慮してください。

  • 収集された情報を手動で確認する
  • 本人確認が失敗したことをユーザーに知らせるメールを送信する
  • ユーザーに代替の本人確認方法を提供する

本番環境に移行する

イベントハンドラのエンドポイントを本番環境にデプロイしたら、エンドポイントを設定して、Stripeが本番環境のイベントの送信先を認識できるようにします。実装を本番環境に円滑に移行するには、開発チェックリスト を確認することもお勧めします。

Webhook エンドポイントは、ダッシュボードで設定することも、API を使用してプログラムで設定することもできます。

ダッシュボードでエンドポイントを追加する

ダッシュボードの Webhooks 設定ページで、エンドポイントを追加をクリックして、新しい Webhook エンドポイントを追加します。Webhook エンドポイントの URL を入力して、リッスンするイベントを選択します。確認セッションイベントの一覧をご覧ください。

API を使用してエンドポイントを追加する

プログラムで Webhook エンドポイントを作成することもできます。ダッシュボードのフォームと同様に、イベントの宛先とする任意の URL と、登録するイベントタイプを設定できます。

Command Line
curl https://api.stripe.com/v1/webhook_endpoints \ -u
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:
\ -d "url"="https://{{DOMAIN}}/my/webhook/endpoint" \ -d "enabled_events[]"="identity.verification_session.verified" \ -d "enabled_events[]"="identity.verification_session.requires_input"

参照情報

  • Webhook エンドポイントをテストする
  • セッションの仕組み
  • Webhook 使用のベストプラクティス
  • Webhook 開発チェックリスト
このページはお役に立ちましたか。
はいいいえ
お困りのことがございましたら 、サポートにお問い合わせください。
早期アクセスプログラムにご参加ください。
変更ログをご覧ください。
ご不明な点がございましたら、お問い合わせください。
LLM ですか?llms.txt を読んでください。
Powered by Markdoc