底层连接已关闭:发送时出现意外错误

底层连接已关闭:发送时出现意外错误

问题描述:

我正在尝试在我的网站中使用DoDirectPayment方法。底层连接已关闭:发送时出现意外错误

这就是我所指的样本:

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

namespace ASPDotNetSamples 
{ 
    public class DoDirectPayment 
    { 
     public DoDirectPayment() 
     { 
     } 
     public string DoDirectPaymentCode(string paymentAction, string amount, string creditCardType, string creditCardNumber, string expdate_month, string cvv2Number, string firstName, string lastName, string address1, string city, string state, string zip, string countryCode, string currencyCode) 
     { 

      com.paypal.soap.api.DoDirectPaymentReq req = new com.paypal.soap.api.DoDirectPaymentReq(); 


      NVPCallerServices caller = new NVPCallerServices(); 
      IAPIProfile profile = ProfileFactory.createSignatureAPIProfile(); 

      // Set up your API credentials, PayPal end point, API operation and version. 
      profile.APIUsername = "sdk-three_api1.sdk.com"; 
      profile.APIPassword = "xxxxxxxxxxxxx"; 
      profile.APISignature = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; 
      profile.Environment = "sandbox"; 
      caller.APIProfile = profile; 

      NVPCodec encoder = new NVPCodec(); 
      encoder["VERSION"] = "51.0"; 
      encoder["METHOD"] = "DoDirectPayment"; 

      // Add request-specific fields to the request. 
      encoder["PAYMENTACTION"] = paymentAction; 
      encoder["AMT"] = amount; 
      encoder["CREDITCARDTYPE"] = creditCardType; 
      encoder["ACCT"] = creditCardNumber; 
      encoder["EXPDATE"] = expdate_month; 
      encoder["CVV2"] = cvv2Number; 
      encoder["FIRSTNAME"] = firstName; 
      encoder["LASTNAME"] = lastName; 
      encoder["STREET"] = address1; 
      encoder["CITY"] = city; 
      encoder["STATE"] = state; 
      encoder["ZIP"] = zip; 
      encoder["COUNTRYCODE"] = countryCode; 
      encoder["CURRENCYCODE"] = currencyCode; 

      // Execute the API operation and obtain the response. 
      string pStrrequestforNvp = encoder.Encode(); 
      string pStresponsenvp = caller.Call(pStrrequestforNvp); 

      NVPCodec decoder = new NVPCodec(); 
      decoder.Decode(pStresponsenvp); 
      return decoder["ACK"]; 

     } 
    } 
} 

这是链接:

https://cms.paypal.com/cms_content/US/en_US/files/developer/nvp_DoDirectPayment_cs.txt

当我通过适当的参数,并尝试运行代码我得到这个错误:“底层连接已关闭:发送时发生意外错误。“ on line:

pp_response = (DoDirectPaymentResponseType)caller.Call("DoDirectPayment", pp_Request); 

SOAP服务调用在dll中。任何人都可以指导我发生了什么以及如何解决它?

+1

隐藏你的用户名和密码! – alex

+0

@亚历克斯:哪一个?这是来自网站的样本!不是我的用户名和密码。 – Jaggu

+0

对不起,我以为他们是你的私人API密钥。 – alex

+0

您提供的链接不包含任何“直接付款”的名称。他们是否停止支持它? – Jaggu

+0

@Jaggu如果你花时间看看网站你会发现api文档,我已经更新了一个链接的答案,希望它有帮助,并且你明白你需要创建一个帐户才能够测试api。 – Joakim

+0

感谢Joakim。我仍然无法找到它。但你的第三个链接帮助我。 – Jaggu