テスト環境
Stripe’s test mode allows you to test your integration without making actual charges or payments. Test mode is a testing environment that simulates creating real objects without the risk of affecting real transactions or moving actual money. We recommend using our quality assurance (QA) testing use cases, and importing our Postman collection to aid you in the testing process.
Test mode
テスト環境では、テスト用のクレジットカードに請求するほか、テスト用の商品と価格を作成することができます。また、テスト環境を使用して取引をシミュレーションし、実装が正常に機能することを確認できます。この機能により、本番環境に移行して実際の支払いを処理する前に、Stripe 実装のバグやエラーを確認することができます。
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, toggle off test mode, and use the live API keys in your integration. Stripe provides a number of resources for testing your integration.
本番環境に対する影響
ダッシュボードでは、テスト環境で設定を変更すると、本番環境でも設定が変更される場合があります。ダッシュボードのページの多くに白色の通知ボックスがあり、テスト環境では本番環境の設定は無効になっています。この場合、有効になっている設定は安全に使用できます。白色のコールアウトがない場合は、オレンジ色のテストデータバナーが表示されていない限り、テスト環境で変更を行うと、本番環境の設定に変更が反映されるものとご理解ください。
テスト環境と本番環境
Stripe API リクエストはすべて、テスト環境か、本番環境のいずれかで発生します。一方の環境の API オブジェクトには、もう一方の環境からアクセスできません。たとえば、テスト環境の Product (商品) オブジェクトを本番環境の支払いの一部にすることはできません。
タイプ | 使用するタイミング | オブジェクト | 使用方法 | 考慮事項 |
---|---|---|---|---|
テスト環境 | 実装を構築する際には、テスト環境と関連するテスト API キーを使用します。テスト環境では、カードネットワークとペイメントプロバイダーは決済を処理しません。 | API コールは、シミュレーションされたオブジェクトを返します。たとえば、テストの account 、payment 、customer 、charge 、refund 、transfer 、balance 、subscription オブジェクトを取得して使用することができます。 | テスト用のクレジットカードとアカウントを使用します。実際の決済手段を受け付けることも、実際のアカウントを処理することもできません。 | Identity による検証チェックは行われません。また、Connect account (アカウント) オブジェクトは機密フィールドを返しません。 |
本番環境 | 実装を立ち上げて実際の支払いを受け付ける準備ができたら、本番環境と関連する本番 API キーを使用します。本番環境では、カードネットワークとペイメントプロバイダーは決済を処理します。 | API コールは、実際のオブジェクトを返します。たとえば、実際の account 、payment 、customer 、charge 、refund 、transfer 、balance 、subscription オブジェクトを取得して使用することができます。 | 実際のクレジットカードを受け付けて、顧客のアカウントを処理します。クレジットカードとアカウントの実際の支払いのオーソリ、支払い、キャプチャーを受け付けることができます。 | 不審請求の申請のフローはより細かく、テストプロセスはよりシンプルです。また、一部の決済手段ではフローがさらに細かく、ステップ数が多くなります。 |
ダッシュボードのテスト環境トグルが、実装環境のコードに影響を与えることはありません。コードの動作に影響を与えるのは、テスト環境と本番環境の API キーです。
テストカード番号
Stripe は、さまざまな決済シナリオのシミュレーションに使用できる一連のテストカード番号を提供しています。これらのテストカード番号を使用すると、実際の決済や請求を処理することなく、シミュレーション用の決済をテスト環境で作成できます。
テストカード番号を使用すると、任意の将来の有効期限と 3 桁のセキュリティコードを入力して、決済の成功をシミュレーションできます。決済の失敗をシミュレーションする場合は、Stripe が提供する特定のテストカード番号とセキュリティコードを使用できます。
テストカード番号はテスト環境でのみ有効です。実際の支払いには使用しないでください。
テストデータを削除する
すべてのテストデータを Stripe アカウントから削除するには、次の手順を実行してください。
- 既存の Stripe アカウントを使用してダッシュボードにログインします。
- テスト環境で、開発者をクリックして、概要タブの下部までスクロールダウンします。
- すべてのテストデータを削除… をクリックします。次に表示されるダイアログに、既存のすべてのテストデータオブジェクトのリストが示されます。
- 削除を開始をクリックして、削除プロセスを開始します。テストデータの削除を取り消すことはできません。
削除プロセスを実行中、テスト環境は一時的に利用できなくなります。
テストメール
デフォルトでは、Stripe からテスト環境の顧客にメールが送信されることはありません。メールで請求書や領収書を確認したい場合は、Customer
オブジェクトにチームのメールアドレスを設定するか、PaymentIntent に receipt_email
属性を設定してください。
Testing use cases
The following table contains quality assurance (QA) testing use cases:
Use case | Action |
---|---|
Charge success (capturing immediately) |
|
PaymentIntent authorization success (capturing funds for later) |
|
PaymentIntent capture success (capturing immediately or capturing funds for later) |
|
Charge fail | The charge appears as Failed in the Dashboard under Payments.
|
Radar block | No matter which version of Radar you use, it might block a charge due to high risk or a rule. The response is the same as what you get when a charge fails. |
Charge disputed |
|
Charge inquiry opened | Inquiries are similar to disputes, with three key distinctions: no funds are withdrawn unless we elevate an inquiry to a dispute, they remain refundable until disputed, and have a different set of statuses. In this case, Stripe fires a
|
Dispute won |
|
Dispute lost | When a customer loses a dispute, Stripe updates the existing
|
Inquiry won | When you win an inquiry, your balance remains the same, as no funds were removed when you initially opened the inquiry. Stripe updates the existing
|
Inquiry lost |
|
Charge refunded | The charge appears as Refunded in the Dashboard under Payments.
|
Charge partially refunded |
|
Account balance goes negative | Make sure to test for a negative balance on Stripe and verify that your bank accounts can accept debits from us. |
Successful payout | If you enable webhooks for a successful payout (recommended), test your handling of the event. |
Failed payout | If you enable webhooks for a failed payout (recommended), test your handling of the event. |
Stripe’s Postman collection
Postman is a widely-used API development tool. To make integrating Stripe easier, we provide a Payments-specific Postman collection with the tools you need to test the server-side component of your integration.
Import the collection
To begin, you need to access the Postman app. You can use either the browser or desktop version. After launching the app, import the collection.
To start this process on the web, press the Import button at the top-left corner, followed by the Link option. Insert the Payments collection link. If you’re using the Postman desktop app, click File > Import. After successfully importing, the collection appears under Collections.
The import dialog
Use the collection
To use the collection, navigate to the collection you just imported and click Variables. Copy your testmode Stripe secret key from the Stripe Dashboard, and paste it into the Initial Value field. After you complete this step, you’re ready to begin making requests.
Other variables are populated by scripts during the runtime of the collection. For example, when creating a customer, price, charge or PaymentIntent, the system saves that ID through a script in the collection, which is then accessible for later requests, like issuing a refund.
Add a secret key to a Postman collection