Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Install deps
run: |
pip install -r requirements.txt
pip install -r test-requirements.txt
pip install "pytest>=7.2.2,<8.0.0"

- name: Run tests
run: pytest tests/
Expand Down
106 changes: 60 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,37 @@ The package is compatible with Python versions `3.7+`.
Install the package from PyPi using the following pip command:

```bash
pip install maxio-advanced-billing-sdk==7.0.1
pip install maxio-advanced-billing-sdk==8.0.0
```

You can also view the package at:
https://pypi.python.org/pypi/maxio-advanced-billing-sdk/7.0.1
https://pypi.python.org/pypi/maxio-advanced-billing-sdk/8.0.0

## Initialize the API Client

**_Note:_** Documentation for the client can be found [here.](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/client.md)
**_Note:_** Documentation for the client can be found [here.](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/client.md)

The following parameters are configurable for the API Client:

| Parameter | Type | Description |
| --- | --- | --- |
| site | `str` | The subdomain for your Advanced Billing site.<br>*Default*: `'subdomain'` |
| environment | `Environment` | The API environment. <br> **Default: `Environment.US`** |
| http_client_instance | `HttpClient` | The Http Client passed from the sdk user for making requests |
| http_client_instance | `Union[Session, HttpClientProvider]` | The Http Client passed from the sdk user for making requests |
| override_http_client_configuration | `bool` | The value which determines to override properties of the passed Http Client from the sdk user |
| http_call_back | `HttpCallBack` | The callback value that is invoked before and after an HTTP call is made to an endpoint |
| timeout | `float` | The value to use for connection timeout. <br> **Default: 120** |
| max_retries | `int` | The number of times to retry an endpoint call if it fails. <br> **Default: 0** |
| backoff_factor | `float` | A backoff factor to apply between attempts after the second try. <br> **Default: 2** |
| 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]** |
| retry_methods | `Array of string` | The http methods on which retry is to be done. <br> **Default: ['GET', 'PUT']** |
| proxy_settings | [`ProxySettings`](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/proxy-settings.md) | Optional proxy configuration to route HTTP requests through a proxy server. |
| basic_auth_credentials | [`BasicAuthCredentials`](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/auth/basic-authentication.md) | The credential object for Basic Authentication |
| proxy_settings | [`ProxySettings`](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/proxy-settings.md) | Optional proxy configuration to route HTTP requests through a proxy server. |
| basic_auth_credentials | [`BasicAuthCredentials`](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/auth/basic-authentication.md) | The credential object for Basic Authentication |

The API client can be initialized as follows:

### Code-Based Client Initialization

```python
from advancedbilling.advanced_billing_client import AdvancedBillingClient
from advancedbilling.configuration import Environment
Expand All @@ -74,6 +76,17 @@ client = AdvancedBillingClient(
)
```

### Environment-Based Client Initialization

```python
from advancedbilling.advanced_billing_client import AdvancedBillingClient

# Specify the path to your .env file if it’s located outside the project’s root directory.
client = AdvancedBillingClient.from_environment(dotenv_path='/path/to/.env')
```

See the [Environment-Based Client Initialization](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/environment-based-client-initialization.md) section for details.

## Environments

The SDK can be configured to use a different environment for making API calls. Available environments are:
Expand All @@ -89,58 +102,59 @@ The SDK can be configured to use a different environment for making API calls. A

This API uses the following authentication schemes.

* [`BasicAuth (Basic Authentication)`](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/auth/basic-authentication.md)
* [`BasicAuth (Basic Authentication)`](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/auth/basic-authentication.md)

## List of APIs

* [API Exports](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/api-exports.md)
* [Advance Invoice](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/advance-invoice.md)
* [Billing Portal](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/billing-portal.md)
* [Component Price Points](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/component-price-points.md)
* [Custom Fields](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/custom-fields.md)
* [Events-Based Billing Segments](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/events-based-billing-segments.md)
* [Payment Profiles](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/payment-profiles.md)
* [Product Families](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/product-families.md)
* [Product Price Points](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/product-price-points.md)
* [Proforma Invoices](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/proforma-invoices.md)
* [Reason Codes](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/reason-codes.md)
* [Referral Codes](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/referral-codes.md)
* [Sales Commissions](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/sales-commissions.md)
* [Subscription Components](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/subscription-components.md)
* [Subscription Groups](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/subscription-groups.md)
* [Subscription Group Invoice Account](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/subscription-group-invoice-account.md)
* [Subscription Group Status](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/subscription-group-status.md)
* [Subscription Invoice Account](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/subscription-invoice-account.md)
* [Subscription Notes](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/subscription-notes.md)
* [Subscription Products](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/subscription-products.md)
* [Subscription Status](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/subscription-status.md)
* [Coupons](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/coupons.md)
* [Components](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/components.md)
* [Customers](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/customers.md)
* [Events](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/events.md)
* [Insights](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/insights.md)
* [Invoices](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/invoices.md)
* [Offers](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/offers.md)
* [Products](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/products.md)
* [Sites](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/sites.md)
* [Subscriptions](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/subscriptions.md)
* [Webhooks](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/controllers/webhooks.md)
* [API Exports](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/api-exports.md)
* [Advance Invoice](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/advance-invoice.md)
* [Billing Portal](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/billing-portal.md)
* [Component Price Points](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/component-price-points.md)
* [Custom Fields](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/custom-fields.md)
* [Events-Based Billing Segments](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/events-based-billing-segments.md)
* [Payment Profiles](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/payment-profiles.md)
* [Product Families](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/product-families.md)
* [Product Price Points](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/product-price-points.md)
* [Proforma Invoices](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/proforma-invoices.md)
* [Reason Codes](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/reason-codes.md)
* [Referral Codes](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/referral-codes.md)
* [Sales Commissions](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/sales-commissions.md)
* [Subscription Components](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/subscription-components.md)
* [Subscription Groups](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/subscription-groups.md)
* [Subscription Group Invoice Account](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/subscription-group-invoice-account.md)
* [Subscription Group Status](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/subscription-group-status.md)
* [Subscription Invoice Account](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/subscription-invoice-account.md)
* [Subscription Notes](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/subscription-notes.md)
* [Subscription Products](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/subscription-products.md)
* [Subscription Status](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/subscription-status.md)
* [Coupons](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/coupons.md)
* [Components](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/components.md)
* [Customers](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/customers.md)
* [Events](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/events.md)
* [Insights](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/insights.md)
* [Invoices](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/invoices.md)
* [Offers](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/offers.md)
* [Products](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/products.md)
* [Sites](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/sites.md)
* [Subscriptions](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/subscriptions.md)
* [Webhooks](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/controllers/webhooks.md)

## SDK Infrastructure

### Configuration

* [ProxySettings](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/proxy-settings.md)
* [ProxySettings](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/proxy-settings.md)
* [Environment-Based Client Initialization](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/environment-based-client-initialization.md)

### HTTP

* [HttpResponse](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/http-response.md)
* [HttpRequest](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/http-request.md)
* [HttpResponse](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/http-response.md)
* [HttpRequest](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/http-request.md)

### Utilities

* [ApiHelper](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/api-helper.md)
* [HttpDateTime](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/http-date-time.md)
* [RFC3339DateTime](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/rfc3339-date-time.md)
* [UnixDateTime](https://www.github.com/maxio-com/ab-python-sdk/tree/7.0.1/doc/unix-date-time.md)
* [ApiHelper](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/api-helper.md)
* [HttpDateTime](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/http-date-time.md)
* [RFC3339DateTime](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/rfc3339-date-time.md)
* [UnixDateTime](https://www.github.com/maxio-com/ab-python-sdk/tree/8.0.0/doc/unix-date-time.md)

1 change: 1 addition & 0 deletions advancedbilling/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
'exceptions',
'http',
'models',
'utilities',
]
9 changes: 6 additions & 3 deletions advancedbilling/advanced_billing_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,11 @@ def __init__(self, http_client_instance=None,
.base_uri_executor(self.config.get_base_uri)\
.user_agent(BaseController.user_agent(), BaseController.user_agent_parameters())

self.auth_managers = {key: None for key in ['BasicAuth']}
self.auth_managers['BasicAuth'] = BasicAuth(
self.config.basic_auth_credentials)
self.auth_managers = {
'BasicAuth': BasicAuth(self.config.basic_auth_credentials)
}
self.global_configuration = self.global_configuration.auth_managers(self.auth_managers)

@classmethod
def from_environment(cls, dotenv_path=None, **overrides):
return cls(config=Configuration.from_environment(dotenv_path=dotenv_path, **overrides))
101 changes: 101 additions & 0 deletions advancedbilling/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
https://www.apimatic.io ).
"""

import os
from dotenv import load_dotenv
from advancedbilling.http.proxy_settings import ProxySettings
from enum import Enum
from advancedbilling.api_helper import APIHelper
from apimatic_core.http.configurations.http_client_configuration import HttpClientConfiguration
Expand All @@ -20,12 +23,66 @@ class Environment(Enum):
# Advanced Billing environment hosted in EU. Use only when you requested EU hosting for your AB account.
EU = 1

@classmethod
def from_value(cls, value, default=None):
"""
Convert a value (string or int) to an Environment enum member.

Args:
value (Union[str, int]): The value to convert.
default (Environment): The fallback enum member if conversion fails.

Returns:
Environment: Matching enum member or fallback if invalid.
"""
if value is None:
return default

# Try to match directly by enum member
if isinstance(value, cls):
return value

# Handle integer or string conversion
for member in cls:
if str(member.value).lower() == str(value).lower() or member.name.lower() == str(value).lower():
return member

# Fallback to provided default
return default


class Server(Enum):
"""An enum for API servers"""
PRODUCTION = 0
EBB = 1

@classmethod
def from_value(cls, value, default=None):
"""
Convert a value (string or int) to an Server enum member.

Args:
value (Union[str, int]): The value to convert.
default (Server): The fallback enum member if conversion fails.

Returns:
Server: Matching enum member or fallback if invalid.
"""
if value is None:
return default

# Try to match directly by enum member
if isinstance(value, cls):
return value

# Handle integer or string conversion
for member in cls:
if str(member.value).lower() == str(value).lower() or member.name.lower() == str(value).lower():
return member

# Fallback to provided default
return default


class Configuration(HttpClientConfiguration):
"""A class used for configuring the SDK by a user.
Expand Down Expand Up @@ -144,3 +201,47 @@ def get_base_uri(self, server=Server.PRODUCTION):
return APIHelper.append_url_with_template_parameters(
self.environments[self.environment][server], parameters
)

@classmethod
def from_environment(cls, dotenv_path=None, **overrides):
"""
Creates a Configuration object using values from a .env file, environment variables, and optional overrides.

Args:
dotenv_path (str, optional): Path to the .env file to load. If None, the default .env file is used.
**overrides: Additional configuration values to override those loaded from the .env file and environment variables.

Returns:
Configuration: A configuration object populated with the resolved values.
"""

# load .env automatically
load_dotenv(dotenv_path or None, override=True)

override_http_client_configuration = os.getenv('OVERRIDE_HTTP_CLIENT_CONFIGURATION', 'false').lower() == 'true'
timeout = int(os.getenv('TIMEOUT', '120'))
max_retries = int(os.getenv('MAX_RETRIES', '0'))
backoff_factor = float(os.getenv('BACKOFF_FACTOR', '2'))
statuses = os.getenv('RETRY_STATUSES', None)
retry_statuses = [int(v.strip()) for v in statuses.split(',') if v.strip().isdigit()] if statuses else None
methods = os.getenv('RETRY_METHODS', None)
retry_methods = [v.strip() for v in methods.split(',') if v.strip()] if methods else None
environment = Environment.from_value(os.getenv('ENVIRONMENT'), Environment.US)
site = os.getenv('SITE', 'subdomain')

from advancedbilling.http.auth.basic_auth import BasicAuthCredentials
# Preparing default configuration
default_config = cls(
override_http_client_configuration=override_http_client_configuration,
timeout=timeout,
max_retries=max_retries,
backoff_factor=backoff_factor,
retry_statuses=retry_statuses,
retry_methods=retry_methods,
environment=environment,
site=site,
proxy_settings=ProxySettings.from_environment(),
basic_auth_credentials=BasicAuthCredentials.from_environment()
)

return default_config.clone_with(**overrides)
5 changes: 2 additions & 3 deletions advancedbilling/controllers/advance_invoice_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def issue_advance_invoice(self,
"""Does a POST request to /subscriptions/{subscription_id}/advance_invoice/issue.json.

Generate an invoice in advance for a subscription's next renewal date.
[Please see our
[See our
docs](https://maxio.zendesk.com/hc/en-us/articles/24252026404749-Issue-
Invoice-In-Advance) for more information on advance invoices,
including eligibility on generating one; for the most part, they
Expand Down Expand Up @@ -144,8 +144,7 @@ def void_advance_invoice(self,
A `reason` is required in order to void, and the invoice must have an
open status. Voiding will cause any prepayments and credits that were
applied to the invoice to be returned to the subscription. For a full
overview of the impact of voiding, please [see our help
docs]($m/Invoice).
overview of the impact of voiding, [see our help docs]($m/Invoice).

Args:
subscription_id (int): The Chargify id of the subscription
Expand Down
Loading