我正在尝试使用 Paypal API DoCapture 一些付款,但我在将 CertificateFile 属性设置为我的证书文件位置的代码行中遇到了致命异常。
相关代码如下:
using com.paypal.sdk.profiles;
using com.paypal.sdk.services;
using com.paypal.sdk.util;
IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();
profile.CertificateFile = @"~\MyTestCertificate.txt";
深入了解异常细节并没有给我更多信息,它或多或少只是确认确实抛出了致命异常。
像这样省略波浪号和反斜杠会引发相同的错误:
profile.CertificateFile = @"MyTestCertificate.txt";
我想也许我需要文件的内容,而不是位置所以我尝试了以下但得到了同样的错误:
profile.CertificateFile = new StreamReader(@"MyTestCertificate.txt").ReadToEnd().ToString();
似乎无论将 CertificateFile 属性设置为什么,都会出现致命异常。
几个问题:
- 在哪里可以找到有关 Paypal API 中 IAPIProfile 类的文档,特别是
CertificateFile
属性的文档 - 如果我不应该将我的证书文件的路径放在这个位置,我应该怎么做?
只是为了确认,MyTestCertificate.txt
已添加到我的解决方案中,并且 Copy to Output Directory
设置为 Copy Always
。
异常文本如下:
{"Exception of type 'com.paypal.sdk.exceptions.FatalException' was thrown."}
StackTrace 看起来像这样:
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 记录错误:
20 Jul 2012 12:39:11 FATAL [FatalException] com.paypal.sdk.exceptions.FatalException: Exception of type 'com.paypal.sdk.exceptions.FatalException' was thrown.
谢谢
最佳答案
您必须在 Microsoft 系统商店中安装您的证书。 SDK 中的自述文件解释了如何使用 WinHttpCertCfg 工具执行此操作。
关于c# - Paypal API 在指向我的证书文件时失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11578192/