Skip to content

Commit 34ebcc6

Browse files
authored
Merge pull request #40 from Borisw123/dev.borisw.fedapay
Update FedaPay Doc and Fixe Pydantic warnings
2 parents 6bfd3af + bdb87a9 commit 34ebcc6

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

docs/integrations/fedapay.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,13 @@ Initiate a payment transaction using EasySwitch's `TransactionDetail` class and
149149
transaction = TransactionDetail(
150150
transaction_id="TXN-123456", # Unique ID generated by your system
151151
provider=Provider.FEDAPAY,
152+
status=TransactionStatus.PENDING,
152153
amount=1000.0, # Amount in cents (10 XOF)
153154
currency=Currency.XOF,
154155
transaction_type=TransactionType.PAYMENT,
155156
customer=CustomerInfo(
156-
firstname="John",
157-
lastname="Doe",
157+
first_name="John",
158+
last_name="Doe",
158159
email="john.doe@email.com", # FedaPay doesn't support many customer with same email
159160
phone_number="+22990123456"
160161
),
@@ -557,8 +558,8 @@ The `CustomerInfo` class standardizes customer data across all providers:
557558
```python
558559
@dataclass
559560
class CustomerInfo:
560-
firstname: str
561-
lastname: str
561+
first_name: str
562+
last_name: str
562563
email: str
563564
phone_number: str
564565
id: Optional[str] = None
@@ -766,8 +767,8 @@ class FedaPayIntegration:
766767
currency=currency,
767768
transaction_type=TransactionType.PAYMENT,
768769
customer=CustomerInfo(
769-
firstname=customer_info["firstname"],
770-
lastname=customer_info["lastname"],
770+
first_name=customer_info["first_name"],
771+
last_name=customer_info["last_name"],
771772
email=customer_info["email"],
772773
phone_number=customer_info["phone_number"]
773774
),
@@ -848,8 +849,8 @@ def main():
848849

849850
# Test customer data
850851
customer = CustomerInfo(
851-
firstname="John",
852-
lastname="Doe",
852+
first_name="John",
853+
last_name="Doe",
853854
email="john.doe@example.com",
854855
phone_number="+22990000001" # Test number for success
855856
)
@@ -861,8 +862,8 @@ def main():
861862
currency=Currency.XOF,
862863
description="Test Payment with EasySwitch",
863864
customer_info={
864-
"firstname": customer.firstname,
865-
"lastname": customer.lastname,
865+
"first_name": customer.first_name,
866+
"last_name": customer.last_name,
866867
"email": customer.email,
867868
"phone_number": customer.phone_number
868869
},

easyswitch/conf/base.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pathlib import Path
88
from typing import Any, Dict, Optional, Type
99

10-
from pydantic import BaseModel, Field, field_validator, model_validator
10+
from pydantic import BaseModel, Field, field_validator, model_validator, ValidationInfo
1111

1212
from easyswitch.exceptions import ConfigurationError
1313
from easyswitch.types import Currency, Provider
@@ -61,7 +61,7 @@ class BaseConfigModel(BaseModel):
6161

6262
class Config:
6363
extra = 'forbid' # Undefined fields are not allowed
64-
validate_all = True
64+
validate_default = True
6565
use_enum_values = True
6666

6767

@@ -127,17 +127,20 @@ class RootConfig(BaseConfigModel):
127127
default_provider: Optional[Provider] = None
128128

129129
@field_validator('default_provider')
130-
def validate_default_provider(cls, v, values):
130+
@classmethod
131+
def validate_default_provider(cls, v, info: ValidationInfo):
131132
"""Ensure default provider is valid."""
132-
133+
133134
# Ensure default provider is in enabled providers
134-
if v is not None and 'providers' in values and v not in values['providers']:
135-
raise ValueError(
136-
f"Default provider {v} must be in enabled providers"
137-
)
135+
if v is not None:
136+
providers = info.data.get('providers')
137+
if providers and v not in providers:
138+
raise ValueError(
139+
f"Default provider {v} must be in enabled providers"
140+
)
138141

139142
# and in supported Providers
140-
if v not in Provider.__members__:
143+
if v is not None and v not in Provider.__members__:
141144
raise ValueError(
142145
f"Default provider {v} is not supported"
143146
)

0 commit comments

Comments
 (0)