Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 0 additions & 8 deletions CHANGELOG.md

This file was deleted.

112 changes: 66 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@

### Important Notes

- **Available Features:** This SDK currently contains only 3 of PayPal's API endpoints. Additional endpoints and functionality will be added in the future.
- **Available Features:** This SDK currently contains only 5 of PayPal's API endpoints. Additional endpoints and functionality will be added in the future.

### Information

The PayPal Server SDK provides integration access to the PayPal REST APIs. The API endpoints are divided into distinct controllers:

- Orders Controller: [Orders API v2](https://developer.paypal.com/docs/api/orders/v2/)
- Payments Controller: [Payments API v2](https://developer.paypal.com/docs/api/payments/v2
- Payments Controller: [Payments API v2](https://developer.paypal.com/docs/api/payments/v2)
- Vault Controller: [Payment Method Tokens API v3](https://developer.paypal.com/docs/api/payment-tokens/v3/) *Available in the US only.*
- Transaction Search Controller: [Transaction Search API v1](https://developer.paypal.com/docs/api/transaction-search/v1/)
- Subscriptions Controller: [Subscriptions API v1](https://developer.paypal.com/docs/api/subscriptions/v1/)

## Install the Package

Expand All @@ -23,43 +25,57 @@ Install the SDK by adding the following dependency in your project's pom.xml fil
<dependency>
<groupId>com.paypal.sdk</groupId>
<artifactId>paypal-server-sdk</artifactId>
<version>1.1.0</version>
<version>2.0.0</version>
</dependency>
```

You can also view the package at:
https://central.sonatype.com/artifact/com.paypal.sdk/paypal-server-sdk/1.1.0
https://central.sonatype.com/artifact/com.paypal.sdk/paypal-server-sdk/2.0.0

## Initialize the API Client

**_Note:_** Documentation for the client can be found [here.](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/client.md)
**_Note:_** Documentation for the client can be found [here.](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/client.md)

The following parameters are configurable for the API Client:

| Parameter | Type | Description |
| --- | --- | --- |
| environment | `Environment` | The API environment. <br> **Default: `Environment.SANDBOX`** |
| httpClientConfig | [`Consumer<HttpClientConfiguration.Builder>`](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/http-client-configuration-builder.md) | Set up Http Client Configuration instance. |
| loggingConfig | [`Consumer<ApiLoggingConfiguration.Builder>`](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/api-logging-configuration-builder.md) | Set up Logging Configuration instance. |
| clientCredentialsAuth | [`ClientCredentialsAuth`](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/auth/oauth-2-client-credentials-grant.md) | The Credentials Setter for OAuth 2 Client Credentials Grant |
| httpClientConfig | [`Consumer<HttpClientConfiguration.Builder>`](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/http-client-configuration-builder.md) | Set up Http Client Configuration instance. |
| loggingConfig | [`Consumer<ApiLoggingConfiguration.Builder>`](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/api-logging-configuration-builder.md) | Set up Logging Configuration instance. |
| clientCredentialsAuth | [`ClientCredentialsAuth`](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/auth/oauth-2-client-credentials-grant.md) | The Credentials Setter for OAuth 2 Client Credentials Grant |

The API client can be initialized as follows:

```java
PaypalServerSdkClient client = new PaypalServerSdkClient.Builder()
.loggingConfig(builder -> builder
.level(Level.DEBUG)
.requestConfig(logConfigBuilder -> logConfigBuilder.body(true))
.responseConfig(logConfigBuilder -> logConfigBuilder.headers(true)))
.httpClientConfig(configBuilder -> configBuilder
.timeout(0))
.clientCredentialsAuth(new ClientCredentialsAuthModel.Builder(
"OAuthClientId",
"OAuthClientSecret"
)
.build())
.environment(Environment.SANDBOX)
.build();
import com.paypal.sdk.Environment;
import com.paypal.sdk.PaypalServerSdkClient;
import com.paypal.sdk.authentication.ClientCredentialsAuthModel;
import com.paypal.sdk.exceptions.ApiException;
import com.paypal.sdk.http.response.ApiResponse;
import com.paypal.sdk.models.OAuthToken;
import java.io.IOException;
import org.slf4j.event.Level;

public class Program {
public static void main(String[] args) {
PaypalServerSdkClient client = new PaypalServerSdkClient.Builder()
.loggingConfig(builder -> builder
.level(Level.DEBUG)
.requestConfig(logConfigBuilder -> logConfigBuilder.body(true))
.responseConfig(logConfigBuilder -> logConfigBuilder.headers(true)))
.httpClientConfig(configBuilder -> configBuilder
.timeout(0))
.clientCredentialsAuth(new ClientCredentialsAuthModel.Builder(
"OAuthClientId",
"OAuthClientSecret"
)
.build())
.environment(Environment.SANDBOX)
.build();

}
}
```

## Environments
Expand All @@ -77,42 +93,46 @@ The SDK can be configured to use a different environment for making API calls. A

This API uses the following authentication schemes.

* [`Oauth2 (OAuth 2 Client Credentials Grant)`](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/auth/oauth-2-client-credentials-grant.md)
* [`Oauth2 (OAuth 2 Client Credentials Grant)`](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/auth/oauth-2-client-credentials-grant.md)

## List of APIs

* [Orders](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/controllers/orders.md)
* [Payments](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/controllers/payments.md)
* [Vault](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/controllers/vault.md)
* [Transactionsearch](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/controllers/transactionsearch.md)
* [Orders](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/controllers/orders.md)
* [Payments](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/controllers/payments.md)
* [Vault](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/controllers/vault.md)
* [Subscriptions](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/controllers/subscriptions.md)

## SDK Infrastructure

### Configuration

* [ApiLoggingConfiguration](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/api-logging-configuration.md)
* [ApiLoggingConfiguration.Builder](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/api-logging-configuration-builder.md)
* [ApiRequestLoggingConfiguration.Builder](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/api-request-logging-configuration-builder.md)
* [ApiResponseLoggingConfiguration.Builder](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/api-response-logging-configuration-builder.md)
* [Configuration Interface](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/configuration-interface.md)
* [HttpClientConfiguration](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/http-client-configuration.md)
* [HttpClientConfiguration.Builder](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/http-client-configuration-builder.md)
* [ApiLoggingConfiguration](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/api-logging-configuration.md)
* [ApiLoggingConfiguration.Builder](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/api-logging-configuration-builder.md)
* [ApiRequestLoggingConfiguration.Builder](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/api-request-logging-configuration-builder.md)
* [ApiResponseLoggingConfiguration.Builder](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/api-response-logging-configuration-builder.md)
* [Configuration Interface](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/configuration-interface.md)
* [HttpClientConfiguration](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/http-client-configuration.md)
* [HttpClientConfiguration.Builder](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/http-client-configuration-builder.md)
* [HttpProxyConfiguration](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/http-proxy-configuration.md)
* [HttpProxyConfiguration.Builder](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/http-proxy-configuration-builder.md)

### HTTP

* [Headers](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/headers.md)
* [HttpCallback Interface](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/http-callback-interface.md)
* [HttpContext](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/http-context.md)
* [HttpBodyRequest](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/http-body-request.md)
* [HttpRequest](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/http-request.md)
* [HttpResponse](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/http-response.md)
* [HttpStringResponse](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/http-string-response.md)
* [Headers](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/headers.md)
* [HttpCallback Interface](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/http-callback-interface.md)
* [HttpContext](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/http-context.md)
* [HttpBodyRequest](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/http-body-request.md)
* [HttpRequest](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/http-request.md)
* [HttpResponse](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/http-response.md)
* [HttpStringResponse](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/http-string-response.md)

### Utilities

* [ApiException](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/api-exception.md)
* [ApiResponse](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/api-response.md)
* [ApiHelper](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/api-helper.md)
* [FileWrapper](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/file-wrapper.md)
* [JsonObject](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/json-object.md)
* [JsonValue](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/1.1.0/doc/json-value.md)
* [ApiException](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/api-exception.md)
* [ApiResponse](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/api-response.md)
* [ApiHelper](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/api-helper.md)
* [FileWrapper](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/file-wrapper.md)
* [JsonObject](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/json-object.md)
* [JsonValue](https://www.github.com/paypal/PayPal-Java-Server-SDK/tree/2.0.0/doc/json-value.md)

98 changes: 63 additions & 35 deletions doc/auth/oauth-2-client-credentials-grant.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,23 @@ Documentation for accessing and setting credentials for Oauth2.
You must initialize the client with *OAuth 2.0 Client Credentials Grant* credentials as shown in the following code snippet. This will fetch the OAuth token automatically when any of the endpoints, requiring *OAuth 2.0 Client Credentials Grant* authentication, are called.

```java
PaypalServerSdkClient client = new PaypalServerSdkClient.Builder()
.clientCredentialsAuth(new ClientCredentialsAuthModel.Builder(
"OAuthClientId",
"OAuthClientSecret"
)
.build())
.build();
import com.paypal.sdk.PaypalServerSdkClient;
import com.paypal.sdk.authentication.ClientCredentialsAuthModel;
import com.paypal.sdk.exceptions.ApiException;
import com.paypal.sdk.models.OAuthToken;
import java.io.IOException;

public class Program {
public static void main(String[] args) {
PaypalServerSdkClient client = new PaypalServerSdkClient.Builder()
.clientCredentialsAuth(new ClientCredentialsAuthModel.Builder(
"OAuthClientId",
"OAuthClientSecret"
)
.build())
.build();
}
}
```


Expand All @@ -45,41 +55,59 @@ Your application can also manually provide an OAuthToken using the setter `oAuth
Whenever the OAuth Token gets updated, the provided callback implementation will be executed. For instance, you may use it to store your access token whenever it gets updated.

```java
PaypalServerSdkClient client = new PaypalServerSdkClient.Builder()
.clientCredentialsAuth(new ClientCredentialsAuthModel.Builder(
"OAuthClientId",
"OAuthClientSecret"
)
.oAuthOnTokenUpdate(oAuthToken -> {
// Add the callback handler to perform operations like save to DB or file etc.
// It will be triggered whenever the token gets updated
saveTokenToDatabase(oAuthToken);
})
.build())
.build();
import com.paypal.sdk.PaypalServerSdkClient;
import com.paypal.sdk.exceptions.ApiException;
import com.paypal.sdk.models.OAuthToken;
import java.io.IOException;

public class Program {
public static void main(String[] args) {
PaypalServerSdkClient client = new PaypalServerSdkClient.Builder()
.clientCredentialsAuth(new ClientCredentialsAuthModel.Builder(
"OAuthClientId",
"OAuthClientSecret"
)
.oAuthOnTokenUpdate(oAuthToken -> {
// Add the callback handler to perform operations like save to DB or file etc.
// It will be triggered whenever the token gets updated
saveTokenToDatabase(oAuthToken);
})
.build())
.build();
}
}
```

### Adding Custom OAuth Token Provider

To authorize a client using a stored access token, set up the `oAuthTokenProvider` in `ClientCredentialsAuthModel` builder along with the other auth parameters before creating the client:

```java
PaypalServerSdkClient client = new PaypalServerSdkClient.Builder()
.clientCredentialsAuth(new ClientCredentialsAuthModel.Builder(
"OAuthClientId",
"OAuthClientSecret"
)
.oAuthTokenProvider((lastOAuthToken, credentialsManager) -> {
// Add the callback handler to provide a new OAuth token
// It will be triggered whenever the lastOAuthToken is undefined or expired
OAuthToken oAuthToken = loadTokenFromDatabase();
if (oAuthToken != null && !credentialsManager.isTokenExpired(oAuthToken)) {
return oAuthToken;
}
return credentialsManager.fetchToken();
})
.build())
.build();
import com.paypal.sdk.PaypalServerSdkClient;
import com.paypal.sdk.exceptions.ApiException;
import com.paypal.sdk.models.OAuthToken;
import java.io.IOException;

public class Program {
public static void main(String[] args) {
PaypalServerSdkClient client = new PaypalServerSdkClient.Builder()
.clientCredentialsAuth(new ClientCredentialsAuthModel.Builder(
"OAuthClientId",
"OAuthClientSecret"
)
.oAuthTokenProvider((lastOAuthToken, credentialsManager) -> {
// Add the callback handler to provide a new OAuth token
// It will be triggered whenever the lastOAuthToken is undefined or expired
OAuthToken oAuthToken = loadTokenFromDatabase();
if (oAuthToken != null && !credentialsManager.isTokenExpired(oAuthToken)) {
return oAuthToken;
}
return credentialsManager.fetchToken();
})
.build())
.build();
}
}
```


44 changes: 30 additions & 14 deletions doc/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,34 @@ The following parameters are configurable for the API Client:
The API client can be initialized as follows:

```java
PaypalServerSdkClient client = new PaypalServerSdkClient.Builder()
.loggingConfig(builder -> builder
.level(Level.DEBUG)
.requestConfig(logConfigBuilder -> logConfigBuilder.body(true))
.responseConfig(logConfigBuilder -> logConfigBuilder.headers(true)))
.httpClientConfig(configBuilder -> configBuilder
.timeout(0))
.clientCredentialsAuth(new ClientCredentialsAuthModel.Builder(
"OAuthClientId",
"OAuthClientSecret"
)
.build())
.environment(Environment.SANDBOX)
.build();
import com.paypal.sdk.Environment;
import com.paypal.sdk.PaypalServerSdkClient;
import com.paypal.sdk.authentication.ClientCredentialsAuthModel;
import com.paypal.sdk.exceptions.ApiException;
import com.paypal.sdk.http.response.ApiResponse;
import com.paypal.sdk.models.OAuthToken;
import java.io.IOException;
import org.slf4j.event.Level;

public class Program {
public static void main(String[] args) {
PaypalServerSdkClient client = new PaypalServerSdkClient.Builder()
.loggingConfig(builder -> builder
.level(Level.DEBUG)
.requestConfig(logConfigBuilder -> logConfigBuilder.body(true))
.responseConfig(logConfigBuilder -> logConfigBuilder.headers(true)))
.httpClientConfig(configBuilder -> configBuilder
.timeout(0))
.clientCredentialsAuth(new ClientCredentialsAuthModel.Builder(
"OAuthClientId",
"OAuthClientSecret"
)
.build())
.environment(Environment.SANDBOX)
.build();

}
}
```

## PayPal Server SDKClient Class
Expand All @@ -40,6 +54,8 @@ The gateway for the SDK. This class acts as a factory for the Controllers and al
| `getOrdersController()` | Provides access to Orders controller. | `OrdersController` |
| `getPaymentsController()` | Provides access to Payments controller. | `PaymentsController` |
| `getVaultController()` | Provides access to Vault controller. | `VaultController` |
| `getTransactionsearchController()` | Provides access to Transactionsearch controller. | `TransactionsearchController` |
| `getSubscriptionsController()` | Provides access to Subscriptions controller. | `SubscriptionsController` |
| `getOAuthAuthorizationController()` | Provides access to OAuthAuthorization controller. | `OAuthAuthorizationController` |

### Methods
Expand Down
Loading
Loading