ユースケースをテストする
テスト環境と Stripe のユースケースを使用して実装内容をテストします。
Stripe’s testing environments, such as test mode and Sandboxes, allow you to test your integration without making actual charges or payments. These environments simulate creating real objects without affecting actual transactions or moving real money. We recommend using our quality assurance (QA) testing use cases, and importing our Postman collection to aid you in the testing process.
Testing environments 
In a testing environment, you can charge test credit cards and create test products and prices. These environments let you simulate transactions to make sure that your integration works correctly. This feature helps to identify any bugs or errors in your Stripe implementation before you go live with actual payments. Learn how to decide between using test mode and Sandboxes.
After you create a Stripe account, you can find a set of test API keys in the Stripe Dashboard. You can use these API keys to create and retrieve simulated data by making requests to the Stripe API. To start accepting real payments, you need to activate your account, exit your testing environment using the account picker, and use the live API keys in your integration. Stripe provides a number of resources for testing your integration.
Impact on live mode when using test mode
If you change settings in the Dashboard while in test mode, you might also change them in live mode. Many Dashboard pages have a white notification box and disable live mode settings while in test mode. In this case, any settings still enabled are safe to use. If you don’t see a white callout, assume any changes made in test mode affect live mode settings (unless you see an orange or blue test data banner).
Testing environments versus live mode 
All Stripe API requests occur in either testing environments or live mode. API objects in one mode aren’t accessible to the other. For example, a test product object can’t be part of a live mode payment.
タイプ | 使用するタイミング | オブジェクト | 使用方法 | 考慮事項 |
---|---|---|---|---|
sandboxes | Use a sandbox, and its associated test API keys, as you build your integration. In a sandbox, card networks and payment providers don’t process payments. | API コールは、シミュレーションされたオブジェクトを返します。たとえば、テストの account 、payment 、customer 、charge 、refund 、transfer 、balance 、subscription オブジェクトを取得して使用することができます。 | テスト用のクレジットカードとアカウントを使用します。実際の支払い方法を受け付けることも、実際のアカウントを処理することもできません。 | Identity による検証チェックは行われません。また、Connect account (アカウント) オブジェクトは機密フィールドを返しません。 |
本番環境 | 実装を立ち上げて実際の支払いを受け付ける準備ができたら、本番環境と関連する本番 API キーを使用します。本番環境では、カードネットワークとペイメントプロバイダーは決済を処理します。 | API コールは、実際のオブジェクトを返します。たとえば、実際の account 、payment 、customer 、charge 、refund 、transfer 、balance 、subscription オブジェクトを取得して使用することができます。 | 実際のクレジットカードを受け付けて、顧客のアカウントを処理します。クレジットカードとアカウントの実際の支払いのオーソリ、支払い、キャプチャーを受け付けることができます。 | 不審請求の申請のフローはより細かく、テストプロセスはよりシンプルです。また、一部の支払い方法ではフローがさらに細かく、ステップ数が多くなります。 |
Being in a testing environment in the Dashboard doesn’t affect your integration code. Your test and live mode API keys affect the behavior of your code. Your test and live mode API keys affect the behavior of your code.
テストカード番号
Stripe provides a set of test card numbers that you can use to simulate various payment scenarios. You can use these test card numbers to create simulated payments in testing environments without processing actual payments or charges.
テストカード番号を使用すると、任意の将来の有効期限と 3 桁のセキュリティコードを入力して、決済の成功をシミュレーションできます。決済の失敗をシミュレーションする場合は、Stripe が提供する特定のテストカード番号とセキュリティコードを使用できます。
Test card numbers are only valid in testing environments. Don’t use them for real payments.
テストデータを削除する
すべてのテストデータを Stripe アカウントから削除するには、次の手順を実行してください。
- 既存の Stripe アカウントを使用してダッシュボードにログインします。
- While in your testing environments, click Developers > Overview.
- テストデータで、テストデータをレビューをクリックします。ここのダイアログに、既存のすべてのテストデータオブジェクトのリストが表示されます。
- テストデータを削除をクリックして、削除プロセスを開始します。テストデータの削除を取り消すことはできません。
Testing environments are temporarily unusable while the deletion process occurs.
注
Meters (従量課金) オブジェクトは、自動化されたテストデータの削除プロセスでサポートされていないため、手動で削除する必要があります。
テストメール
By default, Stripe doesn’t email customers in testing environments. For example, paying an invoice in a sandbox doesn’t send a receipt email to the customer. Invoices finalized through the API in testing environments also don’t send a receipt email to the customer.
If you want Stripe to email customers in a testing environment, you can do the following in the Dashboard:
- 請求書を作成して特定の顧客に手動で送信します。
- 支払い済みの請求書の領収書を手動で送信します。
メールで請求書や領収書を確認する場合は、Customer
オブジェクトにチームのメールアドレスを設定するか、PaymentIntent に receipt_
属性を設定してください。
ユースケースをテストする
次の表には、品質保証 (QA) テストのユースケースが含まれています。
ユースケース | アクション |
---|---|
支払いの成功 (ただちにキャプチャーする場合) |
|
PaymentIntent オーソリ成功 (売上を後でキャプチャーする) |
|
PaymentIntent キャプチャー成功 (売上をただちにキャプチャーする場合、または後で売上をキャプチャーする場合) |
|
支払いの失敗 | この支払いは、ダッシュボードの支払いに失敗として表示されます。
|
Radar によるブロック | 使用する Radar のバージョンに関係なく、リスクが高いため、またはルールにより、支払いがブロックされる場合があります。レスポンスは、支払いの失敗の場合と同じです。 |
不審請求が申請された支払い |
|
未解決の支払い照会 | 照会は不審請求の申請と似ていますが、主な相違点は、照会が不審請求の申請に発展しない限り、売上が引き落とされないこと、不審請求が申請されるまで返金可能なままであること、およびステータスが異なることです。この場合、 Stripeは、
|
不審請求の申請に対する主張が認められた |
|
不審請求の申請に対する主張が認められなかった | 顧客が不審請求の申請で主張が認められなかった場合、Stripe は、既存の
|
照会に対する主張が認められた | 照会の主張が認められた場合、照会を最初に開始した際に売上が削除されなかったため、残高は変わりません。Stripe は、既存の
|
照会に対する主張が認められなかった |
|
返金済みの支払い | この支払いは、ダッシュボードの支払いに返金済みとして表示されます。
|
一部返金済みの支払い |
|
アカウント残高がマイナスになる | 必ず Stripe でマイナス残高をテストして、銀行口座が Stripe からの引き落としを受け付けられることを確認してください。 |
成功した入金 | 成功した入金 (推奨) に対して Webhook を有効にしている場合は、イベントの処理をテストします。 |
失敗した入金 | 失敗した入金 (推奨) に対して Webhook を有効にしている場合は、イベントの処理をテストします。 |
Stripe の Postman コレクション
Postman は、広く利用されている API 開発ツールです。Stripe の導入をよりシンプルにするために、構築済みシステムのサーバー側コンポーネントをテストする際に必要なツールとともに支払い専用の Postman コレクションをご用意しております。
コレクションをインポートする
まず、Postman アプリにアクセスする必要があります。ブラウザーバージョンまたはデスクトップバージョンを使用できます。アプリを起動したら、コレクションをインポートします。
ウェブでこのプロセスを開始するには、左上隅にあるインポートボタンをクリックしてから、Link オプションをクリックします。Payments コレクションのリンクを貼り付けます。Postman のデスクトップアプリを使用している場合は、File (ファイル) > Import (インポート) をクリックします。正常にインポートされると、Collections (コレクション) の下にコレクションが表示されます。

インポートダイアログ
コレクションを使用する
コレクションを使用するには、先ほどインポートしたコレクションに移動して、Variables (変数) をクリックします。テスト環境の Stripe シークレットキーを Stripe ダッシュボードからコピーして、Initial Value (初期値) フィールドに貼り付けます。この手順が完了すると、リクエストの実行準備が整います。
他の変数は、コレクションの実行時にスクリプトによって入力されます。たとえば、customer、price、charge、PaymentIntent を作成する場合は、システムは、コレクションのスクリプトを使用してその ID を保存し、返金などの後続のリクエストで使用できるようにします。

Postman コレクションにシークレットキーを追加する