简体   繁体   中英

PayPal API QueryParameters not found

屏幕截图

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

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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