shops-payment-processing 1.3.0__tar.gz → 2.0.1.dev33609__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.
Files changed (41) hide show
  1. shops_payment_processing-2.0.1.dev33609/PKG-INFO +222 -0
  2. shops_payment_processing-2.0.1.dev33609/README.md +209 -0
  3. {shops_payment_processing-1.3.0 → shops_payment_processing-2.0.1.dev33609}/pyproject.toml +2 -10
  4. shops_payment_processing-1.3.0/PKG-INFO +0 -12
  5. shops_payment_processing-1.3.0/README.md +0 -0
  6. shops_payment_processing-1.3.0/shops_payment_processing/__init__.py +0 -0
  7. shops_payment_processing-1.3.0/shops_payment_processing/__init__.pyi +0 -0
  8. shops_payment_processing-1.3.0/shops_payment_processing/handlers/__init__.py +0 -0
  9. shops_payment_processing-1.3.0/shops_payment_processing/handlers/__init__.pyi +0 -0
  10. shops_payment_processing-1.3.0/shops_payment_processing/handlers/invoice_creation.py +0 -295
  11. shops_payment_processing-1.3.0/shops_payment_processing/handlers/invoice_creation.pyi +0 -23
  12. shops_payment_processing-1.3.0/shops_payment_processing/logging_config.py +0 -3
  13. shops_payment_processing-1.3.0/shops_payment_processing/logging_config.pyi +0 -3
  14. shops_payment_processing-1.3.0/shops_payment_processing/models/__init__.py +0 -0
  15. shops_payment_processing-1.3.0/shops_payment_processing/models/__init__.pyi +0 -0
  16. shops_payment_processing-1.3.0/shops_payment_processing/models/invoice.py +0 -16
  17. shops_payment_processing-1.3.0/shops_payment_processing/models/invoice.pyi +0 -14
  18. shops_payment_processing-1.3.0/shops_payment_processing/models/order.py +0 -89
  19. shops_payment_processing-1.3.0/shops_payment_processing/models/order.pyi +0 -71
  20. shops_payment_processing-1.3.0/shops_payment_processing/models/payment.py +0 -22
  21. shops_payment_processing-1.3.0/shops_payment_processing/models/payment.pyi +0 -17
  22. shops_payment_processing-1.3.0/shops_payment_processing/models/shop.py +0 -10
  23. shops_payment_processing-1.3.0/shops_payment_processing/models/shop.pyi +0 -9
  24. shops_payment_processing-1.3.0/shops_payment_processing/models/user.py +0 -9
  25. shops_payment_processing-1.3.0/shops_payment_processing/models/user.pyi +0 -8
  26. shops_payment_processing-1.3.0/shops_payment_processing/services/__init__.py +0 -0
  27. shops_payment_processing-1.3.0/shops_payment_processing/services/__init__.pyi +0 -0
  28. shops_payment_processing-1.3.0/shops_payment_processing/services/base.py +0 -186
  29. shops_payment_processing-1.3.0/shops_payment_processing/services/base.pyi +0 -65
  30. shops_payment_processing-1.3.0/shops_payment_processing/services/cloudpayments.py +0 -180
  31. shops_payment_processing-1.3.0/shops_payment_processing/services/cloudpayments.pyi +0 -13
  32. shops_payment_processing-1.3.0/shops_payment_processing/services/life_pay.py +0 -61
  33. shops_payment_processing-1.3.0/shops_payment_processing/services/life_pay.pyi +0 -13
  34. shops_payment_processing-1.3.0/shops_payment_processing/services/tkassa.py +0 -114
  35. shops_payment_processing-1.3.0/shops_payment_processing/services/tkassa.pyi +0 -10
  36. shops_payment_processing-1.3.0/shops_payment_processing/services/yookassa.py +0 -115
  37. shops_payment_processing-1.3.0/shops_payment_processing/services/yookassa.pyi +0 -10
  38. shops_payment_processing-1.3.0/shops_payment_processing/utils/__init__.py +0 -0
  39. shops_payment_processing-1.3.0/shops_payment_processing/utils/__init__.pyi +0 -0
  40. shops_payment_processing-1.3.0/shops_payment_processing/utils/link_generation.py +0 -9
  41. shops_payment_processing-1.3.0/shops_payment_processing/utils/link_generation.pyi +0 -1
@@ -0,0 +1,222 @@
1
+ Metadata-Version: 2.4
2
+ Name: shops-payment-processing
3
+ Version: 2.0.1.dev33609
4
+ Summary: Payment processing library for tg-shops.
5
+ Author-email: Pavel Mulin <pavel@shopsbuilder.app>
6
+ Requires-Python: >=3.10
7
+ Requires-Dist: annotated-types>=0.7.0
8
+ Requires-Dist: fastapi>=0.112.2
9
+ Requires-Dist: httpx>=0.25.0
10
+ Requires-Dist: pydantic>=2.10.3
11
+ Requires-Dist: typing-extensions>=4.12.2
12
+ Description-Content-Type: text/markdown
13
+
14
+
15
+ # TMA Authenticator
16
+
17
+ Python library for Telegram Mini App (TMA) and Web3 TON wallet authentication.
18
+
19
+ ## Features
20
+
21
+ - 🔐 **TMA Authentication**: Telegram Mini App user authentication
22
+ - 🌐 **Web3 TON Authentication**: TON wallet authentication via TON Connect
23
+ - 🔑 **JWT Token Generation**: Secure token generation for both auth methods
24
+ - 🔗 **Unified Authentication**: Single endpoint supporting TMA, Web3, and service tokens
25
+ - 💾 **Caching**: Built-in caching for nonces and tokens
26
+ - ✅ **Full Test Coverage**: Comprehensive test suite
27
+ - 📚 **Type Hints**: Full type annotation support
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ pip install tma-authenticator
33
+ ```
34
+
35
+ Or from source:
36
+
37
+ ```bash
38
+ git clone https://github.com/your-repo/python-tma-authorization
39
+ cd python-tma-authorization
40
+ pip install -e .
41
+ ```
42
+
43
+ ## Quick Start
44
+
45
+ ### TMA Authentication
46
+
47
+ ```python
48
+ from tma_authenticator.tma_authentication_router import TMAAuthenticationRouter
49
+ from tma_authenticator.tma_authenticator import TMAAuthenticator
50
+ from database.users import UsersDatabase
51
+ from config import TELEGRAM_BOT_TOKEN, IMPERSONATE_ADMIN_PASSWORD
52
+
53
+ user_database: UsersDatabase = UsersDatabase()
54
+ authenticator = TMAAuthenticator(TELEGRAM_BOT_TOKEN, IMPERSONATE_ADMIN_PASSWORD, user_database)
55
+ authentication_router = authenticator.authentication_router
56
+ ```
57
+
58
+ ### Web3 TON Authentication
59
+
60
+ ```python
61
+ from fastapi import FastAPI
62
+ from aiocache import Cache
63
+ from tma_authenticator.web3_ton_router import Web3TonRouter
64
+
65
+ app = FastAPI()
66
+
67
+ # Setup cache
68
+ Cache.from_url("memory://")
69
+
70
+ # Create Web3 TON router
71
+ web3_router = Web3TonRouter(
72
+ jwt_secret="your-super-secret-jwt-key",
73
+ jwt_algorithm="HS256",
74
+ jwt_expiration_minutes=60,
75
+ nonce_ttl_seconds=300,
76
+ )
77
+
78
+ # Include router
79
+ app.include_router(web3_router)
80
+ ```
81
+
82
+ ## Unified Authentication
83
+
84
+ The `TMAAuthenticator` supports three authentication methods that can be used independently or combined:
85
+
86
+ 1. **TMA Authorization** (`Authorization` header) - Telegram Mini App token
87
+ 2. **Service Token** (`X-Service-Token` header) - Service-to-service JWT
88
+ 3. **Web3 Token** (`X-Web3-Token` header) - Wallet-based JWT (NEW)
89
+
90
+ ### Web3 Token Authentication
91
+
92
+ ```python
93
+ from tma_authenticator import TMAAuthenticator
94
+
95
+ authenticator = TMAAuthenticator(
96
+ service_name="my-app",
97
+ bot_token="YOUR_BOT_TOKEN",
98
+ auth_url="https://auth-service.com",
99
+ storage_provider=storage,
100
+ jwt_secret="your-secret-key", # Enable Web3 support
101
+ jwt_algorithm="HS256"
102
+ )
103
+
104
+ @app.get("/protected")
105
+ async def protected_route(user = Depends(authenticator.oauth_verify_token)):
106
+ # Accepts any of the three token types
107
+ return {
108
+ "user_id": user.tg_id,
109
+ "username": user.username,
110
+ "wallet": user.wallet_address # Present when Web3 token is used
111
+ }
112
+ ```
113
+
114
+ **Usage:**
115
+ ```bash
116
+ # Web3 token only
117
+ curl -H "X-Web3-Token: Bearer <JWT>" https://api.example.com/protected
118
+
119
+ # TMA + Web3 (combine Telegram identity with wallet)
120
+ curl -H "Authorization: Bearer <TMA_TOKEN>" \
121
+ -H "X-Web3-Token: Bearer <WEB3_JWT>" \
122
+ https://api.example.com/protected
123
+ ```
124
+
125
+ See [WEB3_TOKEN_AUTHENTICATION.md](./WEB3_TOKEN_AUTHENTICATION.md) for complete documentation.
126
+
127
+ ## Web3 TON Authentication
128
+
129
+ The library now supports TON wallet authentication following the TON Connect 2.0 specification.
130
+
131
+ ### Available Endpoints
132
+
133
+ 1. **GET `/.well-known/jwks.json`** - JWKS public keys endpoint
134
+ 2. **GET `/web3/nonce?wallet=<address>`** - Generate nonce for wallet
135
+ 3. **POST `/web3/ton/check-proof`** - Verify TON proof and get JWT token
136
+
137
+ ### Authentication Flow
138
+
139
+ ```
140
+ 1. Client requests nonce: GET /web3/nonce?wallet=0:abc...
141
+ 2. Client signs proof with TON wallet using TON Connect
142
+ 3. Client submits proof: POST /web3/ton/check-proof
143
+ 4. Server verifies proof and returns JWT token
144
+ 5. Client uses JWT token for authenticated requests
145
+ ```
146
+
147
+ ### Example Usage
148
+
149
+ See [WEB3_TON_AUTH.md](./WEB3_TON_AUTH.md) for complete documentation and examples.
150
+
151
+ Quick example:
152
+
153
+ ```bash
154
+ # Step 1: Get nonce
155
+ curl "http://localhost:8000/web3/nonce?wallet=0:0e911c7..."
156
+
157
+ # Step 2: Submit proof (after signing with wallet)
158
+ curl -X POST "http://localhost:8000/web3/ton/check-proof" \
159
+ -H "Content-Type: application/json" \
160
+ -d '{
161
+ "ton_addr": {
162
+ "address": "0:0e911c7...",
163
+ "network": "-3",
164
+ "publicKey": "b3e155...",
165
+ "walletStateInit": "te6cc..."
166
+ },
167
+ "ton_proof": {
168
+ "proof": {
169
+ "domain": {"lengthBytes": 4, "value": "t.me"},
170
+ "payload": "2025-12-22T14:55:08.825Z",
171
+ "signature": "360QU7...",
172
+ "timestamp": 1734876508
173
+ }
174
+ }
175
+ }'
176
+ ```
177
+
178
+ ## Documentation
179
+
180
+ - [Web3 Token Authentication](./WEB3_TOKEN_AUTHENTICATION.md) - Web3 token usage and integration
181
+ - [Web3 TON Authentication Guide](./WEB3_TON_AUTH.md) - Complete Web3 TON auth documentation
182
+ - [Web3 TON Quickstart](./QUICKSTART_WEB3_TON.md) - Quick start guide
183
+ - [Examples](./examples/) - Example implementations
184
+ - [Tests](./tests/) - Test suite and usage examples
185
+
186
+ ## Testing
187
+
188
+ ```bash
189
+ # Run all tests
190
+ pytest
191
+
192
+ # Run Web3 TON tests only
193
+ pytest tests/test_web3_ton_router.py -v
194
+
195
+ # Run with coverage
196
+ pytest --cov=tma_authenticator
197
+ ```
198
+
199
+ ## Examples
200
+
201
+ - [TMA Example](./examples/app.py) - Basic TMA authentication
202
+ - [Web3 Token Example](./examples/web3_token_example.py) - Web3 token authentication examples
203
+ - [Web3 TON Example](./examples/web3_ton_example.py) - Complete Web3 TON auth flow
204
+
205
+ ## Requirements
206
+
207
+ - Python 3.8+
208
+ - FastAPI
209
+ - aiocache
210
+ - python-jose
211
+ - pytoniq-core
212
+ - pynacl
213
+
214
+ See [requirements.txt](./requirements.txt) for complete list.
215
+
216
+ ## License
217
+
218
+ MIT License - See LICENSE file for details.
219
+
220
+ ## Contributing
221
+
222
+ Contributions are welcome! Please feel free to submit a Pull Request.
@@ -0,0 +1,209 @@
1
+
2
+ # TMA Authenticator
3
+
4
+ Python library for Telegram Mini App (TMA) and Web3 TON wallet authentication.
5
+
6
+ ## Features
7
+
8
+ - 🔐 **TMA Authentication**: Telegram Mini App user authentication
9
+ - 🌐 **Web3 TON Authentication**: TON wallet authentication via TON Connect
10
+ - 🔑 **JWT Token Generation**: Secure token generation for both auth methods
11
+ - 🔗 **Unified Authentication**: Single endpoint supporting TMA, Web3, and service tokens
12
+ - 💾 **Caching**: Built-in caching for nonces and tokens
13
+ - ✅ **Full Test Coverage**: Comprehensive test suite
14
+ - 📚 **Type Hints**: Full type annotation support
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ pip install tma-authenticator
20
+ ```
21
+
22
+ Or from source:
23
+
24
+ ```bash
25
+ git clone https://github.com/your-repo/python-tma-authorization
26
+ cd python-tma-authorization
27
+ pip install -e .
28
+ ```
29
+
30
+ ## Quick Start
31
+
32
+ ### TMA Authentication
33
+
34
+ ```python
35
+ from tma_authenticator.tma_authentication_router import TMAAuthenticationRouter
36
+ from tma_authenticator.tma_authenticator import TMAAuthenticator
37
+ from database.users import UsersDatabase
38
+ from config import TELEGRAM_BOT_TOKEN, IMPERSONATE_ADMIN_PASSWORD
39
+
40
+ user_database: UsersDatabase = UsersDatabase()
41
+ authenticator = TMAAuthenticator(TELEGRAM_BOT_TOKEN, IMPERSONATE_ADMIN_PASSWORD, user_database)
42
+ authentication_router = authenticator.authentication_router
43
+ ```
44
+
45
+ ### Web3 TON Authentication
46
+
47
+ ```python
48
+ from fastapi import FastAPI
49
+ from aiocache import Cache
50
+ from tma_authenticator.web3_ton_router import Web3TonRouter
51
+
52
+ app = FastAPI()
53
+
54
+ # Setup cache
55
+ Cache.from_url("memory://")
56
+
57
+ # Create Web3 TON router
58
+ web3_router = Web3TonRouter(
59
+ jwt_secret="your-super-secret-jwt-key",
60
+ jwt_algorithm="HS256",
61
+ jwt_expiration_minutes=60,
62
+ nonce_ttl_seconds=300,
63
+ )
64
+
65
+ # Include router
66
+ app.include_router(web3_router)
67
+ ```
68
+
69
+ ## Unified Authentication
70
+
71
+ The `TMAAuthenticator` supports three authentication methods that can be used independently or combined:
72
+
73
+ 1. **TMA Authorization** (`Authorization` header) - Telegram Mini App token
74
+ 2. **Service Token** (`X-Service-Token` header) - Service-to-service JWT
75
+ 3. **Web3 Token** (`X-Web3-Token` header) - Wallet-based JWT (NEW)
76
+
77
+ ### Web3 Token Authentication
78
+
79
+ ```python
80
+ from tma_authenticator import TMAAuthenticator
81
+
82
+ authenticator = TMAAuthenticator(
83
+ service_name="my-app",
84
+ bot_token="YOUR_BOT_TOKEN",
85
+ auth_url="https://auth-service.com",
86
+ storage_provider=storage,
87
+ jwt_secret="your-secret-key", # Enable Web3 support
88
+ jwt_algorithm="HS256"
89
+ )
90
+
91
+ @app.get("/protected")
92
+ async def protected_route(user = Depends(authenticator.oauth_verify_token)):
93
+ # Accepts any of the three token types
94
+ return {
95
+ "user_id": user.tg_id,
96
+ "username": user.username,
97
+ "wallet": user.wallet_address # Present when Web3 token is used
98
+ }
99
+ ```
100
+
101
+ **Usage:**
102
+ ```bash
103
+ # Web3 token only
104
+ curl -H "X-Web3-Token: Bearer <JWT>" https://api.example.com/protected
105
+
106
+ # TMA + Web3 (combine Telegram identity with wallet)
107
+ curl -H "Authorization: Bearer <TMA_TOKEN>" \
108
+ -H "X-Web3-Token: Bearer <WEB3_JWT>" \
109
+ https://api.example.com/protected
110
+ ```
111
+
112
+ See [WEB3_TOKEN_AUTHENTICATION.md](./WEB3_TOKEN_AUTHENTICATION.md) for complete documentation.
113
+
114
+ ## Web3 TON Authentication
115
+
116
+ The library now supports TON wallet authentication following the TON Connect 2.0 specification.
117
+
118
+ ### Available Endpoints
119
+
120
+ 1. **GET `/.well-known/jwks.json`** - JWKS public keys endpoint
121
+ 2. **GET `/web3/nonce?wallet=<address>`** - Generate nonce for wallet
122
+ 3. **POST `/web3/ton/check-proof`** - Verify TON proof and get JWT token
123
+
124
+ ### Authentication Flow
125
+
126
+ ```
127
+ 1. Client requests nonce: GET /web3/nonce?wallet=0:abc...
128
+ 2. Client signs proof with TON wallet using TON Connect
129
+ 3. Client submits proof: POST /web3/ton/check-proof
130
+ 4. Server verifies proof and returns JWT token
131
+ 5. Client uses JWT token for authenticated requests
132
+ ```
133
+
134
+ ### Example Usage
135
+
136
+ See [WEB3_TON_AUTH.md](./WEB3_TON_AUTH.md) for complete documentation and examples.
137
+
138
+ Quick example:
139
+
140
+ ```bash
141
+ # Step 1: Get nonce
142
+ curl "http://localhost:8000/web3/nonce?wallet=0:0e911c7..."
143
+
144
+ # Step 2: Submit proof (after signing with wallet)
145
+ curl -X POST "http://localhost:8000/web3/ton/check-proof" \
146
+ -H "Content-Type: application/json" \
147
+ -d '{
148
+ "ton_addr": {
149
+ "address": "0:0e911c7...",
150
+ "network": "-3",
151
+ "publicKey": "b3e155...",
152
+ "walletStateInit": "te6cc..."
153
+ },
154
+ "ton_proof": {
155
+ "proof": {
156
+ "domain": {"lengthBytes": 4, "value": "t.me"},
157
+ "payload": "2025-12-22T14:55:08.825Z",
158
+ "signature": "360QU7...",
159
+ "timestamp": 1734876508
160
+ }
161
+ }
162
+ }'
163
+ ```
164
+
165
+ ## Documentation
166
+
167
+ - [Web3 Token Authentication](./WEB3_TOKEN_AUTHENTICATION.md) - Web3 token usage and integration
168
+ - [Web3 TON Authentication Guide](./WEB3_TON_AUTH.md) - Complete Web3 TON auth documentation
169
+ - [Web3 TON Quickstart](./QUICKSTART_WEB3_TON.md) - Quick start guide
170
+ - [Examples](./examples/) - Example implementations
171
+ - [Tests](./tests/) - Test suite and usage examples
172
+
173
+ ## Testing
174
+
175
+ ```bash
176
+ # Run all tests
177
+ pytest
178
+
179
+ # Run Web3 TON tests only
180
+ pytest tests/test_web3_ton_router.py -v
181
+
182
+ # Run with coverage
183
+ pytest --cov=tma_authenticator
184
+ ```
185
+
186
+ ## Examples
187
+
188
+ - [TMA Example](./examples/app.py) - Basic TMA authentication
189
+ - [Web3 Token Example](./examples/web3_token_example.py) - Web3 token authentication examples
190
+ - [Web3 TON Example](./examples/web3_ton_example.py) - Complete Web3 TON auth flow
191
+
192
+ ## Requirements
193
+
194
+ - Python 3.8+
195
+ - FastAPI
196
+ - aiocache
197
+ - python-jose
198
+ - pytoniq-core
199
+ - pynacl
200
+
201
+ See [requirements.txt](./requirements.txt) for complete list.
202
+
203
+ ## License
204
+
205
+ MIT License - See LICENSE file for details.
206
+
207
+ ## Contributing
208
+
209
+ Contributions are welcome! Please feel free to submit a Pull Request.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "shops-payment-processing"
3
- version = "v1.3.0"
3
+ version = "v2.0.1.dev33609"
4
4
  description = "Payment processing library for tg-shops."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -9,7 +9,6 @@ dependencies = [
9
9
  "fastapi>=0.112.2",
10
10
  "httpx>=0.25.0",
11
11
  "pydantic>=2.10.3",
12
- "pydantic-core>=2.27.1",
13
12
  "annotated-types>=0.7.0",
14
13
  "typing_extensions>=4.12.2",
15
14
  ]
@@ -18,15 +17,8 @@ dependencies = [
18
17
  requires = ["hatchling"]
19
18
  build-backend = "hatchling.build"
20
19
 
21
- # If your package directory is named `shops_payment_processing/`
22
- # this ensures hatch builds the right wheel contents.
23
20
  [tool.hatch.build.targets.wheel]
24
21
  packages = ["shops_payment_processing"]
25
22
 
26
- # Optional: include package sources in sdist (nice for PyPI)
27
23
  [tool.hatch.build.targets.sdist]
28
- include = [
29
- "shops_payment_processing/**",
30
- "README.md",
31
- "pyproject.toml",
32
- ]
24
+ include = ["shops_payment_processing/**"]
@@ -1,12 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: shops-payment-processing
3
- Version: 1.3.0
4
- Summary: Payment processing library for tg-shops.
5
- Author-email: Pavel Mulin <pavel@shopsbuilder.app>
6
- Requires-Python: >=3.10
7
- Requires-Dist: annotated-types>=0.7.0
8
- Requires-Dist: fastapi>=0.112.2
9
- Requires-Dist: httpx>=0.25.0
10
- Requires-Dist: pydantic-core>=2.27.1
11
- Requires-Dist: pydantic>=2.10.3
12
- Requires-Dist: typing-extensions>=4.12.2
File without changes