Metadata-Version: 2.4
Name: afconwave
Version: 1.0.0
Summary: Official AfconWave Python SDK — Pan-African payments, payouts, crypto, refunds & disputes.
Author-email: AfconWave Team <dev@afconwave.com>
License: MIT License
        
        Copyright (c) 2026 AfconWave
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://docs.afconwave.com/sdks/python
Project-URL: Documentation, https://docs.afconwave.com
Project-URL: Repository, https://github.com/afconwave/afconwave-python
Project-URL: Issues, https://github.com/afconwave/afconwave-python/issues
Keywords: payments,payouts,fintech,africa,mobile-money,afconwave
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Office/Business :: Financial
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.25.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: responses>=0.24; extra == "dev"
Requires-Dist: build>=1.0; extra == "dev"
Requires-Dist: twine>=5.0; extra == "dev"
Dynamic: license-file

# afconwave — Official Python SDK

> The official Python client library for the AfconWave Payments API.

[![PyPI version](https://img.shields.io/pypi/v/afconwave.svg)](https://pypi.org/project/afconwave/)
[![Python](https://img.shields.io/badge/Python-3.8+-blue.svg)](https://www.python.org/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

---

## Features

- ✅ Python 3.8+ compatible
- 🌍 Payments, Payouts, and Refunds in one library
- 🔒 Secure API key handling
- 🔔 Webhook signature verification helper
- 🧪 Sandbox-ready with test keys

---

## Installation

```bash
pip install afconwave
```

---

## Quick Start

```python
from afconwave import AfconWave

afw = AfconWave(secret_key="sk_test_your_key_here")
```

---

## Usage Guide

### Create a Payment

```python
payment = afw.create_payment(
    amount=5000,            # Amount in minor units (5000 = 50 XAF)
    currency="XAF",
    description="Order #1234",
    callback_url="https://yoursite.com/payment/callback",
    customer={
        "name": "Jean Dupont",
        "email": "jean@example.com",
        "phone": "+237600000000",
    },
    metadata={"order_id": "ORD-1234"}
)

print(payment["checkout_url"])  # Redirect user here
print(payment["id"])            # e.g., pay_507f191e8180f
```

### Retrieve a Payment

```python
payment = afw.retrieve_payment("pay_507f191e8180f")

print(payment["status"])   # "pending" | "success" | "failed"
print(payment["amount"])
print(payment["paid_at"])
```

### Create a Payout

```python
payout = afw.create_payout(
    amount=10000,
    currency="XAF",
    recipient={
        "phone": "+237600000001",
        "network": "MTN",  # "MTN" | "ORANGE" | "MOOV" | "WAVE"
        "name": "Marie Kamga",
    },
    reference="PAYOUT-REF-001"
)

print(payout["status"])  # "pending" | "success" | "failed"
```

### List Payments

```python
result = afw.list_payments(limit=20, status="success")

for payment in result["data"]:
    print(payment["id"], payment["amount"], payment["status"])
```

---

## Webhook Verification

Verify that incoming webhooks are genuinely from AfconWave:

```python
import hashlib
import hmac
from flask import Flask, request, abort

app = Flask(__name__)
WEBHOOK_SECRET = "your_webhook_secret"

@app.route("/webhooks/afconwave", methods=["POST"])
def handle_webhook():
    signature = request.headers.get("X-AfconWave-Signature", "")
    payload = request.get_data(as_text=True)

    expected = hmac.new(
        WEBHOOK_SECRET.encode(),
        payload.encode(),
        hashlib.sha256
    ).hexdigest()

    if not hmac.compare_digest(expected, signature):
        abort(400, "Invalid signature")

    event = request.get_json()

    if event["event"] == "payment.success":
        print("Payment received:", event["data"]["id"])
    elif event["event"] == "payment.failed":
        print("Payment failed")
    elif event["event"] == "payout.success":
        print("Payout delivered")

    return "OK", 200
```

---

## Error Handling

```python
from afconwave import AfconWave, AfconWaveError

afw = AfconWave(secret_key="sk_test_...")

try:
    payment = afw.create_payment(amount=5000, currency="XAF", callback_url="...")
except AfconWaveError as e:
    print(f"API Error {e.status_code}: {e.message}")
except Exception as e:
    print(f"Unexpected error: {e}")
```

---

## Configuration

| Parameter | Type | Default | Description |
|---|---|---|---|
| `secret_key` | `str` | **required** | Your AfconWave secret API key |
| `base_url` | `str` | `https://api.afconwave.com/v1` | API base URL |
| `timeout` | `int` | `30` | Request timeout (seconds) |

---

## Sandbox / Testing

Use test keys prefixed with `sk_test_` for sandbox mode. No real transactions occur.

```python
afw = AfconWave(secret_key="sk_test_...")
```

---

## Django / Flask Integration

### Django (example view)

```python
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from afconwave import AfconWave

afw = AfconWave(secret_key="sk_live_...")

def create_checkout(request):
    payment = afw.create_payment(
        amount=int(request.POST["amount"]),
        currency="XAF",
        callback_url="https://yoursite.com/payment/success",
    )
    return JsonResponse({"checkout_url": payment["checkout_url"]})
```

---

## Documentation

Full API documentation: [docs.afconwave.com](https://docs.afconwave.com)

---

## License

MIT © AfconWave
