"Security header is invalid" using the PayPal stand-alone software platform in .NET.

I am using the PayPal sandbox in ASP.Net C # 4.0. I added the following web links:

https://www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl https://www.paypalobjects.com/wsdl/PayPalSvc.wsdl 

When I run this code:

 PayPalAPIHelper.PayPalSandboxWS.SetExpressCheckoutReq req = new PayPalAPIHelper.PayPalSandboxWS.SetExpressCheckoutReq() { SetExpressCheckoutRequest = new PayPalAPIHelper.PayPalSandboxWS.SetExpressCheckoutRequestType() { Version = Version, SetExpressCheckoutRequestDetails = reqDetails } }; // query PayPal and get token PayPalAPIHelper.PayPalSandboxWS.SetExpressCheckoutResponseType resp = BuildPayPalSandboxWebservice().SetExpressCheckout(req); 

In my resp object, the error message says:

Security header is invalid

I was told to give him the correct API credentials. I signed up for developer.paypal.com and I assume that the email address and password I used are my valid credentials. How and where can I provide him with my API credentials? Thanks

+7
source share
1 answer

You checked the addresses of the endpoints in the web.config file

They should be referenced at the following URL.

For API certificate => SOAP https://api.sandbox.paypal.com/2.0/

For API Signature => SOAP https://api-3t.sandbox.paypal.com/2.0/

If you use a signature, use the following code

 CustomSecurityHeaderType type = new CustomSecurityHeaderType(); type.Credentials = new UserIdPasswordType() { Username = ConfigurationManager.AppSettings["PayPalUserName"], //Not paypal login username Password = ConfigurationManager.AppSettings["PayPalPassword"], //not login password Signature = ConfigurationManager.AppSettings["PayPalSignature"] }; 

To get a Paypal signature, follow the link

For more information, click here.

Update:

Please check the following code that it works for me

 CustomSecurityHeaderType type = new CustomSecurityHeaderType(); type.Credentials = new UserIdPasswordType() { Username = ConfigurationManager.AppSettings["PayPalUserName"], Password = ConfigurationManager.AppSettings["PayPalPassword"], Signature = ConfigurationManager.AppSettings["PayPalSignature"] }; PaymentDetailsItemType[] pdItem = new PaymentDetailsItemType[1]; pdItem[0] = new PaymentDetailsItemType() { Amount = new BasicAmountType(){currencyID = CurrencyCodeType.USD,Value = ItemPrice}, Name = ItemName, Number = ItemNumber, Description = ItemDescription, ItemURL = ItemUrl }; SetExpressCheckoutRequestDetailsType sdt = new SetExpressCheckoutRequestDetailsType(); sdt.NoShipping = "1"; PaymentDetailsType pdt = new PaymentDetailsType() { OrderDescription = OrderDesc, PaymentDetailsItem = pdItem, OrderTotal = new BasicAmountType() { currencyID = CurrencyCodeType.USD, Value = ItemPrice } }; sdt.PaymentDetails = new PaymentDetailsType[] { pdt }; sdt.CancelURL = "http://localhost:62744/PaymentGateway/PaymentFailure.aspx"; sdt.ReturnURL = "http://localhost:62744/PaymentGateway/ExpressCheckoutSuccess.aspx"; SetExpressCheckoutReq req = new SetExpressCheckoutReq() { SetExpressCheckoutRequest = new SetExpressCheckoutRequestType() { SetExpressCheckoutRequestDetails = sdt, Version = "92.0" } }; var paypalAAInt = new PayPalAPIAAInterfaceClient(); var resp = paypalAAInt.SetExpressCheckout(ref type, req); if (resp.Errors != null && resp.Errors.Length > 0) { // errors occured throw new Exception("Exception(s) occured when calling PayPal. First exception: " + resp.Errors[0].LongMessage); } Response.Redirect(string.Format("{0}?cmd=_express-checkout&token={1}", ConfigurationManager.AppSettings["PayPalOriginalUrl"], resp.Token)); 
+4
source

All Articles