Skip to content

Commit 2b172cf

Browse files
authored
Merge pull request #41 from Borisw123/dev.borisw.fedapay
Update FedaPay Doc
2 parents 34ebcc6 + e254deb commit 2b172cf

File tree

1 file changed

+81
-82
lines changed

1 file changed

+81
-82
lines changed

docs/integrations/fedapay.md

Lines changed: 81 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ Create a `.env` file or set the following environment variables:
9494

9595
```bash
9696
# FedaPay Configuration
97-
FEDAPAY_API_KEY=sk_sandbox_your_api_key_here
98-
FEDAPAY_ENVIRONMENT=sandbox
99-
FEDAPAY_WEBHOOK_SECRET=your_webhook_secret_here
100-
FEDAPAY_CALLBACK_URL=https://your-domain.com/webhook/fedapay
97+
EASYSWITCH_FEDAPAY_SECRET_KEY=sk_sandbox_your_api_secret_here
98+
EASYSWITCH_FEDAPAY_ENVIRONMENT=sandbox
99+
EASYSWITCH_FEDAPAY_WEBHOOK_SECRET=your_webhook_secret_here
100+
EASYSWITCH_FEDAPAY_CALLBACK_URL=https://your-domain.com/webhook/fedapay
101101
```
102102

103103
### Authentication
@@ -106,7 +106,7 @@ FedaPay uses API key authentication. EasySwitch automaticaly set this for reques
106106

107107
```python
108108
headers = {
109-
'Authorization': f'Bearer {api_key}',
109+
'Authorization': f'Bearer {api_secret}',
110110
'Content-Type': 'application/json'
111111
}
112112
```
@@ -469,12 +469,16 @@ EasySwitch automatically handles webhook signature validation using FedaPay's si
469469
EasySwitch also provides methods to manage webhooks through the FedaPay API:
470470

471471
```python
472+
473+
import asyncio
474+
472475
# Get all webhooks
473-
webhooks_response = await client._get_integrator(Provider.FEDAPAY).get_all_webhooks()
474-
print(f"Total webhooks: {len(webhooks_response.webhooks)}")
476+
FedaPay = client._get_integrator(Provider.FEDAPAY)
477+
all_webhooks_response = asyncio.run(FedaPay.get_all_webhooks())
478+
print(f"Total Webhooks: {len(webhooks_response.webhooks)}")
475479

476480
# Get specific webhook details
477-
webhook_detail = await client._get_integrator(Provider.FEDAPAY).get_webhook_detail("webhook_id")
481+
webhook_detail = asyncio.run(FedaPay.get_webhook_detail("webhook_id"))
478482
print(f"Webhook URL: {webhook_detail.url}")
479483
print(f"Webhook enabled: {webhook_detail.enabled}")
480484
```
@@ -580,39 +584,31 @@ EasySwitch standardizes transaction statuses across all providers. Here's how Fe
580584

581585
## Error Handling
582586

583-
Proper error handling is crucial for a robust payment integration. EasySwitch provides specific exception types for different error scenarios:
587+
Proper error handling is crucial for a robust payment integration. EasySwitch provides specific exception types for common error scenarios, but note that this list is not exhaustive — additional exceptions may occur depending on your configuration, aggregator behavior, or network conditions.
584588

585589
```python
586590
from easyswitch.exceptions import (
587591
PaymentError,
588-
InsufficientFundsError,
589-
InvalidPhoneNumberError,
590592
NetworkError,
591593
AuthenticationError,
592-
ValidationError
594+
ValidationError,
595+
ConfigurationError,
596+
InvalidRequestError
593597
)
594598

595-
def process_payment_safely(payment_data):
599+
def process_payment_safely(transaction):
596600
"""Process payment with comprehensive error handling"""
597601
try:
598-
result = client.process_payment(payment_data)
599-
return result
600-
601-
except InsufficientFundsError:
602-
# Customer doesn't have enough funds
603-
return {
604-
'success': False,
605-
'error': 'Insufficient funds',
606-
'message': 'Please check your account balance and try again'
607-
}
602+
result = client.send_payment(transaction)
603+
return result
608604

609-
except InvalidPhoneNumberError:
610-
# Invalid phone number format
611-
return {
612-
'success': False,
613-
'error': 'Invalid phone number',
614-
'message': 'Please enter a valid phone number'
615-
}
605+
except ValidationError as e:
606+
# Invalid payment data
607+
return {
608+
'success': False,
609+
'error': 'Validation error',
610+
'message': str(e)
611+
}
616612

617613
except AuthenticationError:
618614
# API key issues
@@ -622,29 +618,37 @@ def process_payment_safely(payment_data):
622618
'message': 'Please check your API configuration'
623619
}
624620

625-
except ValidationError as e:
626-
# Invalid payment data
621+
except ConfigurationError:
622+
# Configuration issues
627623
return {
628624
'success': False,
629-
'error': 'Validation error',
630-
'message': str(e)
625+
'error': 'Configuration error',
626+
'message': 'Please check your SDK configuration'
631627
}
632628

633629
except NetworkError:
634-
# Network connectivity issues
635-
return {
636-
'success': False,
637-
'error': 'Network error',
638-
'message': 'Please check your internet connection and try again'
639-
}
630+
# Network connectivity issues
631+
return {
632+
'success': False,
633+
'error': 'Network error',
634+
'message': 'Please check your internet connection and try again'
635+
}
640636

641637
except PaymentError as e:
642-
# General payment error
643-
return {
644-
'success': False,
645-
'error': 'Payment error',
646-
'message': str(e)
647-
}
638+
# General payment error
639+
return {
640+
'success': False,
641+
'error': 'Payment error',
642+
'message': str(e)
643+
}
644+
645+
except InvalidRequestError as e:
646+
# Invalid request format
647+
return {
648+
'success': False,
649+
'error': 'Invalid request',
650+
'message': str(e)
651+
}
648652

649653
except Exception as e:
650654
# Unexpected error
@@ -655,16 +659,13 @@ def process_payment_safely(payment_data):
655659
}
656660
```
657661

658-
### Common Error Codes
662+
🔎 **Note**
663+
664+
The exceptions above cover the most common scenarios.
665+
Depending on the aggregator and your implementation, additional exceptions may be raised.
666+
Always include a generic Exception handler to gracefully catch unforeseen errors.
667+
For production systems, consider logging all errors for easier debugging and monitoring.
659668

660-
| Error Code | Description | Solution |
661-
|------------|-------------|----------|
662-
| `INSUFFICIENT_FUNDS` | Customer has insufficient balance | Ask customer to add funds |
663-
| `INVALID_PHONE` | Phone number format is invalid | Validate phone number format |
664-
| `NETWORK_ERROR` | Network connectivity issue | Retry with exponential backoff |
665-
| `AUTH_ERROR` | Authentication failed | Check API keys |
666-
| `VALIDATION_ERROR` | Invalid request data | Validate input parameters |
667-
| `TIMEOUT` | Request timed out | Implement retry logic |
668669

669670
## Testing
670671

@@ -739,14 +740,14 @@ logging.basicConfig(level=logging.INFO)
739740
logger = logging.getLogger(__name__)
740741

741742
class FedaPayIntegration:
742-
def __init__(self, api_key, environment="sandbox"):
743+
def __init__(self, api_secret, environment="sandbox"):
743744
"""Initialize FedaPay integration with EasySwitch"""
744745
self.config = {
745746
"debug": True,
746747
"default_provider": Provider.FEDAPAY,
747748
"providers": {
748749
Provider.FEDAPAY: {
749-
"api_secret": api_key,
750+
"api_secret": api_secret,
750751
"environment": environment,
751752
"timeout": 60,
752753
"callback_url": "https://your-domain.com/webhook/fedapay",
@@ -756,25 +757,28 @@ class FedaPayIntegration:
756757
}
757758
self.client = EasySwitch.from_dict(self.config)
758759

759-
def create_payment(self, amount, currency, description, customer_info, order_id=None):
760+
def create_payment(
761+
self,
762+
amount: float,
763+
currency: Currency,
764+
reason: str,
765+
customer: CustomerInfo,
766+
order_id=None
767+
):
760768
"""Create a payment transaction using EasySwitch"""
761769
try:
762770
# Create TransactionDetail object
763771
transaction = TransactionDetail(
764-
transaction_id="", # Will be generated
772+
transaction_id="TXN-123456", # Will be generated
765773
provider=Provider.FEDAPAY,
774+
status=TransactionStatus.PENDING,
766775
amount=amount,
767776
currency=currency,
768777
transaction_type=TransactionType.PAYMENT,
769-
customer=CustomerInfo(
770-
first_name=customer_info["first_name"],
771-
last_name=customer_info["last_name"],
772-
email=customer_info["email"],
773-
phone_number=customer_info["phone_number"]
774-
),
778+
customer=customer,
779+
reason=reason,
775780
metadata={
776-
"description": description,
777-
"order_id": order_id or f"ORD-{int(time.time())}"
781+
"order_id": order_id # Optional business identifier
778782
}
779783
)
780784

@@ -801,12 +805,12 @@ class FedaPayIntegration:
801805
def check_payment_status(self, transaction_id):
802806
"""Check payment status using EasySwitch"""
803807
try:
804-
status = self.client.check_status(transaction_id)
805-
logger.info(f"Payment status: {status}")
808+
result = self.client.check_status(transaction_id)
809+
logger.info(f"Payment status: {result}")
806810
return {
807811
'success': True,
808-
'status': status,
809-
'status_value': status.value
812+
'status': result,
813+
'status_value': status.result
810814
}
811815
except Exception as e:
812816
logger.error(f"Status check failed: {e}")
@@ -843,7 +847,7 @@ def main():
843847
"""Main function demonstrating FedaPay integration with EasySwitch"""
844848
# Initialize integration
845849
integration = FedaPayIntegration(
846-
api_key="sk_sandbox_your_test_key_here",
850+
api_secret="sk_sandbox_your_test_key_here",
847851
environment="sandbox"
848852
)
849853

@@ -852,22 +856,17 @@ def main():
852856
first_name="John",
853857
last_name="Doe",
854858
email="john.doe@example.com",
855-
phone_number="+22990000001" # Test number for success
859+
phone_number="+22990000001"
856860
)
857861

858862
# Create payment
859863
print("Creating payment with EasySwitch...")
860864
payment_result = integration.create_payment(
861-
amount=2500.0, # 25 XOF
865+
amount=2500.0,
862866
currency=Currency.XOF,
863-
description="Test Payment with EasySwitch",
864-
customer_info={
865-
"first_name": customer.first_name,
866-
"last_name": customer.last_name,
867-
"email": customer.email,
868-
"phone_number": customer.phone_number
869-
},
870-
order_id="TEST-001"
867+
reason="Test Payment with EasySwitch",
868+
customer=customer,
869+
order_id="ORDER-001"
871870
)
872871

873872
if payment_result['success']:

0 commit comments

Comments
 (0)