Metadata-Version: 2.4
Name: inpay-sdk
Version: 1.0.0
Summary: Official inPAY Python SDK — create invoices, check status, and verify webhooks for the inPAY payment platform (Uzbekistan).
Author: inPAY
License: MIT
Project-URL: Homepage, https://inpay.uz
Project-URL: Source, https://github.com/inpayuz/inpay-python
Project-URL: Changelog, https://github.com/inpayuz/inpay-python/blob/main/CHANGELOG.md
Keywords: inpay,payment,uzbekistan,click,payme,uzcard,humo,invoice,webhook
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
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: Typing :: Typed
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Dynamic: license-file

# inPAY Python SDK

Official Python SDK for the [inPAY](https://inpay.uz) payment platform (Uzbekistan).
One inPAY contract → accept **Click, Payme, UzCard/HUMO** with a few lines of code.

> Bitta inPAY shartnomasi bilan barcha to'lov usullarini qabul qiling.

## O'rnatish / Installation

```bash
pip install inpay-sdk
```

Talab: Python ≥ 3.8. Tashqi bog'liqliksiz (faqat standart kutubxona).

## Tez boshlash / Quick start

```python
from inpay import InPay

inpay = InPay(
    merchant_id=12345,          # kassa merchant_id
    bearer_token="xxxxxxxx",    # kassa bearer token
    webhook_secret="yyyyyyyy",  # webhook imzosi uchun
)

# 1) To'lov yaratish
invoice = inpay.create(
    amount=50000,                       # so'm (min 1000)
    callback_url="https://shop.uz/inpay/webhook",
    order_id="A-123",                   # sizning ichki reference
)

print(invoice.pay_url)   # foydalanuvchini shu manzilga yo'naltiring
```

`invoice`:

| Atribut | Izoh |
|---|---|
| `invoice.order_id` | inPAY buyurtma ID (16 hex) |
| `invoice.pay_url` | Universal checkout sahifasi |
| `invoice.pay_url_link` | So'ralgan usulga mos to'g'ridan havola |
| `invoice.pay_links` | `{"click": ..., "payme": ...}` to'g'ridan havolalar |

### To'g'ridan-to'g'ri bitta usul

```python
invoice = inpay.create(amount=50000, payment_method="click")  # "click"|"payme"|"myuzcard"
```

## 2) Holatni tekshirish / Status

```python
tx = inpay.status("a1b2c3d4e5f6a7b8")
if tx.is_paid:
    ...
# tx.status: "pending" | "success" | "failed"
```

## 3) Webhook (payment.success)

inPAY to'lov muvaffaqiyatli bo'lganda `callback_url`'ingizga POST yuboradi va uni
`X-InPAY-Signature` (HMAC-SHA256) bilan imzolaydi. SDK imzoni **constant-time** tekshiradi.

Flask misoli:

```python
from flask import Flask, request
from inpay import InPay
from inpay.exceptions import SignatureError

app = Flask(__name__)
inpay = InPay(merchant_id=12345, bearer_token="xxxxxxxx", webhook_secret="yyyyyyyy")

@app.post("/inpay/webhook")
def inpay_webhook():
    sig = request.headers.get("X-InPAY-Signature", "")
    try:
        tx = inpay.webhook().verify(request.get_data(as_text=True), sig)
    except SignatureError:
        return {"ok": False}, 401

    if tx.is_paid:
        # ⚠️ IDEMPOTENT bo'ling — takror kelishi mumkin
        # if already_paid(tx.order_id): return {"ok": True}
        # mark_paid(tx.order_id, tx.amount)
        ...
    return {"ok": True}
```

> **Xavfsizlik:** imzo tekshiruvidan o'tmagan webhook'ni HECH QACHON to'lov deb qabul
> qilmang.

## Xatolar / Errors

```python
from inpay.exceptions import ApiError, SignatureError, InPayError

try:
    inpay.create(amount=50000)
except ApiError as e:
    print(e.error_code)   # masalan "MERCHANT_INACTIVE", "AMOUNT_TOO_LOW"
```

## Litsenziya

MIT © inPAY
