# mongolian-payment-pass

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

## Installation

```bash
pip install mongolian-payment-pass
```

## Usage

### Synchronous

```python
from mongolian_payment_pass import PassClient, PassConfig

client = PassClient(PassConfig(
    endpoint="https://api.pass.mn",
    ecommerce_token="your_token",
    callback="https://example.com/callback",
))

# Create a new order (amount is multiplied by 100 automatically)
result = client.create_order(1500)
print(result.order_id)
print(result.shop)

# Create order with callback query params
result = client.create_order(1500, callback_params={"ref": "order-123"})

# Check order status
status = client.inquiry_order(result.order_id)
print(status.status)       # "paid", "pending", "cancelled", "voided"
print(status.resp_code)

# Notify a phone number about an order
client.notify_order(result.order_id, "99112233")

# Cancel an order
client.cancel_order(result.order_id)

# Void an order
client.void_order(result.order_id)
```

### Asynchronous

```python
import asyncio
from mongolian_payment_pass import AsyncPassClient, PassConfig

async def main():
    async with AsyncPassClient(PassConfig(
        endpoint="https://api.pass.mn",
        ecommerce_token="your_token",
        callback="https://example.com/callback",
    )) as client:
        result = await client.create_order(1500)
        status = await client.inquiry_order(result.order_id)
        print(status.status)

asyncio.run(main())
```

### Webhook Parsing

```python
from mongolian_payment_pass import PassClient

# Parse incoming webhook payload (works as a static method)
webhook = PassClient.parse_webhook(request_body)
print(webhook.order_id)
print(webhook.operation)   # "payment" or "void"
print(webhook.is_success)
```

### Configuration from Environment Variables

```python
from mongolian_payment_pass import PassClient, load_config_from_env

client = PassClient(load_config_from_env())
```

Required environment variables:

| Variable               | Description                        |
|------------------------|------------------------------------|
| `PASS_ENDPOINT`        | Pass API base URL                  |
| `PASS_ECOMMERCE_TOKEN` | E-commerce token for authentication |
| `PASS_CALLBACK`        | Callback URL for order notifications |

### Status Constants

```python
from mongolian_payment_pass import (
    OrderInquiryStatusPaid,       # "paid"
    OrderInquiryStatusPending,    # "pending"
    OrderInquiryStatusCancelled,  # "cancelled"
    OrderInquiryStatusVoided,     # "voided"
    WebhookOperationPayment,      # "payment"
    WebhookOperationVoid,         # "void"
)
```

## License

MIT
