The error you are getting:
Security error Security header is not valid
occurs if you have not excepted the billing agreement after requesting the API credentials.
It may also occur if you are using Live API Credentials when processing the transaction through the paypal sand box or vice versa.
Some the credentials are just bad, and you need to request new ones.