Test error conditions with negative testing
APICurrentLast updated: March 16th 2023, @ 11:23:55 am
Important: Negative testing in the sandbox is in beta.
Negative testing lets you force the flows through specific error conditions that you want to test to ensure you handle errors correctly. Use negative testing to trigger the following types of errors:
- Errors that result from calling a PayPal API.
- Errors related to Virtual Terminal and the
DoDirectPaymentoperation, which relate to verification and credit card validation errors.
You can force two types of API errors: errors related to the transaction amount, and errors not related to the transaction amount.
Know before you code
Negative testing is only available for use with the following:
- Sandbox environments. You cannot force or simulate error conditions in the live PayPal environment.
- Classic PayPal API versions 2.4 and later.
- Business accounts.
Enable negative testing
- Go to the developer.paypal.com home page. Log into the Dashboard and select the menu below your name to select
- Under the
Sandboxheading in the left navigation column, select
- Locate the sandbox account for which you wish to enable negative testing. Choose a business sandbox account or you won't see the options you need.
- In the
Manage Accountscolumn, select ... to display the menu choices.
View/Edit Accountto see the
Account Detailspage that has the
Profiletab selected by default.
- Select the
Settingstab to display a list of options you can set.
- Set the
Negative Testingoption to
The sandbox is now in the negative testing state for transactions that include the merchant. Without this configuration, the sandbox does not raise error conditions unless the error occurs through normal transaction processing.
In the PayPal sandbox, you can pass inputs to simulate scenarios that mimic the actual API responses without calling downstream services.
You can use the following methods to conduct negative testing in the sandbox: