diff --git a/docs/integrations/fedapay.md b/docs/integrations/fedapay.md index 0dd4367..8782755 100644 --- a/docs/integrations/fedapay.md +++ b/docs/integrations/fedapay.md @@ -149,12 +149,13 @@ Initiate a payment transaction using EasySwitch's `TransactionDetail` class and transaction = TransactionDetail( transaction_id="TXN-123456", # Unique ID generated by your system provider=Provider.FEDAPAY, + status=TransactionStatus.PENDING, amount=1000.0, # Amount in cents (10 XOF) currency=Currency.XOF, transaction_type=TransactionType.PAYMENT, customer=CustomerInfo( - firstname="John", - lastname="Doe", + first_name="John", + last_name="Doe", email="john.doe@email.com", # FedaPay doesn't support many customer with same email phone_number="+22990123456" ), @@ -557,8 +558,8 @@ The `CustomerInfo` class standardizes customer data across all providers: ```python @dataclass class CustomerInfo: - firstname: str - lastname: str + first_name: str + last_name: str email: str phone_number: str id: Optional[str] = None @@ -766,8 +767,8 @@ class FedaPayIntegration: currency=currency, transaction_type=TransactionType.PAYMENT, customer=CustomerInfo( - firstname=customer_info["firstname"], - lastname=customer_info["lastname"], + first_name=customer_info["first_name"], + last_name=customer_info["last_name"], email=customer_info["email"], phone_number=customer_info["phone_number"] ), @@ -848,8 +849,8 @@ def main(): # Test customer data customer = CustomerInfo( - firstname="John", - lastname="Doe", + first_name="John", + last_name="Doe", email="john.doe@example.com", phone_number="+22990000001" # Test number for success ) @@ -861,8 +862,8 @@ def main(): currency=Currency.XOF, description="Test Payment with EasySwitch", customer_info={ - "firstname": customer.firstname, - "lastname": customer.lastname, + "first_name": customer.first_name, + "last_name": customer.last_name, "email": customer.email, "phone_number": customer.phone_number }, diff --git a/easyswitch/conf/base.py b/easyswitch/conf/base.py index 9f9945f..86a1207 100644 --- a/easyswitch/conf/base.py +++ b/easyswitch/conf/base.py @@ -7,7 +7,7 @@ from pathlib import Path from typing import Any, Dict, Optional, Type -from pydantic import BaseModel, Field, field_validator, model_validator +from pydantic import BaseModel, Field, field_validator, model_validator, ValidationInfo from easyswitch.exceptions import ConfigurationError from easyswitch.types import Currency, Provider @@ -61,7 +61,7 @@ class BaseConfigModel(BaseModel): class Config: extra = 'forbid' # Undefined fields are not allowed - validate_all = True + validate_default = True use_enum_values = True @@ -127,17 +127,20 @@ class RootConfig(BaseConfigModel): default_provider: Optional[Provider] = None @field_validator('default_provider') - def validate_default_provider(cls, v, values): + @classmethod + def validate_default_provider(cls, v, info: ValidationInfo): """Ensure default provider is valid.""" - + # Ensure default provider is in enabled providers - if v is not None and 'providers' in values and v not in values['providers']: - raise ValueError( - f"Default provider {v} must be in enabled providers" - ) + if v is not None: + providers = info.data.get('providers') + if providers and v not in providers: + raise ValueError( + f"Default provider {v} must be in enabled providers" + ) # and in supported Providers - if v not in Provider.__members__: + if v is not None and v not in Provider.__members__: raise ValueError( f"Default provider {v} is not supported" )