简体   繁体   English

PayPal RestApiSDK .NET http 503服务器不可用

[英]PayPal RestApiSDK .NET http 503 Server Unavailable

I am trying to use the PayPal .NET RestApiSDK to store credit cards and take payments in their sandbox. 我正在尝试使用PayPal .NET RestApiSDK来存储信用卡并在其沙箱中付款。 I am using .NET 4.5 in an MVC project. 我在MVC项目中使用.NET 4.5。

I followed the example code here: https://developer.paypal.com/webapps/developer/docs/api/#store-a-credit-card 我在这里遵循示例代码: https : //developer.paypal.com/webapps/developer/docs/api/#store-a-credit-card

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) 在第一天,我能够:-分几次付款-存储几张卡-查找销售-退款销售-在金库中存储卡(基本上,示例代码中的所有内容)

Ever since day one (about a week), I have been getting an http 503 "Server Unavailable" error. 从第一天(大约一周)开始,我一直收到一个HTTP 503“服务器不可用”错误。 Unless I changed something in my sleep, I am using the exact code that worked before. 除非我在睡觉时更改了某些内容,否则我将使用以前使用过的确切代码。

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. 我联系了贝宝(PayPal)支持人员,在反复来回消息后,他们让我知道,尽管他们无法查明我的代码中的错误,但该错误必须在我这一边,因为他们的服务器运行良好。

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(). 例如,我可以调用payments.List()。 However, I can't call creditCard.Create() or payment.Create(). 但是,我无法调用creditCard.Create()或payment.Create()。

Also, the access token is being created just fine. 同样,可以创建访问令牌。 The line tokenCredential.GetAccessToken() does not return any server error. 行tokenCredential.GetAccessToken()不返回任何服务器错误。 When I debug the code, it has indeed returned with a proper token. 当我调试代码时,它确实已经返回了正确的令牌。

Question: What could possibly be causing an http 503 error when I try to store a card or take a payment? 问题:当我尝试存储卡或付款时,什么可能导致http 503错误?

Here is some relevant code. 这是一些相关的代码。

controller: 控制器:

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

When stepping through, the error occors on the line 单步执行时,错误会在线上发生

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

the exact error (as a Json Object): 确切的错误(作为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 keys are truncated here): 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>

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. 如您所见,我已经配置了log4net,它正在记录由我正在使用的另一个.dll(对于RavenDB)生成的数据,但是PayPal没有任何条目。

Thanks! 谢谢!

I finally uninstalled the two nuget packages RestApiSDK and PayPalCoreSDK. 我终于卸载了两个Nuget软件包RestApiSDK和PayPalCoreSDK。 I then restarted Visual Studio. 然后,我重新启动了Visual Studio。 Finally, I re-installed those same two packages. 最后,我重新安装了这两个软件包。

Without changing any code, it started working. 在不更改任何代码的情况下,它开始工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM