Configuration API

Configuration Schema

from fastapi_payments.config.config_schema import PaymentConfig

# Example usage
config = PaymentConfig(**config_dict)

PaymentConfig

class fastapi_payments.config.config_schema.PaymentConfig(**data)[source]

Bases: BaseModel

Configuration for payment module.

Attributes:

providers

database

messaging

pricing

default_provider

retry_attempts

retry_delay

logging_level

debug

allowed_currencies

additional_settings

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Methods:

validate_default_provider(v, info)

Validate default provider exists in providers.

validate_logging_level(v)

Validate logging level.

Parameters:
providers: Dict[str, Any]
database: DatabaseConfig
messaging: MessagingConfig
pricing: PricingConfig
default_provider: str
retry_attempts: int
retry_delay: int
logging_level: str
debug: bool
allowed_currencies: List[str]
additional_settings: Dict[str, Any]
classmethod validate_default_provider(v, info)[source]

Validate default provider exists in providers.

classmethod validate_logging_level(v)[source]

Validate logging level.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

ProviderConfig

class fastapi_payments.config.config_schema.ProviderConfig(**data)[source]

Bases: BaseModel

Payment provider configuration.

Attributes:

api_key

api_secret

webhook_secret

sandbox_mode

additional_settings

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Parameters:
  • api_key (str)

  • api_secret (str | None)

  • webhook_secret (str | None)

  • sandbox_mode (bool)

  • additional_settings (Dict[str, Any])

api_key: str
api_secret: Optional[str]
webhook_secret: Optional[str]
sandbox_mode: bool
additional_settings: Dict[str, Any]
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

DatabaseConfig

class fastapi_payments.config.config_schema.DatabaseConfig(**data)[source]

Bases: BaseModel

Database configuration.

Attributes:

url

echo

pool_size

max_overflow

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Parameters:
url: str
echo: bool
pool_size: int
max_overflow: int
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

RabbitMQConfig

PricingConfig

class fastapi_payments.config.config_schema.PricingConfig(**data)[source]

Bases: BaseModel

Pricing configuration.

Attributes:

default_currency

default_pricing_model

round_to_decimal_places

allow_custom_pricing

tax

additional_settings

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Parameters:
  • default_currency (str)

  • default_pricing_model (str)

  • round_to_decimal_places (int)

  • allow_custom_pricing (bool)

  • tax (TaxConfig)

  • additional_settings (Dict[str, Any])

default_currency: str
default_pricing_model: str
round_to_decimal_places: int
allow_custom_pricing: bool
tax: TaxConfig
additional_settings: Dict[str, Any]
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

TaxConfig

class fastapi_payments.config.config_schema.TaxConfig(**data)[source]

Bases: BaseModel

Tax configuration.

Attributes:

default_rate

included_in_price

use_tax_service

tax_service_url

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Parameters:
  • default_rate (float)

  • included_in_price (bool)

  • use_tax_service (bool)

  • tax_service_url (str | None)

default_rate: float
included_in_price: bool
use_tax_service: bool
tax_service_url: Optional[str]
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Configuration Functions

load_config

fastapi_payments.config.settings.load_config(file_path=None, env_override=True, validate=True)[source]

Load and validate payment configuration.

Parameters:
  • file_path (Union[str, Path, None]) – Optional path to JSON configuration file

  • env_override (bool) – Whether to override with environment variables

  • validate (bool) – Whether to validate and return a PaymentConfig instance

Return type:

Union[PaymentConfig, Dict[str, Any]]

Returns:

PaymentConfig if validate=True, otherwise a configuration dictionary

Raises:

load_config_from_file

fastapi_payments.config.settings.load_config_from_file(file_path)[source]

Load configuration from a JSON file.

Parameters:

file_path (Union[str, Path]) – Path to JSON configuration file

Return type:

Dict[str, Any]

Returns:

Configuration dictionary

Raises:

load_config_from_env

fastapi_payments.config.settings.load_config_from_env()[source]

Load configuration from environment variables.

Environment variables should be prefixed with PAYMENT_ For nested keys, use double underscore as separator

Examples: - PAYMENT_DEFAULT_PROVIDER=stripe - PAYMENT_DATABASE__URL=postgresql://user:pass@localhost/db - PAYMENT_PROVIDERS__STRIPE__API_KEY=sk_test_123

Return type:

Dict[str, Any]

Returns:

Configuration dictionary

merge_configs

fastapi_payments.config.settings.merge_configs(base_config, override_config)[source]

Merge two configuration dictionaries with the override taking precedence.

Parameters:
  • base_config (Dict[str, Any]) – Base configuration

  • override_config (Dict[str, Any]) – Override configuration

Return type:

Dict[str, Any]

Returns:

Merged configuration dictionary