Skip to content

Commit a6a795e

Browse files
Automated commit message
1 parent 8231f00 commit a6a795e

File tree

100 files changed

+2359
-47
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+2359
-47
lines changed

README.md

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ The package is compatible with Python versions `3.7+`.
2323
Install the package from PyPi using the following pip command:
2424

2525
```bash
26-
pip install paypal-server-sdk==2.0.0
26+
pip install paypal-server-sdk==2.1.0
2727
```
2828

2929
You can also view the package at:
30-
https://pypi.python.org/pypi/paypal-server-sdk/2.0.0
30+
https://pypi.python.org/pypi/paypal-server-sdk/2.1.0
3131

3232
## Initialize the API Client
3333

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

3636
The following parameters are configurable for the API Client:
3737

@@ -46,12 +46,14 @@ The following parameters are configurable for the API Client:
4646
| backoff_factor | `float` | A backoff factor to apply between attempts after the second try. <br> **Default: 2** |
4747
| retry_statuses | `Array of int` | The http statuses on which retry is to be done. <br> **Default: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524]** |
4848
| retry_methods | `Array of string` | The http methods on which retry is to be done. <br> **Default: ['GET', 'PUT']** |
49-
| proxy_settings | [`ProxySettings`](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.0.0/doc/proxy-settings.md) | Optional proxy configuration to route HTTP requests through a proxy server. |
50-
| logging_configuration | [`LoggingConfiguration`](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.0.0/doc/logging-configuration.md) | The SDK logging configuration for API calls |
51-
| client_credentials_auth_credentials | [`ClientCredentialsAuthCredentials`](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.0.0/doc/auth/oauth-2-client-credentials-grant.md) | The credential object for OAuth 2 Client Credentials Grant |
49+
| proxy_settings | [`ProxySettings`](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/proxy-settings.md) | Optional proxy configuration to route HTTP requests through a proxy server. |
50+
| logging_configuration | [`LoggingConfiguration`](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/logging-configuration.md) | The SDK logging configuration for API calls |
51+
| client_credentials_auth_credentials | [`ClientCredentialsAuthCredentials`](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/auth/oauth-2-client-credentials-grant.md) | The credential object for OAuth 2 Client Credentials Grant |
5252

5353
The API client can be initialized as follows:
5454

55+
### Code-Based Client Initialization
56+
5557
```python
5658
import logging
5759

@@ -80,6 +82,17 @@ client = PaypalServersdkClient(
8082
)
8183
```
8284

85+
### Environment-Based Client Initialization
86+
87+
```python
88+
from paypalserversdk.paypal_serversdk_client import PaypalServersdkClient
89+
90+
# Specify the path to your .env file if it’s located outside the project’s root directory.
91+
client = PaypalServersdkClient.from_environment(dotenv_path='/path/to/.env')
92+
```
93+
94+
See the [Environment-Based Client Initialization](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/environment-based-client-initialization.md) section for details.
95+
8396
## Environments
8497

8598
The SDK can be configured to use a different environment for making API calls. Available environments are:
@@ -95,36 +108,37 @@ The SDK can be configured to use a different environment for making API calls. A
95108

96109
This API uses the following authentication schemes.
97110

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

100113
## List of APIs
101114

102-
* [Transactionsearch](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.0.0/doc/controllers/transactionsearch.md)
103-
* [Orders](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.0.0/doc/controllers/orders.md)
104-
* [Payments](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.0.0/doc/controllers/payments.md)
105-
* [Vault](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.0.0/doc/controllers/vault.md)
106-
* [Subscriptions](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.0.0/doc/controllers/subscriptions.md)
115+
* [Orders](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/controllers/orders.md)
116+
* [Payments](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/controllers/payments.md)
117+
* [Vault](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/controllers/vault.md)
118+
* [Transaction Search](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/controllers/transaction-search.md)
119+
* [Subscriptions](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/controllers/subscriptions.md)
107120

108121
## SDK Infrastructure
109122

110123
### Configuration
111124

112-
* [ProxySettings](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.0.0/doc/proxy-settings.md)
113-
* [AbstractLogger](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.0.0/doc/abstract-logger.md)
114-
* [LoggingConfiguration](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.0.0/doc/logging-configuration.md)
115-
* [RequestLoggingConfiguration](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.0.0/doc/request-logging-configuration.md)
116-
* [ResponseLoggingConfiguration](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.0.0/doc/response-logging-configuration.md)
125+
* [ProxySettings](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/proxy-settings.md)
126+
* [Environment-Based Client Initialization](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/environment-based-client-initialization.md)
127+
* [AbstractLogger](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/abstract-logger.md)
128+
* [LoggingConfiguration](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/logging-configuration.md)
129+
* [RequestLoggingConfiguration](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/request-logging-configuration.md)
130+
* [ResponseLoggingConfiguration](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/response-logging-configuration.md)
117131

118132
### HTTP
119133

120-
* [HttpResponse](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.0.0/doc/http-response.md)
121-
* [HttpRequest](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.0.0/doc/http-request.md)
134+
* [HttpResponse](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/http-response.md)
135+
* [HttpRequest](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/http-request.md)
122136

123137
### Utilities
124138

125-
* [ApiResponse](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.0.0/doc/api-response.md)
126-
* [ApiHelper](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.0.0/doc/api-helper.md)
127-
* [HttpDateTime](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.0.0/doc/http-date-time.md)
128-
* [RFC3339DateTime](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.0.0/doc/rfc3339-date-time.md)
129-
* [UnixDateTime](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.0.0/doc/unix-date-time.md)
139+
* [ApiResponse](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/api-response.md)
140+
* [ApiHelper](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/api-helper.md)
141+
* [HttpDateTime](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/http-date-time.md)
142+
* [RFC3339DateTime](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/rfc3339-date-time.md)
143+
* [UnixDateTime](https://www.github.com/paypal/PayPal-Python-Server-SDK/tree/2.1.0/doc/unix-date-time.md)
130144

doc/client.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ The following parameters are configurable for the API Client:
2020

2121
The API client can be initialized as follows:
2222

23+
## Code-Based Client Initialization
24+
2325
```python
2426
import logging
2527

@@ -48,6 +50,17 @@ client = PaypalServersdkClient(
4850
)
4951
```
5052

53+
## Environment-Based Client Initialization
54+
55+
```python
56+
from paypalserversdk.paypal_serversdk_client import PaypalServersdkClient
57+
58+
# Specify the path to your .env file if it’s located outside the project’s root directory.
59+
client = PaypalServersdkClient.from_environment(dotenv_path='/path/to/.env')
60+
```
61+
62+
See the [Environment-Based Client Initialization](../doc/environment-based-client-initialization.md) section for details.
63+
5164
## PayPal Server SDK Client
5265

5366
The gateway for the SDK. This class acts as a factory for the Controllers and also holds the configuration of the SDK.

doc/controllers/transactionsearch.md renamed to doc/controllers/transaction-search.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
# Transactionsearch
1+
# Transaction Search
2+
3+
Use the `/transactions` resource to list transactions and the `/balances` resource to list balances.
24

35
```python
4-
transactionsearch_controller = client.transactionsearch
6+
transaction_search_controller = client.transaction_search
57
```
68

79
## Class Name
810

9-
`TransactionsearchController`
11+
`TransactionSearchController`
1012

1113
## Methods
1214

13-
* [Search Transactions](../../doc/controllers/transactionsearch.md#search-transactions)
14-
* [Search Balances](../../doc/controllers/transactionsearch.md#search-balances)
15+
* [Search Transactions](../../doc/controllers/transaction-search.md#search-transactions)
16+
* [Search Balances](../../doc/controllers/transaction-search.md#search-balances)
1517

1618

1719
# Search Transactions
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
2+
# Environment-Based Client Initialization
3+
4+
The SDK client can also be initialized directly from environment variables using the `from_environment()` class method. This allows the SDK to automatically read configuration values from the runtime environment or a .env file.
5+
6+
## Example
7+
8+
```python
9+
from paypalserversdk.paypal_serversdk_client import PaypalServersdkClient
10+
11+
# Specify the path to your .env file if it’s located outside the project’s root directory.
12+
client = PaypalServersdkClient.from_environment(dotenv_path='/path/to/.env')
13+
```
14+
15+
You can also specify a path to a `.env` file by passing it to the `from_environment()` method:
16+
17+
The same method can accept keyword arguments to override any values read from the environment, and the arguments to override values should follow the same approach as code-based client initialization.
18+
19+
```python
20+
from paypalserversdk.paypal_serversdk_client import PaypalServersdkClient
21+
22+
client = PaypalServersdkClient.from_environment(
23+
dotenv_path='/path/to/.env',
24+
timeout=0, # overrides timeout from environment variable
25+
)
26+
```
27+
28+
Values provided through arguments take precedence over those defined in environment variables.
29+
30+
## Example `.env` File
31+
32+
```python
33+
ENVIRONMENT=sandbox
34+
35+
O_AUTH_CLIENT_ID=ExampleOAuthClientId
36+
O_AUTH_CLIENT_SECRET=ExampleOAuthClientSecret
37+
O_AUTH_CLOCK_SKEW=5
38+
39+
TIMEOUT=60
40+
MAX_RETRIES=3
41+
BACKOFF_FACTOR=2
42+
RETRY_STATUSES=408,413
43+
RETRY_METHODS=GET,PUT,DELETE
44+
45+
# Logging Configuration
46+
LOG_LEVEL=DEBUG
47+
MASK_SENSITIVE_HEADERS=true
48+
49+
# Request Logging Configuration
50+
REQUEST_LOG_BODY=true
51+
REQUEST_LOG_HEADERS=true
52+
REQUEST_INCLUDE_QUERY_IN_PATH=true
53+
REQUEST_HEADERS_TO_INCLUDE=Content-Type,X-Request-ID
54+
REQUEST_HEADERS_TO_EXCLUDE=Authorization
55+
REQUEST_HEADERS_TO_UNMASK=X-Request-ID
56+
57+
# Response Logging Configuration
58+
RESPONSE_LOG_BODY=true
59+
RESPONSE_LOG_HEADERS=true
60+
RESPONSE_HEADERS_TO_INCLUDE=Content-Type,X-Correlation-ID,Date,Server
61+
RESPONSE_HEADERS_TO_EXCLUDE=Set-Cookie,Authorization,X-API-Key
62+
RESPONSE_HEADERS_TO_UNMASK=X-Correlation-ID
63+
64+
# Proxy Configuration
65+
PROXY_ADDRESS=http://localhost:3000
66+
PROXY_PORT=8080
67+
PROXY_USERNAME=username
68+
PROXY_PASSWORD=password
69+
```
70+
71+
## Note
72+
73+
- If an environment variable is not defined, the default SDK configuration value will be used.
74+

doc/models/order-tracker-request.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The tracking details of an order.
2525
"capture_id": "capture_id0",
2626
"notify_payer": false,
2727
"tracking_number": "tracking_number6",
28-
"carrier": "ZELERIS",
28+
"carrier": "ACS_GR",
2929
"carrier_name_other": "carrier_name_other0",
3030
"items": [
3131
{

doc/models/shipment-carrier.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,4 +1423,5 @@ The carrier for the shipment. Some carriers have a global version as well as loc
14231423
| `SWIFTX` | Swiftx. |
14241424
| `SFYDEXPRESS` | Sfyd Express. |
14251425
| `TOPTRANS` | Toptrans. |
1426+
| `OTHER` | Other. |
14261427

paypalserversdk/configuration.py

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
https://www.apimatic.io ).
88
"""
99

10+
import os
11+
from dotenv import load_dotenv
12+
from paypalserversdk.http.proxy_settings import ProxySettings
1013
from enum import Enum
14+
from paypalserversdk.logging.configuration.api_logging_configuration import LoggingConfiguration
1115
from apimatic_core.http.configurations.http_client_configuration import HttpClientConfiguration
1216
from apimatic_requests_client_adapter.requests_client import RequestsClient
1317

@@ -19,11 +23,65 @@ class Environment(Enum):
1923
# PayPal Sandbox Environment
2024
SANDBOX = 1
2125

26+
@classmethod
27+
def from_value(cls, value, default=None):
28+
"""
29+
Convert a value (string or int) to an Environment enum member.
30+
31+
Args:
32+
value (Union[str, int]): The value to convert.
33+
default (Environment): The fallback enum member if conversion fails.
34+
35+
Returns:
36+
Environment: Matching enum member or fallback if invalid.
37+
"""
38+
if value is None:
39+
return default
40+
41+
# Try to match directly by enum member
42+
if isinstance(value, cls):
43+
return value
44+
45+
# Handle integer or string conversion
46+
for member in cls:
47+
if str(member.value).lower() == str(value).lower() or member.name.lower() == str(value).lower():
48+
return member
49+
50+
# Fallback to provided default
51+
return default
52+
2253

2354
class Server(Enum):
2455
"""An enum for API servers"""
2556
DEFAULT = 0
2657

58+
@classmethod
59+
def from_value(cls, value, default=None):
60+
"""
61+
Convert a value (string or int) to an Server enum member.
62+
63+
Args:
64+
value (Union[str, int]): The value to convert.
65+
default (Server): The fallback enum member if conversion fails.
66+
67+
Returns:
68+
Server: Matching enum member or fallback if invalid.
69+
"""
70+
if value is None:
71+
return default
72+
73+
# Try to match directly by enum member
74+
if isinstance(value, cls):
75+
return value
76+
77+
# Handle integer or string conversion
78+
for member in cls:
79+
if str(member.value).lower() == str(value).lower() or member.name.lower() == str(value).lower():
80+
return member
81+
82+
# Fallback to provided default
83+
return default
84+
2785

2886
class Configuration(HttpClientConfiguration):
2987
"""A class used for configuring the SDK by a user.
@@ -129,3 +187,46 @@ def get_base_uri(self, server=Server.DEFAULT):
129187
130188
"""
131189
return self.environments[self.environment][server]
190+
191+
@classmethod
192+
def from_environment(cls, dotenv_path=None, **overrides):
193+
"""
194+
Creates a Configuration object using values from a .env file, environment variables, and optional overrides.
195+
196+
Args:
197+
dotenv_path (str, optional): Path to the .env file to load. If None, the default .env file is used.
198+
**overrides: Additional configuration values to override those loaded from the .env file and environment variables.
199+
200+
Returns:
201+
Configuration: A configuration object populated with the resolved values.
202+
"""
203+
204+
# load .env automatically
205+
load_dotenv(dotenv_path or None, override=True)
206+
207+
override_http_client_configuration = os.getenv('OVERRIDE_HTTP_CLIENT_CONFIGURATION', 'false').lower() == 'true'
208+
timeout = int(os.getenv('TIMEOUT', '60'))
209+
max_retries = int(os.getenv('MAX_RETRIES', '0'))
210+
backoff_factor = float(os.getenv('BACKOFF_FACTOR', '2'))
211+
statuses = os.getenv('RETRY_STATUSES', None)
212+
retry_statuses = [int(v.strip()) for v in statuses.split(',') if v.strip().isdigit()] if statuses else None
213+
methods = os.getenv('RETRY_METHODS', None)
214+
retry_methods = [v.strip() for v in methods.split(',') if v.strip()] if methods else None
215+
environment = Environment.from_value(os.getenv('ENVIRONMENT'), Environment.SANDBOX)
216+
217+
from paypalserversdk.http.auth.o_auth_2 import ClientCredentialsAuthCredentials
218+
# Preparing default configuration
219+
default_config = cls(
220+
override_http_client_configuration=override_http_client_configuration,
221+
timeout=timeout,
222+
max_retries=max_retries,
223+
backoff_factor=backoff_factor,
224+
retry_statuses=retry_statuses,
225+
retry_methods=retry_methods,
226+
environment=environment,
227+
proxy_settings=ProxySettings.from_environment(),
228+
logging_configuration=LoggingConfiguration.from_environment(),
229+
client_credentials_auth_credentials=ClientCredentialsAuthCredentials.from_environment()
230+
)
231+
232+
return default_config.clone_with(**overrides)

paypalserversdk/controllers/base_controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class BaseController(object):
3030

3131
@staticmethod
3232
def user_agent():
33-
return 'PayPal REST API Python SDK, Version: 2.0.0, on OS {os-info}'
33+
return 'PayPal REST API Python SDK, Version: 2.1.0, on OS {os-info}'
3434

3535
@staticmethod
3636
def user_agent_parameters():

0 commit comments

Comments
 (0)