uzpay 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- uzpay-0.1.0/.gitattributes +1 -0
- uzpay-0.1.0/.github/ISSUE_TEMPLATE/bug_report.md +18 -0
- uzpay-0.1.0/.github/workflows/publish.yml +44 -0
- uzpay-0.1.0/.github/workflows/tests.yml +60 -0
- uzpay-0.1.0/.gitignore +9 -0
- uzpay-0.1.0/CHANGELOG.md +14 -0
- uzpay-0.1.0/CONTRIBUTING.md +32 -0
- uzpay-0.1.0/LICENSE +21 -0
- uzpay-0.1.0/PKG-INFO +204 -0
- uzpay-0.1.0/README.md +179 -0
- uzpay-0.1.0/examples/django_demo/README.md +43 -0
- uzpay-0.1.0/examples/django_demo/demo/__init__.py +0 -0
- uzpay-0.1.0/examples/django_demo/demo/settings.py +52 -0
- uzpay-0.1.0/examples/django_demo/demo/urls.py +12 -0
- uzpay-0.1.0/examples/django_demo/demo/wsgi.py +6 -0
- uzpay-0.1.0/examples/django_demo/manage.py +9 -0
- uzpay-0.1.0/examples/django_demo/shop/__init__.py +0 -0
- uzpay-0.1.0/examples/django_demo/shop/management/__init__.py +0 -0
- uzpay-0.1.0/examples/django_demo/shop/management/commands/__init__.py +0 -0
- uzpay-0.1.0/examples/django_demo/shop/management/commands/create_orders.py +17 -0
- uzpay-0.1.0/examples/django_demo/shop/migrations/0001_initial.py +24 -0
- uzpay-0.1.0/examples/django_demo/shop/migrations/__init__.py +0 -0
- uzpay-0.1.0/examples/django_demo/shop/models.py +13 -0
- uzpay-0.1.0/examples/django_demo/shop/payments.py +37 -0
- uzpay-0.1.0/examples/django_demo/shop/templates/shop/index.html +28 -0
- uzpay-0.1.0/examples/django_demo/shop/templates/shop/order.html +23 -0
- uzpay-0.1.0/examples/django_demo/shop/views.py +27 -0
- uzpay-0.1.0/pyproject.toml +39 -0
- uzpay-0.1.0/src/uzpay/__init__.py +12 -0
- uzpay-0.1.0/src/uzpay/click.py +205 -0
- uzpay-0.1.0/src/uzpay/contrib/__init__.py +0 -0
- uzpay-0.1.0/src/uzpay/contrib/django/__init__.py +1 -0
- uzpay-0.1.0/src/uzpay/contrib/django/apps.py +8 -0
- uzpay-0.1.0/src/uzpay/contrib/django/migrations/0001_initial.py +35 -0
- uzpay-0.1.0/src/uzpay/contrib/django/migrations/__init__.py +0 -0
- uzpay-0.1.0/src/uzpay/contrib/django/models.py +34 -0
- uzpay-0.1.0/src/uzpay/contrib/django/store.py +49 -0
- uzpay-0.1.0/src/uzpay/contrib/django/views.py +41 -0
- uzpay-0.1.0/src/uzpay/core.py +159 -0
- uzpay-0.1.0/src/uzpay/payme.py +303 -0
- uzpay-0.1.0/tests/__init__.py +0 -0
- uzpay-0.1.0/tests/django_urls.py +19 -0
- uzpay-0.1.0/tests/helpers.py +61 -0
- uzpay-0.1.0/tests/settings.py +7 -0
- uzpay-0.1.0/tests/test_click.py +113 -0
- uzpay-0.1.0/tests/test_django.py +52 -0
- uzpay-0.1.0/tests/test_payme.py +160 -0
- uzpay-0.1.0/tools/payme_check.py +192 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* text=auto eol=lf
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug report / Xato haqida
|
|
3
|
+
about: Something does not work as the Click or Payme docs say
|
|
4
|
+
labels: bug
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
**Provider:** Click / Payme
|
|
8
|
+
|
|
9
|
+
**What happened / Nima bo'ldi:**
|
|
10
|
+
|
|
11
|
+
**Request and response** (remove keys, card numbers and personal data):
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
**Expected / Kutilgan natija:**
|
|
17
|
+
|
|
18
|
+
**Versions:** uzpay ..., Python ..., Django ...
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
name: publish
|
|
2
|
+
|
|
3
|
+
# Publishing a GitHub release (tag vX.Y.Z) builds the package and uploads it to PyPI
|
|
4
|
+
# with trusted publishing: no API token is stored anywhere.
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
release:
|
|
8
|
+
types: [published]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-python@v5
|
|
16
|
+
with:
|
|
17
|
+
python-version: "3.12"
|
|
18
|
+
- name: Check the tag matches the package version
|
|
19
|
+
run: |
|
|
20
|
+
version=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
|
|
21
|
+
test "v$version" = "${GITHUB_REF_NAME}" || { echo "tag ${GITHUB_REF_NAME} != v$version"; exit 1; }
|
|
22
|
+
- run: pip install build twine pytest pytest-django django
|
|
23
|
+
- run: pip install -e . && pytest -q
|
|
24
|
+
- run: python -m build
|
|
25
|
+
- run: twine check --strict dist/*
|
|
26
|
+
- uses: actions/upload-artifact@v4
|
|
27
|
+
with:
|
|
28
|
+
name: dist
|
|
29
|
+
path: dist/
|
|
30
|
+
|
|
31
|
+
pypi:
|
|
32
|
+
needs: build
|
|
33
|
+
runs-on: ubuntu-latest
|
|
34
|
+
environment:
|
|
35
|
+
name: pypi
|
|
36
|
+
url: https://pypi.org/project/uzpay/
|
|
37
|
+
permissions:
|
|
38
|
+
id-token: write
|
|
39
|
+
steps:
|
|
40
|
+
- uses: actions/download-artifact@v4
|
|
41
|
+
with:
|
|
42
|
+
name: dist
|
|
43
|
+
path: dist/
|
|
44
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
name: tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
fail-fast: false
|
|
13
|
+
matrix:
|
|
14
|
+
include:
|
|
15
|
+
- python: "3.10"
|
|
16
|
+
django: "4.2"
|
|
17
|
+
- python: "3.11"
|
|
18
|
+
django: "5.1"
|
|
19
|
+
- python: "3.12"
|
|
20
|
+
django: "5.2"
|
|
21
|
+
- python: "3.13"
|
|
22
|
+
django: "5.2"
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
|
+
- uses: actions/setup-python@v5
|
|
26
|
+
with:
|
|
27
|
+
python-version: ${{ matrix.python }}
|
|
28
|
+
- run: pip install -e . "django~=${{ matrix.django }}.0" pytest pytest-django
|
|
29
|
+
- run: pytest -q
|
|
30
|
+
|
|
31
|
+
core-without-django:
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
steps:
|
|
34
|
+
- uses: actions/checkout@v4
|
|
35
|
+
- uses: actions/setup-python@v5
|
|
36
|
+
with:
|
|
37
|
+
python-version: "3.12"
|
|
38
|
+
- run: pip install -e . pytest
|
|
39
|
+
- run: pytest -q -p no:django tests/test_click.py tests/test_payme.py
|
|
40
|
+
|
|
41
|
+
payme-check:
|
|
42
|
+
name: payme_check.py against the demo
|
|
43
|
+
runs-on: ubuntu-latest
|
|
44
|
+
steps:
|
|
45
|
+
- uses: actions/checkout@v4
|
|
46
|
+
- uses: actions/setup-python@v5
|
|
47
|
+
with:
|
|
48
|
+
python-version: "3.12"
|
|
49
|
+
- run: pip install -e ".[django]"
|
|
50
|
+
- name: Start demo shop
|
|
51
|
+
working-directory: examples/django_demo
|
|
52
|
+
env:
|
|
53
|
+
PAYME_KEY: ci-key
|
|
54
|
+
PAYME_MERCHANT_ID: ci
|
|
55
|
+
run: |
|
|
56
|
+
python manage.py migrate -v0
|
|
57
|
+
echo "ORDERS=$(python manage.py create_orders 3 --amount 1000)" >> "$GITHUB_ENV"
|
|
58
|
+
python manage.py runserver 8040 --noreload > server.log 2>&1 &
|
|
59
|
+
sleep 3
|
|
60
|
+
- run: python tools/payme_check.py http://127.0.0.1:8040/pay/payme/ --key ci-key --orders "$ORDERS" --amount 1000
|
uzpay-0.1.0/.gitignore
ADDED
uzpay-0.1.0/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 — 2026-12-06
|
|
4
|
+
|
|
5
|
+
First release.
|
|
6
|
+
|
|
7
|
+
- Click SHOP API: checkout links, Prepare / Complete with signature check, all error codes.
|
|
8
|
+
- Payme Merchant API: checkout links and all six methods (`CheckPerformTransaction`, `CreateTransaction`,
|
|
9
|
+
`PerformTransaction`, `CancelTransaction`, `CheckTransaction`, `GetStatement`), 12-hour timeout,
|
|
10
|
+
refunds, one active transaction per order, localized error messages.
|
|
11
|
+
- `OrderHandler` hooks, `Store` interface, `MemoryStore`.
|
|
12
|
+
- Django app: `PaymentTransaction` model, `DjangoStore` with row locking, `click_view` / `payme_view`.
|
|
13
|
+
- `tools/payme_check.py`: 32-scenario Payme protocol check for any endpoint.
|
|
14
|
+
- Demo shop in `examples/django_demo`.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Contributing / Hissa qo'shish
|
|
2
|
+
|
|
3
|
+
Thanks for helping! Rahmat!
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
git clone https://github.com/hamidillomannopov-stack/uzpay
|
|
9
|
+
cd uzpay
|
|
10
|
+
python -m venv .venv && . .venv/bin/activate # Windows: .venv\Scripts\activate
|
|
11
|
+
pip install -e ".[test]"
|
|
12
|
+
pytest
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Rules
|
|
16
|
+
|
|
17
|
+
- The core (`src/uzpay/*.py`) stays **dependency-free**. Framework code goes in `src/uzpay/contrib/`.
|
|
18
|
+
- Every behaviour change comes with a test. Protocol changes should cite the provider's docs in the PR.
|
|
19
|
+
- Never put real keys, card numbers or customer data in issues, tests or examples.
|
|
20
|
+
- Issues and PRs in English, O'zbekcha or Русский are all welcome.
|
|
21
|
+
|
|
22
|
+
## Good first issues
|
|
23
|
+
|
|
24
|
+
- Flask / FastAPI helpers in `contrib/`
|
|
25
|
+
- A `click_check.py` tool like `tools/payme_check.py`
|
|
26
|
+
- Uzum Bank / Paynet providers
|
|
27
|
+
- Payme receipts (fiscal data) support
|
|
28
|
+
|
|
29
|
+
## Security
|
|
30
|
+
|
|
31
|
+
Found a way to fake a payment? Please do **not** open a public issue. Use GitHub's
|
|
32
|
+
"Report a vulnerability" button on the Security tab instead.
|
uzpay-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hamidillo Mannopov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
uzpay-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: uzpay
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Click and Payme merchant APIs for Python: checkout links, webhook handling, Django integration. No dependencies.
|
|
5
|
+
Project-URL: Homepage, https://github.com/hamidillomannopov-stack/uzpay
|
|
6
|
+
Project-URL: Issues, https://github.com/hamidillomannopov-stack/uzpay/issues
|
|
7
|
+
Project-URL: Changelog, https://github.com/hamidillomannopov-stack/uzpay/blob/main/CHANGELOG.md
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: click,django,merchant-api,paycom,payme,payments,uzbekistan
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Framework :: Django
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Provides-Extra: django
|
|
19
|
+
Requires-Dist: django>=4.2; extra == 'django'
|
|
20
|
+
Provides-Extra: test
|
|
21
|
+
Requires-Dist: django>=4.2; extra == 'test'
|
|
22
|
+
Requires-Dist: pytest-django>=4.5; extra == 'test'
|
|
23
|
+
Requires-Dist: pytest>=7; extra == 'test'
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# uzpay
|
|
27
|
+
|
|
28
|
+
[](https://github.com/hamidillomannopov-stack/uzpay/actions/workflows/tests.yml)
|
|
29
|
+
[](https://github.com/hamidillomannopov-stack/uzpay/blob/main/LICENSE)
|
|
30
|
+
|
|
31
|
+
**Click and Payme for Python, done right.** Payment links and the merchant-side webhook
|
|
32
|
+
protocols for Uzbekistan's two main payment systems, with a ready Django integration.
|
|
33
|
+
|
|
34
|
+
## Why uzpay
|
|
35
|
+
|
|
36
|
+
- **Both providers, one API.** Click and Payme share the same `OrderHandler` and the same transaction
|
|
37
|
+
table, so adding the second provider is three lines, not a second integration.
|
|
38
|
+
- **A protocol checker you can point at production.** `tools/payme_check.py` plays Payme and runs 32
|
|
39
|
+
scenarios against any endpoint, written with uzpay or not.
|
|
40
|
+
- **Nothing to install.** The core is pure standard library.
|
|
41
|
+
|
|
42
|
+
## Features
|
|
43
|
+
|
|
44
|
+
- No dependencies in the core: works with Django, FastAPI, Flask or plain WSGI.
|
|
45
|
+
- Full protocol: Click Prepare/Complete with signature check; all six Payme Merchant API methods,
|
|
46
|
+
including the 12-hour timeout, idempotent retries, cancellations and `GetStatement`.
|
|
47
|
+
- You write three small methods ("how much is this order", "it's paid", optionally "it's cancelled").
|
|
48
|
+
uzpay keeps the transaction state machine.
|
|
49
|
+
- Tested: 31 unit tests plus a 32-scenario HTTP check of the Payme protocol.
|
|
50
|
+
|
|
51
|
+
[O'zbekcha qo'llanma pastda](#ozbekcha)
|
|
52
|
+
|
|
53
|
+
## Install
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install uzpay # core
|
|
57
|
+
pip install "uzpay[django]" # with the Django app
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## 1. Tell uzpay about your orders
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from uzpay import OrderHandler
|
|
64
|
+
|
|
65
|
+
class ShopOrders(OrderHandler):
|
|
66
|
+
def get_amount(self, order_id):
|
|
67
|
+
order = Order.objects.filter(pk=order_id).first()
|
|
68
|
+
return order.total if order else None # so'm; None = no such order
|
|
69
|
+
|
|
70
|
+
def is_payable(self, order_id):
|
|
71
|
+
return Order.objects.filter(pk=order_id, status="new").exists()
|
|
72
|
+
|
|
73
|
+
def on_paid(self, order_id, tx):
|
|
74
|
+
Order.objects.filter(pk=order_id).update(status="paid")
|
|
75
|
+
|
|
76
|
+
def on_cancelled(self, order_id, tx): # optional
|
|
77
|
+
...
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## 2. Configure the providers
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from uzpay import Click, Payme
|
|
84
|
+
from uzpay.contrib.django.store import DjangoStore # or MemoryStore / your own Store
|
|
85
|
+
|
|
86
|
+
click = Click(service_id=CLICK_SERVICE_ID, merchant_id=CLICK_MERCHANT_ID,
|
|
87
|
+
secret_key=CLICK_SECRET_KEY, orders=ShopOrders(), store=DjangoStore())
|
|
88
|
+
|
|
89
|
+
payme = Payme(merchant_id=PAYME_MERCHANT_ID, key=PAYME_KEY,
|
|
90
|
+
orders=ShopOrders(), store=DjangoStore(),
|
|
91
|
+
test=False) # True -> test.paycom.uz
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## 3. Send the customer to pay
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
click.checkout_url(order.pk, order.total, return_url="https://shop.uz/thanks")
|
|
98
|
+
payme.checkout_url(order.pk, order.total, return_url="https://shop.uz/thanks", lang="uz")
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Amounts are always in **so'm**. uzpay converts to tiyin for Payme.
|
|
102
|
+
|
|
103
|
+
## 4. Receive the webhooks
|
|
104
|
+
|
|
105
|
+
### Django
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
# settings.py
|
|
109
|
+
INSTALLED_APPS += ["uzpay.contrib.django"] # then: python manage.py migrate
|
|
110
|
+
|
|
111
|
+
# urls.py
|
|
112
|
+
from uzpay.contrib.django.views import click_view, payme_view
|
|
113
|
+
|
|
114
|
+
urlpatterns += [
|
|
115
|
+
path("pay/click/", click_view(click)), # set as both Prepare URL and Complete URL in Click
|
|
116
|
+
path("pay/payme/", payme_view(payme)), # set as the endpoint in the Payme cabinet
|
|
117
|
+
]
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
The views run inside `transaction.atomic()` and lock the transaction row, so parallel retries are safe.
|
|
121
|
+
Transactions show up in the `PaymentTransaction` model.
|
|
122
|
+
|
|
123
|
+
### FastAPI (or anything else)
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
@app.post("/pay/click")
|
|
127
|
+
async def click_hook(request: Request):
|
|
128
|
+
return click.handle(dict(await request.form()))
|
|
129
|
+
|
|
130
|
+
@app.post("/pay/payme")
|
|
131
|
+
async def payme_hook(request: Request):
|
|
132
|
+
return payme.handle(await request.body(), request.headers.get("authorization"))
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Outside Django, implement `uzpay.Store` (7 short methods) on top of your database, or use
|
|
136
|
+
`MemoryStore` for tests.
|
|
137
|
+
|
|
138
|
+
## Options
|
|
139
|
+
|
|
140
|
+
| Option | Default | Meaning |
|
|
141
|
+
|---|---|---|
|
|
142
|
+
| `Payme(account_field=...)` | `"order_id"` | Name of the account field configured in your Payme cabinet |
|
|
143
|
+
| `Payme(test=True)` | `False` | Checkout links point to `test.paycom.uz` |
|
|
144
|
+
| `OrderHandler.can_cancel_paid` | `False` | Allow Payme to cancel (refund) a paid transaction |
|
|
145
|
+
| `Click(merchant_user_id=...)` | `None` | Added to checkout links if your Click service requires it |
|
|
146
|
+
|
|
147
|
+
## Error codes
|
|
148
|
+
|
|
149
|
+
uzpay answers with the codes each provider expects:
|
|
150
|
+
|
|
151
|
+
- **Click:** `-1` bad signature, `-2` wrong amount, `-4` already paid, `-5` order not found,
|
|
152
|
+
`-6` transaction not found, `-7` `on_paid` raised, `-8` bad request, `-9` cancelled.
|
|
153
|
+
- **Payme:** `-32504` bad key, `-31001` wrong amount, `-31003` transaction not found,
|
|
154
|
+
`-31007` cannot cancel, `-31008` cannot perform (state or timeout), `-31050` order not found,
|
|
155
|
+
`-31051` order already paid, `-31052` order is being paid in another transaction.
|
|
156
|
+
|
|
157
|
+
## Check any Payme endpoint
|
|
158
|
+
|
|
159
|
+
`tools/payme_check.py` plays the role of Payme and runs 32 sandbox-style scenarios (bad key,
|
|
160
|
+
wrong amount, unknown order, retries, refunds, cancellations, 12-hour timeout, `GetStatement`)
|
|
161
|
+
against a live URL. It works with any Merchant API implementation, not only uzpay, and needs only
|
|
162
|
+
the standard library:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
python tools/payme_check.py https://shop.uz/pay/payme/ --key TEST_KEY --orders 11,12,13 --amount 1000
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
A runnable demo shop lives in [examples/django_demo](https://github.com/hamidillomannopov-stack/uzpay/tree/main/examples/django_demo).
|
|
169
|
+
|
|
170
|
+
## Development
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
pip install -e ".[test]"
|
|
174
|
+
pytest
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## O'zbekcha
|
|
180
|
+
|
|
181
|
+
**uzpay** — Click va Payme to'lov tizimlarini Python loyihangizga ulash uchun kutubxona.
|
|
182
|
+
|
|
183
|
+
**Nima qiladi:**
|
|
184
|
+
- to'lov havolasini yaratadi (`checkout_url`);
|
|
185
|
+
- Click va Payme serverlaridan keladigan so'rovlarni to'liq qayta ishlaydi: imzo va kalitni tekshiradi,
|
|
186
|
+
tranzaksiya holatini saqlaydi, takroriy so'rovlarga to'g'ri javob beradi, 12 soatlik muddatni kuzatadi;
|
|
187
|
+
- Django uchun tayyor model, migratsiya va view'lar bor.
|
|
188
|
+
|
|
189
|
+
**Sizdan kerak bo'lgani** — `OrderHandler`'dan meros olib, uchta metod yozish:
|
|
190
|
+
|
|
191
|
+
| Metod | Vazifasi |
|
|
192
|
+
|---|---|
|
|
193
|
+
| `get_amount(order_id)` | Buyurtma summasini so'mda qaytaring, topilmasa `None` |
|
|
194
|
+
| `is_payable(order_id)` | Buyurtma allaqachon to'langan yoki yopilgan bo'lsa `False` |
|
|
195
|
+
| `on_paid(order_id, tx)` | Pul tushdi: buyurtmani «to'langan» deb belgilang |
|
|
196
|
+
|
|
197
|
+
Keyin yuqoridagi 2–4-qadamlarni bajaring. Click kabinetida **Prepare URL** va **Complete URL** uchun
|
|
198
|
+
bitta manzilni (`/pay/click/`) bering, Payme kabinetida esa endpoint sifatida `/pay/payme/` ni.
|
|
199
|
+
|
|
200
|
+
Savol va takliflar uchun issue oching, PR'lar mamnuniyat bilan qabul qilinadi.
|
|
201
|
+
|
|
202
|
+
## License
|
|
203
|
+
|
|
204
|
+
MIT
|
uzpay-0.1.0/README.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# uzpay
|
|
2
|
+
|
|
3
|
+
[](https://github.com/hamidillomannopov-stack/uzpay/actions/workflows/tests.yml)
|
|
4
|
+
[](https://github.com/hamidillomannopov-stack/uzpay/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
**Click and Payme for Python, done right.** Payment links and the merchant-side webhook
|
|
7
|
+
protocols for Uzbekistan's two main payment systems, with a ready Django integration.
|
|
8
|
+
|
|
9
|
+
## Why uzpay
|
|
10
|
+
|
|
11
|
+
- **Both providers, one API.** Click and Payme share the same `OrderHandler` and the same transaction
|
|
12
|
+
table, so adding the second provider is three lines, not a second integration.
|
|
13
|
+
- **A protocol checker you can point at production.** `tools/payme_check.py` plays Payme and runs 32
|
|
14
|
+
scenarios against any endpoint, written with uzpay or not.
|
|
15
|
+
- **Nothing to install.** The core is pure standard library.
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
- No dependencies in the core: works with Django, FastAPI, Flask or plain WSGI.
|
|
20
|
+
- Full protocol: Click Prepare/Complete with signature check; all six Payme Merchant API methods,
|
|
21
|
+
including the 12-hour timeout, idempotent retries, cancellations and `GetStatement`.
|
|
22
|
+
- You write three small methods ("how much is this order", "it's paid", optionally "it's cancelled").
|
|
23
|
+
uzpay keeps the transaction state machine.
|
|
24
|
+
- Tested: 31 unit tests plus a 32-scenario HTTP check of the Payme protocol.
|
|
25
|
+
|
|
26
|
+
[O'zbekcha qo'llanma pastda](#ozbekcha)
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install uzpay # core
|
|
32
|
+
pip install "uzpay[django]" # with the Django app
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## 1. Tell uzpay about your orders
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from uzpay import OrderHandler
|
|
39
|
+
|
|
40
|
+
class ShopOrders(OrderHandler):
|
|
41
|
+
def get_amount(self, order_id):
|
|
42
|
+
order = Order.objects.filter(pk=order_id).first()
|
|
43
|
+
return order.total if order else None # so'm; None = no such order
|
|
44
|
+
|
|
45
|
+
def is_payable(self, order_id):
|
|
46
|
+
return Order.objects.filter(pk=order_id, status="new").exists()
|
|
47
|
+
|
|
48
|
+
def on_paid(self, order_id, tx):
|
|
49
|
+
Order.objects.filter(pk=order_id).update(status="paid")
|
|
50
|
+
|
|
51
|
+
def on_cancelled(self, order_id, tx): # optional
|
|
52
|
+
...
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## 2. Configure the providers
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from uzpay import Click, Payme
|
|
59
|
+
from uzpay.contrib.django.store import DjangoStore # or MemoryStore / your own Store
|
|
60
|
+
|
|
61
|
+
click = Click(service_id=CLICK_SERVICE_ID, merchant_id=CLICK_MERCHANT_ID,
|
|
62
|
+
secret_key=CLICK_SECRET_KEY, orders=ShopOrders(), store=DjangoStore())
|
|
63
|
+
|
|
64
|
+
payme = Payme(merchant_id=PAYME_MERCHANT_ID, key=PAYME_KEY,
|
|
65
|
+
orders=ShopOrders(), store=DjangoStore(),
|
|
66
|
+
test=False) # True -> test.paycom.uz
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## 3. Send the customer to pay
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
click.checkout_url(order.pk, order.total, return_url="https://shop.uz/thanks")
|
|
73
|
+
payme.checkout_url(order.pk, order.total, return_url="https://shop.uz/thanks", lang="uz")
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Amounts are always in **so'm**. uzpay converts to tiyin for Payme.
|
|
77
|
+
|
|
78
|
+
## 4. Receive the webhooks
|
|
79
|
+
|
|
80
|
+
### Django
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
# settings.py
|
|
84
|
+
INSTALLED_APPS += ["uzpay.contrib.django"] # then: python manage.py migrate
|
|
85
|
+
|
|
86
|
+
# urls.py
|
|
87
|
+
from uzpay.contrib.django.views import click_view, payme_view
|
|
88
|
+
|
|
89
|
+
urlpatterns += [
|
|
90
|
+
path("pay/click/", click_view(click)), # set as both Prepare URL and Complete URL in Click
|
|
91
|
+
path("pay/payme/", payme_view(payme)), # set as the endpoint in the Payme cabinet
|
|
92
|
+
]
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The views run inside `transaction.atomic()` and lock the transaction row, so parallel retries are safe.
|
|
96
|
+
Transactions show up in the `PaymentTransaction` model.
|
|
97
|
+
|
|
98
|
+
### FastAPI (or anything else)
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
@app.post("/pay/click")
|
|
102
|
+
async def click_hook(request: Request):
|
|
103
|
+
return click.handle(dict(await request.form()))
|
|
104
|
+
|
|
105
|
+
@app.post("/pay/payme")
|
|
106
|
+
async def payme_hook(request: Request):
|
|
107
|
+
return payme.handle(await request.body(), request.headers.get("authorization"))
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Outside Django, implement `uzpay.Store` (7 short methods) on top of your database, or use
|
|
111
|
+
`MemoryStore` for tests.
|
|
112
|
+
|
|
113
|
+
## Options
|
|
114
|
+
|
|
115
|
+
| Option | Default | Meaning |
|
|
116
|
+
|---|---|---|
|
|
117
|
+
| `Payme(account_field=...)` | `"order_id"` | Name of the account field configured in your Payme cabinet |
|
|
118
|
+
| `Payme(test=True)` | `False` | Checkout links point to `test.paycom.uz` |
|
|
119
|
+
| `OrderHandler.can_cancel_paid` | `False` | Allow Payme to cancel (refund) a paid transaction |
|
|
120
|
+
| `Click(merchant_user_id=...)` | `None` | Added to checkout links if your Click service requires it |
|
|
121
|
+
|
|
122
|
+
## Error codes
|
|
123
|
+
|
|
124
|
+
uzpay answers with the codes each provider expects:
|
|
125
|
+
|
|
126
|
+
- **Click:** `-1` bad signature, `-2` wrong amount, `-4` already paid, `-5` order not found,
|
|
127
|
+
`-6` transaction not found, `-7` `on_paid` raised, `-8` bad request, `-9` cancelled.
|
|
128
|
+
- **Payme:** `-32504` bad key, `-31001` wrong amount, `-31003` transaction not found,
|
|
129
|
+
`-31007` cannot cancel, `-31008` cannot perform (state or timeout), `-31050` order not found,
|
|
130
|
+
`-31051` order already paid, `-31052` order is being paid in another transaction.
|
|
131
|
+
|
|
132
|
+
## Check any Payme endpoint
|
|
133
|
+
|
|
134
|
+
`tools/payme_check.py` plays the role of Payme and runs 32 sandbox-style scenarios (bad key,
|
|
135
|
+
wrong amount, unknown order, retries, refunds, cancellations, 12-hour timeout, `GetStatement`)
|
|
136
|
+
against a live URL. It works with any Merchant API implementation, not only uzpay, and needs only
|
|
137
|
+
the standard library:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
python tools/payme_check.py https://shop.uz/pay/payme/ --key TEST_KEY --orders 11,12,13 --amount 1000
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
A runnable demo shop lives in [examples/django_demo](https://github.com/hamidillomannopov-stack/uzpay/tree/main/examples/django_demo).
|
|
144
|
+
|
|
145
|
+
## Development
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
pip install -e ".[test]"
|
|
149
|
+
pytest
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## O'zbekcha
|
|
155
|
+
|
|
156
|
+
**uzpay** — Click va Payme to'lov tizimlarini Python loyihangizga ulash uchun kutubxona.
|
|
157
|
+
|
|
158
|
+
**Nima qiladi:**
|
|
159
|
+
- to'lov havolasini yaratadi (`checkout_url`);
|
|
160
|
+
- Click va Payme serverlaridan keladigan so'rovlarni to'liq qayta ishlaydi: imzo va kalitni tekshiradi,
|
|
161
|
+
tranzaksiya holatini saqlaydi, takroriy so'rovlarga to'g'ri javob beradi, 12 soatlik muddatni kuzatadi;
|
|
162
|
+
- Django uchun tayyor model, migratsiya va view'lar bor.
|
|
163
|
+
|
|
164
|
+
**Sizdan kerak bo'lgani** — `OrderHandler`'dan meros olib, uchta metod yozish:
|
|
165
|
+
|
|
166
|
+
| Metod | Vazifasi |
|
|
167
|
+
|---|---|
|
|
168
|
+
| `get_amount(order_id)` | Buyurtma summasini so'mda qaytaring, topilmasa `None` |
|
|
169
|
+
| `is_payable(order_id)` | Buyurtma allaqachon to'langan yoki yopilgan bo'lsa `False` |
|
|
170
|
+
| `on_paid(order_id, tx)` | Pul tushdi: buyurtmani «to'langan» deb belgilang |
|
|
171
|
+
|
|
172
|
+
Keyin yuqoridagi 2–4-qadamlarni bajaring. Click kabinetida **Prepare URL** va **Complete URL** uchun
|
|
173
|
+
bitta manzilni (`/pay/click/`) bering, Payme kabinetida esa endpoint sifatida `/pay/payme/` ni.
|
|
174
|
+
|
|
175
|
+
Savol va takliflar uchun issue oching, PR'lar mamnuniyat bilan qabul qilinadi.
|
|
176
|
+
|
|
177
|
+
## License
|
|
178
|
+
|
|
179
|
+
MIT
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# uzpay demo (Django)
|
|
2
|
+
|
|
3
|
+
Kichik do'kon: buyurtma yaratadi, Payme / Click havolalarini beradi va ularning so'rovlarini
|
|
4
|
+
`uzpay` orqali qabul qiladi. Sandbox'da sinash uchun mo'ljallangan.
|
|
5
|
+
|
|
6
|
+
## Lokal ishga tushirish
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install -e "../..[django]"
|
|
10
|
+
python manage.py migrate
|
|
11
|
+
PAYME_KEY=local-test-key PAYME_MERCHANT_ID=local DJANGO_DEBUG=1 python manage.py runserver 8040
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Payme rolini o'ynaydigan tekshiruv (32 ssenariy):
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
python manage.py create_orders 3 --amount 1000 # -> 4,5,6
|
|
18
|
+
python ../../tools/payme_check.py http://localhost:8040/pay/payme/ \
|
|
19
|
+
--key local-test-key --orders 4,5,6 --amount 1000
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Payme sandbox'da sinash (kassa ochilgandan keyin)
|
|
23
|
+
|
|
24
|
+
1. **merchant.payme.uz** da kassa yarating. Kassa sozlamalaridan quyidagilarni oling:
|
|
25
|
+
kassa **ID** va **TEST KEY** (sandbox paroli).
|
|
26
|
+
2. Demoni ommaviy HTTPS manzilga joylang (masalan `https://uzpay-test.<domen>`), env:
|
|
27
|
+
```
|
|
28
|
+
PAYME_MERCHANT_ID=<kassa ID>
|
|
29
|
+
PAYME_KEY=<TEST KEY>
|
|
30
|
+
PAYME_TEST=1
|
|
31
|
+
DJANGO_ALLOWED_HOSTS=uzpay-test.<domen>
|
|
32
|
+
DJANGO_SECRET_KEY=<tasodifiy satr>
|
|
33
|
+
```
|
|
34
|
+
`gunicorn demo.wsgi` + nginx yetarli. Payme so'rovlari 185.234.113.1–15 manzillaridan keladi.
|
|
35
|
+
3. Kassa sozlamalarida endpoint: `https://uzpay-test.<domen>/pay/payme/`,
|
|
36
|
+
hisob maydoni (account): `order_id`.
|
|
37
|
+
4. Avval o'zingiz tekshiring:
|
|
38
|
+
`python tools/payme_check.py https://uzpay-test.<domen>/pay/payme/ --key <TEST KEY> --orders ... --amount 1000`
|
|
39
|
+
5. **test.paycom.uz** sandbox'ida kassani tanlang, `create_orders` bilan yaratilgan buyurtma raqami va
|
|
40
|
+
summasini kiriting va barcha testlarni ishga tushiring.
|
|
41
|
+
6. Hammasi yashil bo'lsa, demodagi «Payme orqali to'lash» tugmasi bilan sandbox kartasida to'lab ko'ring.
|
|
42
|
+
|
|
43
|
+
Ishlab chiqarishga o'tishda `PAYME_KEY` ni haqiqiy **KEY** ga almashtiring va `PAYME_TEST=0` qiling.
|
|
File without changes
|