コンテンツにスキップ
アカウントを作成
または
サインイン
Stripe ドキュメントのロゴ
/
AI に質問する
アカウントを作成
サインイン
始める
支払い
売上
プラットフォームおよびマーケットプレイス
資金管理
開発者向けリソース
概要
Stripe Payments について
構築済みのシステムをアップグレード
支払いの分析
オンライン決済
概要ユースケースを見つけるManaged Payments
Payment Links を使用する
決済ページを構築
高度なシステムを構築
アプリ内実装を構築
決済手段
決済手段を追加
決済手段を管理
Link による購入の迅速化
支払いインターフェイス
Payment Links
Checkout
Web Elements
アプリ内 Elements
決済シナリオ
複数の通貨を扱う
カスタムの決済フロー
柔軟なアクワイアリング
オーケストレーション
店頭支払い
端末
決済にとどまらない機能
会社を設立する
仮想通貨
Financial Connections
Climate
不正利用について
Radar の不正防止
不審請求の申請の管理
本人確認
    概要
    始める
    本人確認書類を確認
    確認結果を処理
    確認結果へのアクセス
    確認結果を表示
    確認フロー
    検証チェック
    API について
    確認セッション
    本番環境へ移行
    本番環境への移行前
    サポートするユースケース
    Identity に関する説明
ホーム支払いVerify identities

注

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

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

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

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

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

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

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

Stripe を設定する
サーバー側

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

Command Line
Ruby
Python
PHP
Java
Node
Go
.NET
No results
# Available as a gem sudo gem install stripe
Gemfile
Ruby
Python
PHP
Java
Node
Go
.NET
No results
# If you use bundler, you can add this line to your Gemfile gem 'stripe'

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

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

Webhook は、サーバー上のエンドポイントで、Stripe からのリクエストを受信し、アカウントで発生するイベントについて通知します。このステップでは、VerificationSession の ステータス変更 でイベントを受信するエンドポイントを構築します。

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

server.js
Node
Ruby
Python
PHP
Java
Go
.NET
No results
// 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 イベントを処理する必要があります。他のセッションイベント に登録して、アプリで追加のリアクションをトリガーすることもできます。

VerificationSession 確認済みステータス変化を処理する

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

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

server.js
Node
Ruby
Python
PHP
Java
Go
.NET
No results
// 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 の確認された出力を拡張し、予測される値と比較します。

VerificationSession requires_input のステータス変化を処理する

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

  • last_error.code フィールドを使用して、確認の失敗をプログラムで処理可能です。
  • last_error.reason フィールドには、失敗の理由を示すメッセージが含まれます。このフィールドをユーザーに提示できます。

イベントエラーコード

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

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

server.js
Node
Ruby
Python
PHP
Java
Go
.NET
No results
// 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 endpoints are configured in Workbench or programmatically using the API.

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

  1. In Workbench’s Webhooks tab, click Add destination to add a new webhook endpoint.
  2. Stripe API のバージョンを入力します。
  3. Select which events to listen to. See the full list of Verification Session events.
  4. 続行をクリックし、使用可能な送信先タイプのリストからWebhook エンドポイントを選択します。
  5. 続行をクリックし、エンドポイントの URL、オプションの名前、オプションの説明を入力します。
  6. 送信先を作成するをクリックします。

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

プログラムで Webhook エンドポイントを作成 することもできます。Workbench のフォームと同様に、イベントの送信先として任意の 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