File size: 1,836 Bytes
021e065
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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"
    ]