From fd8c877d0745e95326b028d22a50d6603d5d7a09 Mon Sep 17 00:00:00 2001 From: Koffi Boris Gilbride WOGLO Date: Fri, 3 Oct 2025 01:27:20 +0000 Subject: [PATCH 1/2] Refactor FedaPay integration to use 'first_name' and 'last_name' instead of 'firstname' and 'lastname; add status parameter for Transaction creation --- docs/integrations/fedapay.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) 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 }, From bdb87a979bca7d5bb6cc7b28963386507278c679 Mon Sep 17 00:00:00 2001 From: Koffi Boris Gilbride WOGLO Date: Fri, 3 Oct 2025 01:27:57 +0000 Subject: [PATCH 2/2] `Update easyswitch/conf/base.py to include ValidationInfo in validate_default_provider method and change validate_all to validate_default` --- easyswitch/conf/base.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) 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" )