指向我的证书文件时,贝宝API掉落 [英] Paypal API falls over when pointing to my certificate file

查看:64
本文介绍了指向我的证书文件时,贝宝API掉落的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Paypal API进行一些付款,并且在将CertificateFile属性设置为证书文件位置的代码行上出现致命异常.

I am trying to DoCapture some payments using the Paypal API and I am getting a Fatal Exception on the line of code where I set the CertificateFile property to the location of my certificate file.

相关代码如下:

using com.paypal.sdk.profiles;
using com.paypal.sdk.services;
using com.paypal.sdk.util;

IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();
profile.CertificateFile = @"~\MyTestCertificate.txt";

深入研究例外"详细信息并不能为我提供更多信息,它或多或少只是确认确实引发了致命异常.

Drilling down into the Exceptions details doesn't give me much more information, it more or less just confirms that a Fatal Exception has indeed been thrown.

像这样省略波浪号和反斜杠会引发相同的错误:

Leaving out the tilde and backslash like so throws the same error:

profile.CertificateFile = @"MyTestCertificate.txt";

我以为也许我需要文件的内容而不是位置,所以我尝试了以下操作,但遇到了相同的错误:

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

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

无论将CertificateFile属性设置为什么,都会出现致命异常.

It seems that whatever you set the CertificateFile property to, you get a fatal exception.

几个问题:

  1. 在哪里可以找到有关Paypal API中IAPIProfile类的文档,特别是CertificateFile属性的文档
  2. 如果我不应该将证书文件的路径放在这个位置,我该怎么办?
  1. Where can I find documentation on the IAPIProfile class in the Paypal API, in particular documentation for the CertificateFile property
  2. If I am not supposed to put the path to my certificate file in this location, what am I supposed to do?

仅需确认,将MyTestCertificate.txt添加到我的解决方案中,并且Copy to Output Directory设置为Copy Always.

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

异常文本如下:

{引发了'com.paypal.sdk.exceptions.FatalException类型的异常."}

{"Exception of type 'com.paypal.sdk.exceptions.FatalException' was thrown."}

StackTrace看起来像这样:

The StackTrace looks like this:

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()

贝宝(Paypal)API使用Log4Net来记录错误,如下所示:

The Paypal API uses Log4Net which logs the error as so:

2012年7月20日12:39:11致命[FatalException] com.paypal.sdk.exceptions.FatalException:引发了"com.paypal.sdk.exceptions.FatalException"类型的异常.

20 Jul 2012 12:39:11 FATAL [FatalException] com.paypal.sdk.exceptions.FatalException: Exception of type 'com.paypal.sdk.exceptions.FatalException' was thrown.

谢谢

推荐答案

事实证明aydiv是正确的,我必须使用WinHttpCertCfg来注册证书. Martin也是对的,因为我使用的是签名配置文件,而不是证书配置文件.

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

我要做的第一件事是使用以下命令使用OpenSSL加密我的证书.我必须在这里输入一个密码,稍后再使用.这创建了一个名为paypal_cert.p12:

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

openssl pkcs12-导出-in MyTestCertificate.txt -inkey MyTestCertificate.txt -out paypal_cert.p12

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

然后我安装了WinHttpCertCfg,并使用以下命令注册了我的证书,用PFXPassword代替了我之前输入的密码:

I then installed WinHttpCertCfg and used the following command to register my certificate, substituting PFXPassword for the password I entered earlier:

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

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

此外,我以前使用过NVP DLL文件,而我需要使用

Also, I was using the NVP DLL files before, I instead need to use the SOAP dll's from here. This meant that I had to replace NVPCallerServices in my code with Callerservices, along with a few other things.

下面是我在C#.Net中执行Paypal DoCapture的最终代码,希望这将对以后遇到此问题的人有所帮助!

My final code for performing a Paypal DoCapture in C# .Net is below, hopefully this will help somebody who comes across 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();
    }
}

这篇关于指向我的证书文件时,贝宝API掉落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆