# OxaPay Python Client

[![PyPI version](https://badge.fury.io/py/oxapay.svg)](https://badge.fury.io/py/oxapay)
[![Python Version](https://img.shields.io/pypi/v/oxapay)](https://pypi.org/project/oxapay/)
[![License](https://img.shields.io/pypi/l/oxapay)](https://codeberg.org/TheKaram/PyOxapay/src/branch/main/LICENSE)

A fully-typed Python client for the [OxaPay](https://oxapay.com/) cryptocurrency payment gateway v1 API.

## Features

- 🚀 Async-first with sync wrapper
- 🔒 Full type hints & Pydantic models
- 🌐 Complete API coverage (Merchant, Payout, Swap, System)
- 🔄 FastAPI webhook integration

## Installation

```bash
pip install oxapay
```

For webhook handling:
```bash
pip install "oxapay[webhook]"
```

## Quick Start

### Create an Invoice

```python
import asyncio
from oxapay import OxaPayClient, CreateInvoiceRequest

async def main():
    async with OxaPayClient(merchant_api_key="your_key") as client:
        invoice = CreateInvoiceRequest(
            amount=100,
            currency="USD",
            order_id="order_123"
        )
        response = await client.create_invoice(invoice)
        print(f"Payment URL: {response.data.payment_url}")
        print(f"Track ID: {response.data.track_id}")

asyncio.run(main())
```

### Sync Client

```python
from oxapay.sync import SyncOxaPayClient, CreateInvoiceRequest

client = SyncOxaPayClient(merchant_api_key="your_key")
response = client.create_invoice(
    CreateInvoiceRequest(amount=100, currency="USD")
)
print(response.data.payment_url)
```

### Webhooks

```python
from fastapi import FastAPI
from oxapay.webhook import WebhookRouter, PaymentWebhookEvent

app = FastAPI()
webhook = WebhookRouter(
    app=app,
    merchant_api_key="your_key",
    path="/webhook"
)

@webhook.on_payment_paid
async def handle_payment(event: PaymentWebhookEvent):
    print(f"Payment received: {event.track_id}")
```

## API Coverage

- **Merchant**: Invoices, white-label, static wallets, payment info
- **Payout**: Send crypto, track payouts, balances
- **Swap**: Exchange rates, swap requests
- **System**: Prices, currencies, networks, status

## Examples

See the `examples/` directory for more detailed usage patterns.

## License

MIT License - see LICENSE file for details.
