10

I downloaded the Paypal SDK for C# and am trying to create a basic payment in my asp.net mvc app. I'm running the exact code mentioned in the paypal dev site, https://developer.paypal.com/webapps/developer/docs/api/#create-a-payment but am getting an error (stack trace below). I'm able to get an access token so I'm assuming the app is able to communicate with the endpoint, but not sure why it complains in the Payment.create method. This is the first time I'm using asp.net mvc so am a little confused about what I could be doing wrong and would really appreciate any help :)

My Web.config file has this section:

  <paypal>
    <settings>
      <add name="endpoint" value="https://api.sandbox.paypal.com" />
      <add name="connectionTimeout" value="360000" />
      <add name="requestRetries" value="1" />
      <add name="ClientID" value="xyz" />
      <add name="ClientSecret" value="abc" />
    </settings>
  </paypal>

Stack trace:

PayPal.Exception.PayPalException was unhandled by user code   HResult=-2146233088   Message=Exception in HttpConnection Execute: Invalid HTTP response The remote server returned an error: (503) Server Unavailable.   Source=PayPalCoreSDK   StackTrace:
       at PayPal.PayPalResource.ConfigureAndExecute[T](Dictionary`2 config, IAPICallPreHandler apiCallPreHandler, HttpMethod httpMethod, String resourcePath)
       at PayPal.PayPalResource.ConfigureAndExecute[T](APIContext apiContext, HttpMethod httpMethod, String resource, String payload)
       at PayPal.Api.Payments.Payment.Create(APIContext apiContext)
       at PayPal.Api.Payments.Payment.Create(String accessToken)
       at Requext.Controllers.EventController.CreatePayment() in c:\Users\Ishan\Source\Repos\requext.com\Requext\Controllers\EventController.cs:line 169
       at Requext.Controllers.EventController.Test() in c:\Users\Ishan\Source\Repos\requext.com\Requext\Controllers\EventController.cs:line 95
       at lambda_method(Closure , ControllerBase , Object[] )
       at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
       at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.InvokeSynchronousActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41()
       at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult
_)
       at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
       at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33()
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() InnerException: PayPal.Exception.ConnectionException
       HResult=-2146233088
       Message=Invalid HTTP response The remote server returned an error: (503) Server Unavailable.
       Source=PayPalCoreSDK
       Response=""
       StackTrace:
            at PayPal.HttpConnection.Execute(String payLoad, HttpWebRequest httpRequest)
       InnerException:
iman453
  • 9,105
  • 16
  • 54
  • 70
  • I am having the same problem. I'm starting to think it's a problem with the .Net library they provide. The code doesn't look like production quality code. I can make curl calls with no problem. I may Fork my own copy so I can debug it. – Agile Jedi Oct 16 '13 at 13:27
  • I've had less than stellar experience integrating PayPal direct payment in our c# MVC3 application a couple years back due to their lack of documentation and an outdated c# SDK. Ultimately, I had success manually creating a `HttpWebRequest` that POSTs an HTML form with the appropriate form values in the content. I'd be happy to post the details if you're interested. However, uninstalling the nuget packages (RestApiSDK and PayPalCoreSDK), restarting Visual Studio and re-installing the nuget packages seemed to resolve this error (from this [answer](http://stackoverflow.com/a/19504323/143008)). – HOCA Nov 21 '13 at 00:47
  • Thanks Agile and HOCA. I gave up on it and used a workaround since it looks like the SDK code is buggy. – iman453 Dec 05 '13 at 00:25

1 Answers1

1

I worked a lot with PayPal and I found out hard way what the best way is using just their “REST” api (note the “”). I cannot post solution I made due to “not divulgation” agreement, but Trust me, just finish move SDK to trash and start with their POST api and “back POST” apis. It’s way simpler.

CRABOLO
  • 8,605
  • 39
  • 41
  • 68
Jurion
  • 1,230
  • 11
  • 18