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 the 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 the error is, You have a mismatched/invalid required parameter value.

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

Check the list of Paypal Errors from the Paypal Official site Paypal Errors,

How to check whether 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 the Account Access tab from the left sidebar, and click on the Update link from the API Access.
sandbox-paypal
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), and Click on the 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 whether Paypal checkout is working or not.