【问题标题】:PayPal RestApiSDK .NET http 503 Server UnavailablePayPal RestApiSDK .NET http 503 服务器不可用
【发布时间】:2013-10-28 15:38:34
【问题描述】:

我正在尝试使用 PayPal .NET RestApiSDK 来存储信用卡并在他们的沙箱中进行付款。我在 MVC 项目中使用 .NET 4.5。

我按照这里的示例代码: https://developer.paypal.com/webapps/developer/docs/api/#store-a-credit-card

最初,事情很简单。在第一天,我能够: - 接受几笔付款 - 存储多张卡片 - 查找销售 - 退款销售 - 在保险库中存储卡片 (基本上,他们的示例代码中的所有内容)

从第一天(大约一周)开始,我就收到了 http 503“服务器不可用”错误。除非我在睡梦中改变了某些东西,否则我会使用之前有效的代码。

我联系了 PayPal 支持,经过多次来回消息,他们告诉我,虽然他们无法查明我的代码中的错误,但错误一定是我自己,因为他们的服务器工作正常。

真正奇怪的是,我似乎能够做任何不更改数据的事情。例如,我可以调用 payment.List()。但是,我不能调用 creditCard.Create() 或 payment.Create()。

此外,访问令牌的创建也很好。行 tokenCredential.GetAccessToken() 不返回任何服务器错误。当我调试代码时,它确实返回了一个正确的令牌。

问题: 当我尝试存储卡或付款时,可能会导致 http 503 错误的原因是什么?

这是一些相关的代码。

控制器:

public JsonResult RunTestPayment()
        {
        string id = ConfigManager.Instance.GetProperties()["ClientID"];
        string secret = ConfigManager.Instance.GetProperties()["ClientSecret"];

        OAuthTokenCredential tokenCredential = new OAuthTokenCredential(id, secret);

        string accessToken = tokenCredential.GetAccessToken();

        PayPal.Api.Payments.Address billingAddress = new PayPal.Api.Payments.Address();
        billingAddress.line1 = "52 N Main St";
        billingAddress.city = "Johnstown";
        billingAddress.country_code = "US";
        billingAddress.postal_code = "43210";
        billingAddress.state = "OH";

        PayPal.Api.Payments.CreditCard creditCard = new PayPal.Api.Payments.CreditCard();
        creditCard.number = "4417119669820331";
        creditCard.type = "visa";
        creditCard.expire_month = 11;
        creditCard.expire_year = 2018;
        creditCard.cvv2 = "874";
        creditCard.first_name = "Joe";
        creditCard.last_name = "Shopper";
        creditCard.billing_address = billingAddress;

        PayPal.Api.Payments.Details amountDetails = new PayPal.Api.Payments.Details();
        amountDetails.subtotal = "7.51";
        amountDetails.tax = "0.03";
        amountDetails.shipping = "0.03";

        PayPal.Api.Payments.Amount amount = new PayPal.Api.Payments.Amount();
        amount.total = "7.56";
        amount.currency = "USD";
        amount.details = amountDetails;

        PayPal.Api.Payments.Transaction transaction = new PayPal.Api.Payments.Transaction();
        transaction.amount = amount;
        transaction.description = "This is the payment transaction description.";

        List<PayPal.Api.Payments.Transaction> transactions = new List<PayPal.Api.Payments.Transaction>();
        transactions.Add(transaction);

        PayPal.Api.Payments.FundingInstrument fundingInstrument = new PayPal.Api.Payments.FundingInstrument();
        fundingInstrument.credit_card = creditCard;

        List<PayPal.Api.Payments.FundingInstrument> fundingInstruments = new List<PayPal.Api.Payments.FundingInstrument>();
        fundingInstruments.Add(fundingInstrument);

        PayPal.Api.Payments.Payer payer = new PayPal.Api.Payments.Payer();
        payer.funding_instruments = fundingInstruments;
        payer.payment_method = "credit_card";

        PayPal.Api.Payments.Payment payment = new PayPal.Api.Payments.Payment();
        payment.intent = "sale";
        payment.payer = payer;
        payment.transactions = transactions;

        PayPal.Api.Payments.Payment createdPayment = payment.Create(accessToken);
        return Json(new JsonWrapper { Data = createdPayment });
}

单步执行时,错误发生在行

        PayPal.Api.Payments.Payment createdPayment = payment.Create(accessToken);

确切的错误(作为 Json 对象):

"ClassName":"PayPal.Exception.PayPalException","Message":"Exception in HttpConnection Execute: Invalid HTTP response The remote server returned an error: (503) Server Unavailable.","Data":null,"InnerException":{"ClassName":"PayPal.Exception.ConnectionException","Message":"Invalid HTTP response The remote server returned an error: (503) Server Unavailable.","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":"   at PayPal.HttpConnection.Execute(String payLoad, HttpWebRequest httpRequest)","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nExecute\nPayPalCoreSDK, Version=1.4.1.0, Culture=neutral, PublicKeyToken=null\nPayPal.HttpConnection\nSystem.String Execute(System.String, System.Net.HttpWebRequest)","HResult":-2146233088,"Source":"PayPalCoreSDK","WatsonBuckets":null},"HelpURL":null,"StackTraceString":"   at PayPal.PayPalResource.ConfigureAndExecute[T](Dictionary`2 config, IAPICallPreHandler apiCallPreHandler, HttpMethod httpMethod, String resourcePath)\r\n   at PayPal.PayPalResource.ConfigureAndExecute[T](APIContext apiContext, HttpMethod httpMethod, String resource, String payload)\r\n   at PayPal.Api.Payments.Payment.Create(APIContext apiContext)\r\n   at PayPal.Api.Payments.Payment.Create(String accessToken)\r\n   at Scout.Controllers.PaymentController.RequestPermissions() in e:\\Scout\\Scout\\Controllers\\PaymentController.cs:line 1105","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nConfigureAndExecute\nPayPalCoreSDK, Version=1.4.1.0, Culture=neutral, PublicKeyToken=null\nPayPal.PayPalResource\nT ConfigureAndExecute[T](System.Collections.Generic.Dictionary`2[System.String,System.String], PayPal.IAPICallPreHandler, PayPal.HttpMethod, System.String)","HResult":-2146233088,"Source":"PayPalCoreSDK","WatsonBuckets":null

web.config(api 键在这里被截断):

...
<configuration>
    <configSections>
       <section name="paypal" type="PayPal.Manager.SDKConfigHandler, PayPalCoreSDK" />
       <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    ...
    </configSections>
  ...
  <paypal>
    <settings>
      <add name="endpoint" value="https://api.sandbox.paypal.com"/>

      <add name="ClientID" value="AbayoRB3Eq6YxM6"/>
      <add name="ClientSecret" value="EDWNfxDxnGZ3hWZW"/>

      <add name="connectionTimeout" value="360000"/>
      <!-- The number of times a request must be retried if the API endpoint is unresponsive -->
      <add name="requestRetries" value="3"/>
    </settings>
  </paypal>
  ...
  <log4net>
    <appender name="FileAppender" type="log4net.Appender.FileAppender">
      <file value="ScoutPaypalLog.log" />
      <appendToFile value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] %message%newline" />
      </layout>
    </appender>
    <root>
      <level value="DEBUG" />
      <appender-ref ref="FileAppender" />
    </root>
  </log4net>

如您所见,我已经配置了 log4net,它正在记录我正在使用的另一个 .dll 生成的数据(用于 RavenDB),但没有 PayPal 生成的条目。

谢谢!

【问题讨论】:

    标签: asp.net asp.net-mvc paypal paypal-sandbox paypal-rest-sdk


    【解决方案1】:

    我终于卸载了RestApiSDK和PayPalCoreSDK这两个nuget包。然后我重新启动了 Visual Studio。最后,我重新安装了这两个相同的软件包。

    无需更改任何代码,它就开始工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-31
      • 1970-01-01
      • 2021-06-16
      • 2015-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多