PayPal's SDK for interacting with the REST APIs
$ dotnet add package PayPalServerSDKThe PayPal Server SDK provides integration access to the PayPal REST APIs. The API endpoints are divided into distinct controllers:
If you are building with .NET CLI tools then you can also use the following command:
dotnet add package PayPalServerSDK --version 2.2.0
You can also view the package at: https://www.nuget.org/packages/PayPalServerSDK/2.2.0
Note: Documentation for the client can be found here.
The following parameters are configurable for the API Client:
| Parameter | Type | Description |
|---|---|---|
| Environment | Environment | The API environment. Default: Environment.Sandbox |
| Timeout | TimeSpan | Http client timeout. Default: TimeSpan.FromSeconds(100) |
| HttpClientConfiguration | Action<HttpClientConfiguration.Builder> | Action delegate that configures the HTTP client by using the HttpClientConfiguration.Builder for customizing API call settings. Default: new HttpClient() |
| LogBuilder | LogBuilder | Represents the logging configuration builder for API calls |
| ClientCredentialsAuth | ClientCredentialsAuth | The Credentials Setter for OAuth 2 Client Credentials Grant |
The API client can be initialized as follows:
using Microsoft.Extensions.Logging;
using PaypalServerSdk.Standard;
using PaypalServerSdk.Standard.Authentication;
namespace ConsoleApp;
PaypalServerSdkClient client = new PaypalServerSdkClient.Builder()
.ClientCredentialsAuth(
new ClientCredentialsAuthModel.Builder(
"OAuthClientId",
"OAuthClientSecret"
)
.Build())
.Environment(PaypalServerSdk.Standard.Environment.Sandbox)
.LoggingConfig(config => config
.LogLevel(LogLevel.Information)
.RequestConfig(reqConfig => reqConfig.Body(true))
.ResponseConfig(respConfig => respConfig.Headers(true))
)
.Build();
using PaypalServerSdk.Standard;
using Microsoft.Extensions.Configuration;
namespace ConsoleApp;
// Build the IConfiguration using .NET conventions (JSON, environment, etc.)
var configuration = new ConfigurationBuilder()
.AddJsonFile("config.json")
.AddEnvironmentVariables() // [optional] read environment variables
.Build();
// Instantiate your SDK and configure it from IConfiguration
var client = PaypalServerSdkClient
.FromConfiguration(configuration.GetSection("PaypalServerSdk"));
See the Configuration-Based Initialization section for details.
The SDK can be configured to use a different environment for making API calls. Available environments are:
| Name | Description |
|---|---|
| Production | PayPal Live Environment |
| Sandbox | Default PayPal Sandbox Environment |
This API uses the following authentication schemes.