PayPal API QueryParameters not found

154 views Asked by At

Screenshot

I copied and pasted a section from here (You will have to scroll to the top - click C# on the right and scroll down/refresh) and have installed the PayPal API into the project Install-Package PayPal but QueryParameters is not found - is there a second part or something I should already know about?


Code from site

OAuthTokenCredential tokenCredential =new OAuthTokenCredential("<CLIENT_ID>", "<CLIENT_SECRET>");

string accessToken = tokenCredential.GetAccessToken();
var parameters = new QueryParameters();
parameters.SetCount("10");

PaymentHistory paymentHistory = Payment.Get(accessToken, parameters);
2

There are 2 answers

3
cramopy On BEST ANSWER

AFAICS are the PayPal QueryParameters part of PayPal.Util. Please try if you can access this namespace.

If not you can add it manually (as a class) using this link.

You should also consider downloading the whole SDK if the above does not work using nuget.

0
Jason Z On

Some of the language tabs on the PayPal REST API Reference page have sample code that is woefully out-of-date (and in this case, completely incorrect since Payment.Get(...) is intended to return a single payment resource, not a list). The PayPal docs team is well aware of this issue and will be removing the language tabs in the near future in favor of the SDKs providing their own samples via GitHub.

I'd recommend checking out the PayPal .NET SDK samples project on GitHub, which does a much better job of showing you not only the code, but displaying the request/response details for each API operation.

Regarding getting the payment history, you'll want to do the following using the PayPal .NET SDK:

using PayPal.Api;

// Authenticate with PayPal and setup the APIContext object.
var config = ConfigManager.Instance.GetProperties();
var accessToken = new OAuthTokenCredential(config).GetAccessToken();
var apiContext = new APIContext(accessToken)
{
    Config = config
};

// Get the payment history
var paymentHistory = Payment.List(apiContext, count: 10, startIndex: 5);