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
21 changes: 11 additions & 10 deletions docs/integrations/fedapay.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"]
),
Expand Down Expand Up @@ -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
)
Expand All @@ -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
},
Expand Down
21 changes: 12 additions & 9 deletions easyswitch/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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"
)
Expand Down