2013-10-20 35 views
0

我正在嘗試使用PayPal .NET RestApiSDK存儲信用卡並在其沙箱中進行付款。我在一個MVC項目中使用.NET 4.5。PayPal RestApiSDK .NET HTTP 503服務器不可用

我跟着示例代碼在這裏: https://developer.paypal.com/webapps/developer/docs/api/#store-a-credit-card

最初,事情很容易。在某一天,我能: -Take多次付款 -store幾張卡 -Look了銷售 -refund銷售 -store卡在跳馬 (基本上,一切都在他們的示例代碼)

永遠自第一天(大約一週)以來,我一直在收到http 503「服務器不可用」錯誤。除非我在睡眠中改變了某些東西,否則我正在使用以前工作的確切代碼。

我聯繫了PayPal支持,並且在幾次來回消息之後,他們讓我知道,儘管他們無法在我的代碼中查明錯誤,但錯誤必須在我身邊,因爲他們的服務器工作正常。

什麼是真奇怪,是我似乎能夠做任何不更改數據。例如,我可以調用payments.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 = ""; 
     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); 

確切錯誤的錯誤occors(作爲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)生成的數據,但沒有貝寶做出的條目。

謝謝!

回答

0

我終於卸載了兩個nuget軟件包RestApiSDK和PayPalCoreSDK。然後我重新啓動了Visual Studio。最後,我重新安裝了這兩個相同的軟件包。

不更改任何代碼,它開始工作。

相關問題