贝宝RestApiSDK .NET HTTP 503服务器不可用 [英] PayPal RestApiSDK .NET http 503 Server Unavailable

查看:507
本文介绍了贝宝RestApiSDK .NET HTTP 503服务器不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用支付宝.NET RestApiSDK存储信用卡,并采取在他们的沙箱付款。我使用.NET 4.5在MVC项目。

I am trying to use the PayPal .NET RestApiSDK to store credit cards and take payments in their sandbox. I am using .NET 4.5 in an MVC project.

我也跟着例如code在这里:
https://developer.paypal.com/webapps/开发商/文档/ API /#存储-A-信用卡

I followed the example code here: https://developer.paypal.com/webapps/developer/docs/api/#store-a-credit-card

起初,事情很容易。在有一天,我能够:
通吃多种付款
-store几款显卡
-Look了销售
-refund销售
在跳马-store卡
(基本上,一切都在他们的榜样code)

Initially, things were very easy. On day one, I was able to: -take several payments -store several cards -look up sales -refund sales -store cards in the vault (basically, everything in their example code)

自从一天(一个星期左右),我一直得到一个HTTP 503服务器不可用的错误。除非我在我的睡眠变的东西,我现在用的确切code,以前的工作。

Ever since day one (about a week), I have been getting an http 503 "Server Unavailable" error. Unless I changed something in my sleep, I am using the exact code that worked before.

我联系了贝宝的支持,并经过多次来回的消息,他们让我知道,虽然他们不能在我的code精确定位错误,误差必须在我身边,因为他们的服务器工作正常

I contacted PayPal support, and after several back and forth messages they have let me know that while they can't pinpoint an error in my code, the error must be on my side, because their servers are working fine.

什么是真正奇怪的是,我似乎能够做任何事情,没有的变更的数据。举例来说,我可以调用payments.List()。但是,我不能叫creditCard.Create()或payment.Create()。

What is really strange, is that I seem to be able to do anything that doesn't change data. For instance, I can call payments.List(). However, I can't call creditCard.Create() or payment.Create().

此外,访问令牌正在创建就好了。该生产线tokenCredential.GetAccessToken()不返回任何服务器错误。当我调试code,它确实有一个适当的令牌返回。

Also, the access token is being created just fine. The line tokenCredential.GetAccessToken() does not return any server error. When I debug the code, it has indeed returned with a proper token.

问题:
当我尝试存储卡或拍下付款怎么可能会导致HTTP 503错误?

Question: What could possibly be causing an http 503 error when I try to store a card or take a payment?

下面是一些相关的code。

Here is some relevant code.

控制器:

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 });
}

当单步调试,上线错误occors

When stepping through, the error occors on the line

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

确切的错误(如一个JSON对象):

the exact error (as a Json Object):

"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密钥都在这里截断):

web.config (api keys are truncated here):

...
<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的,它是通过记录我使用(用于RavenDB)另一个.dll文件生成的数据,但目前还没有通过贝宝的条目。

As you can see, I have configured log4net, and it is recording data generated by another .dll I'm using (for RavenDB), but there are no entries made by PayPal.

谢谢!

推荐答案

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

I finally uninstalled the two nuget packages RestApiSDK and PayPalCoreSDK. I then restarted Visual Studio. Finally, I re-installed those same two packages.

在不改变任何code,它开始工作。

Without changing any code, it started working.

这篇关于贝宝RestApiSDK .NET HTTP 503服务器不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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