Error PayPal gateway has rejected request. Security header is not valid (#10002: Security error) PHP Magento 2.

When you have set up a Payment Method as Paypal for your eCommerce store and might be you have faced the error of Paypal gateway has rejected the request in Magento 2 or PHP Web application.

The error will be,
PayPal gateway has rejected the request. Security header is not valid (#10002: Security error)

The Cause of error is, You have a mismatched/invalid required parameter value.

Invalid Parameter will be, API Username, API Password or API Signature. Doublecheck your parameter doesn’t contain any extra whitespace.

Check the Paypal Errors from the Paypal site Paypal Errors,

How to check the Required parameter is valid or not from Paypal?

You have to verify your Username, Password, and signature from your Paypal Account. I will show to get the Sandbox credential from the Paypal site.

Check your Sandbox credential from the Sandbox Login link.

  • Login with Your email/mobile and password.
  • Once Logged In to your sandbox account,  Click on Setting Icon(Before Logout link) at the top right location.
  • Choose Account Setting from the Dropdown.
  • Go to Account Access tab from the left sidebar, Click on Update link from the API Access.
Sandbox-PayPal page

On click of the Update link,  New Page will be displayed.

Next Go to the Custom checkout experience section with NVP/SOAP API integration (Classic), Click on Manage API credentials link.

Get Your API Username, Password, and signature from the page.

Paypal Signature Username and Password

Verify your username, password, and signature with your saved Magento Stores -> Configuration.

if any parameter is invalid, You need to set the valid parameter for username, password, and signature in your Magento admin panel Paypal configuration section.

Clear the cache and check again the checkout page to verify Paypal checkout is working or not.