note

Some of our exceptions may be indicators of a known issue with Braintree's API. To stay up-to-date with any current issues or scheduled maintenance, we recommend subscribing to PayPal's status page, specifically the Product and API sections for Braintree services.

Handling exceptions

Handling exceptions is straightforward and follows common language conventions.

PHP
try {
  $customer = $gateway->customer()->find('an_unknown_customer_id');
} catch (Braintree\Exception\NotFound $e) {
  echo $e->getMessage();
}
This code snippet now uses PHP standard PSR-4 namespacing to load modules. Learn more.

Our list of available exceptions is up-to-date with the latest versions of the server SDKs. Check our migration guide if you are integrating from an older version.

Authentication Error

Braintree\Exception\Authentication

Raised when your API keys are incorrect. If you're getting this exception when first integrating, double-check that you haven't accidentally tried to use your sandbox keys in production or vice-versa.

Authorization Error

Braintree\Exception\Authorization

Raised when the API key that you're using is not authorized to perform the attempted action according to the role assigned to the user who owns the API key.

This error can also occur if the data you submitted was malformed – either a parameter isn't in the allowed list, or it is at the wrong location in the nested parameters.

Configuration Error

Braintree\Exception\Configuration

Raised when the library isn't configured. Make sure you have environment, merchantId, publicKey, and privateKey.

PHP
$gateway = new Braintree\Gateway([
    'environment' => 'sandbox',
    'merchantId' => 'your_merchant_id',
    'publicKey' => 'your_public_key',
    'privateKey' => 'your_private_key'
]);
This code snippet now uses PHP standard PSR-4 namespacing to load modules. Learn more.

Invalid Challenge

Braintree\Exception\InvalidChallenge

Raised when the webhook challenge you attempt to verify is in an invalid format.

Invalid Signature

Braintree\Exception\InvalidSignature

Raised when the webhook notification you attempt to parse has an invalid signature.

This could be caused by a payload being modified in transit or if you attempt to parse messages that did not originate from our servers.

Not Found Error

Braintree\Exception\NotFound

Raised when the record that you're trying to operate on can't be found. For example, if you try to update a customer and the customer ID isn't valid. For references and associations, you'll receive a validation error if the reference is invalid. For example, when creating a credit card and specifying which customer ID it should be associated to, if the customer ID is invalid, it will be a validation error, not a not found exception.

Server Error

Braintree\Exception\ServerError

Raised when something goes wrong on the Braintree server when trying to process your request.

SSL Certificate

Braintree\Exception\SSLCertificate

Raised when the client library can't verify the server's TLS/SSL certificate. This error can also mean you are unable to connect to the Braintree gateway due to an outage or network issue.

Unexpected Error

Braintree\Exception\Unexpected

Raised when an error occurs that the client library is not built to handle. If this happens, there's probably a bug in the client library.

Too Many Requests Error

Braintree\Exception\TooManyRequests

Raised when requests associated with your account reach unsafe levels. We may limit API resources by merchant if activity risks negative impact to other merchants.

Upgrade Required Error

Braintree\Exception\UpgradeRequired

Raised when you're trying to use a version of the library that is no longer supported. Please see our Server SDK Deprecation Policy for more information.

Timeouts

Timeout Exception

Braintree\Exception\Timeout

Raised when a request times out because it takes longer than the custom timeout limit you set in the server SDKs. A request that returns this exception could still be successful if it processes within the Braintree gateway timeout limit of 60 seconds. Learn more about timeouts.

Gateway Timeout Error

Braintree\Exception\GatewayTimeout

Raised when Braintree servers time out delivering a response. For search API calls, this usually indicates the amount of information you are requesting is greater than the amount of time Braintree servers have to retrieve it and send a response. Try breaking down your search calls into smaller batches.

Request Timeout Error

Braintree\Exception\RequestTimeout

Raised when Braintree servers time out waiting for the entire request from your server. This usually indicates an issue upstream of Braintree.

Service Unavailable Error

Braintree\Exception\ServiceUnavailable

Raised when the Braintree gateway service is unavailable.