Paypal API crashes when pointing to my certificate file

I try to perform some payments using DoPapture using the Paypal API, and I get a Fatal Exception in the line of code where I set the CertificateFile property to the location of my certificate file.

The corresponding code is given below:

using com.paypal.sdk.profiles; using com.paypal.sdk.services; using com.paypal.sdk.util; IAPIProfile profile = ProfileFactory.createSignatureAPIProfile(); profile.CertificateFile = @"~\MyTestCertificate.txt"; 

Collapsing the details of the Exception does not give me more information; it more or less simply confirms that Fatal Exception was actually thrown.

Leaving the tilde and backslash, he is also mistaken:

 profile.CertificateFile = @"MyTestCertificate.txt"; 

I thought that maybe I need the contents of the file instead of the place, so I tried the following, but got the same error:

 profile.CertificateFile = new StreamReader(@"MyTestCertificate.txt").ReadToEnd().ToString(); 

It seems that no matter what you set for the CertificateFile property, you get a fatal exception.

A few questions:

  • Where can I find documentation for the IAPIProfile class in the Paypal API, in particular, documentation for the CertificateFile property
  • If I should not indicate the path to my certificate file in this place, what should I do?

To confirm, MyTestCertificate.txt added to my solution, and Copy to Output Directory is Copy Always .

The exception text is as follows:

{"An exception of type" com.paypal.sdk.exceptions.FatalException "has been thrown." }

StackTrace is as follows:

 at com.paypal.sdk.profiles.SignatureAPIProfile.set_CertificateFile(String value) at MyProject_Payment_Processing.Paypal.DoCaptureCode(String authorization_id, String amount) in C:\Users\JMK\documents\visual studio 2010\Projects\MyProject Payment Processing\MyProject Payment Processing\Paypal.cs:line 16 at MyProject_Payment_Processing.Program.Main(String[] args) in C:\Users\JMK\documents\visual studio 2010\Projects\MyProject Payment Processing\MyProject Payment Processing\Program.cs:line 15 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() 

The Paypal API uses Log4Net, which logs the error as follows:

Jul 20, 2012 12:39:11 PM FATAL [FatalException] com.paypal.sdk.exceptions.FatalException: an exception of type "com.paypal.sdk.exceptions.FatalException" was thrown.

thanks

+2
source share
2 answers

It turns out that aydiv was right, I had to use WinHttpCertCfg to register the certificate. Martin was also right that I used a signature profile, as opposed to a certificate profile.

The first thing I needed to do was use OpenSSL to encrypt my certificate using the following command. I had to enter the password here, which I used later. This created an encrypted certificate file called paypal_cert.p12 :

openssl pkcs12 -export -in MyTestCertificate.txt -inkey MyTestCertificate.txt -out paypal_cert.p12

Then I installed WinHttpCertCfg and used the following command to register my certificate, replacing PFXPassword with the password I entered earlier:

winhttpcertcfg -i PFXFile -c LOCAL_MACHINE \ My -a JMK -p PFXPassword

Also, I used to use NVP DLL files, instead I need to use the SOAP dll from here . This meant that I had to replace the NVPCallerServices in my code with Callerservices , as well as several other things.

My latest code for running DoCapture Paypal in C # .Net is below, hope this helps someone who will run into this problem in the future!

 class Paypal { public string DoCaptureCode(string authorization_id, string amount) { CallerServices caller = new CallerServices(); IAPIProfile profile = ProfileFactory.createSSLAPIProfile(); profile.APIUsername = "JMK"; profile.APIPassword = "FooBar"; profile.CertificateFile = @"~\MyTestCertificate.txt"; profile.Environment = "sandbox"; caller.APIProfile = profile; DoCaptureRequestType pp_request = new DoCaptureRequestType(); pp_request.Version = "51.0"; pp_request.AuthorizationID = authorization_id; pp_request.Amount = new BasicAmountType(); pp_request.Amount.Value = amount; pp_request.Amount.currencyID = CurrencyCodeType.GBP; pp_request.CompleteType = CompleteCodeType.Complete; DoCaptureResponseType pp_response = new DoCaptureResponseType(); pp_response = (DoCaptureResponseType)caller.Call("DoCapture", pp_request); return pp_response.Ack.ToString(); } } 
0
source

You will need to install the certificate in the Microsoft system store. The readme in the SDK explains how you can do this using the WinHttpCertCfg tool.

+1
source

All Articles