# mongolian-payment-mongolchat

MongolChat payment gateway SDK for Python. Supports both synchronous and asynchronous usage.

## Installation

```bash
pip install mongolian-payment-mongolchat
```

## Usage

### Synchronous

```python
from mongolian_payment_mongolchat import MongolChatClient, MongolChatConfig, MchatGenerateQrInput, MchatProduct

client = MongolChatClient(MongolChatConfig(
    endpoint="https://api.mongolchat.mn",
    api_key="your_api_key",
    worker_key="your_worker_key",
    app_secret="your_app_secret",
    branch_no="001",
))

# Generate a QR code
qr = client.generate_qr(MchatGenerateQrInput(
    amount=5000,
    products=[MchatProduct(product_name="Coffee", quantity="1", price=5000, tag="food")],
    title="Coffee Shop",
    sub_title="Order #123",
    noat="123456",
    nhat="654321",
    ttd="789",
    reference_number="REF-001",
    expire_time="2026-12-31T23:59:59",
))

print(qr.qr)  # QR code string

# Check QR payment status
status = client.check_qr(qr.qr)
print(status.status)
```

### Asynchronous

```python
import asyncio
from mongolian_payment_mongolchat import AsyncMongolChatClient, MongolChatConfig, MchatGenerateQrInput, MchatProduct

async def main():
    async with AsyncMongolChatClient(MongolChatConfig(
        endpoint="https://api.mongolchat.mn",
        api_key="your_api_key",
        worker_key="your_worker_key",
        app_secret="your_app_secret",
        branch_no="001",
    )) as client:
        qr = await client.generate_qr(MchatGenerateQrInput(
            amount=5000,
            products=[MchatProduct(product_name="Coffee", quantity="1", price=5000, tag="food")],
            title="Coffee Shop",
            sub_title="Order #123",
            noat="123456",
            nhat="654321",
            ttd="789",
            reference_number="REF-001",
            expire_time="2026-12-31T23:59:59",
        ))

        status = await client.check_qr(qr.qr)
        print(status.status)

asyncio.run(main())
```

### Configuration from Environment Variables

```python
from mongolian_payment_mongolchat import MongolChatClient, load_config_from_env

client = MongolChatClient(load_config_from_env())
```

Required environment variables:

| Variable              | Description                                      |
|-----------------------|--------------------------------------------------|
| `MONGOLCHAT_ENDPOINT` | MongolChat API base URL                          |
| `MONGOLCHAT_API_KEY`  | API key for the `api-key` header                 |
| `MONGOLCHAT_WORKER_KEY` | Worker key for `Authorization: WorkerKey` header |
| `MONGOLCHAT_APP_SECRET` | Application secret                              |
| `MONGOLCHAT_BRANCH_NO`  | Branch number                                   |

## License

MIT
