Spaces:
Running
Running
| import time | |
| import requests | |
| class FlutterwaveIntegration: | |
| """ | |
| Pan-African payment processing. | |
| Works in: Nigeria, Ghana, South Africa, | |
| Kenya, Uganda, Tanzania, Rwanda, and more. | |
| """ | |
| BASE_URL = "https://api.flutterwave.com/v3" | |
| def __init__(self, secret_key: str): | |
| self.secret_key = secret_key | |
| self.headers = { | |
| "Authorization": f"Bearer {secret_key}", | |
| "Content-Type": "application/json" | |
| } | |
| def initiate_payment( | |
| self, | |
| amount: float, | |
| currency: str, | |
| customer_email: str, | |
| customer_phone: str, | |
| description: str, | |
| redirect_url: str | |
| ) -> dict: | |
| payload = { | |
| "tx_ref": f"senti_{int(time.time())}", | |
| "amount": amount, | |
| "currency": currency, | |
| "redirect_url": redirect_url, | |
| "customer": { | |
| "email": customer_email, | |
| "phone_number": customer_phone, | |
| "name": "Senti Customer" | |
| }, | |
| "customizations": { | |
| "title": "Senti Payment", | |
| "description": description, | |
| "logo": "https://senti.ai/logo.png" | |
| } | |
| } | |
| try: | |
| response = requests.post( | |
| f"{self.BASE_URL}/payments", | |
| json=payload, | |
| headers=self.headers, | |
| timeout=10 | |
| ) | |
| return response.json() | |
| except Exception as e: | |
| return {"status": "error", "message": str(e)} | |
| def get_transaction_status( | |
| self, transaction_id: str | |
| ) -> dict: | |
| try: | |
| response = requests.get( | |
| f"{self.BASE_URL}/transactions/{transaction_id}/verify", | |
| headers=self.headers, | |
| timeout=10 | |
| ) | |
| return response.json() | |
| except Exception as e: | |
| return {"status": "error", "message": str(e)} | |
| def get_supported_countries(self) -> list: | |
| return [ | |
| "NG", "GH", "ZA", "KE", "UG", | |
| "TZ", "RW", "ZM", "CM", "CI" | |
| ] | |