paytechuz 0.2.20__py3-none-any.whl → 0.2.22__py3-none-any.whl
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.
Potentially problematic release.
This version of paytechuz might be problematic. Click here for more details.
- paytechuz/integrations/fastapi/routes.py +32 -27
- {paytechuz-0.2.20.dist-info → paytechuz-0.2.22.dist-info}/METADATA +6 -33
- paytechuz-0.2.22.dist-info/RECORD +36 -0
- {paytechuz-0.2.20.dist-info → paytechuz-0.2.22.dist-info}/WHEEL +1 -1
- paytechuz-0.2.22.dist-info/top_level.txt +1 -0
- core/__init__.py +0 -0
- core/base.py +0 -97
- core/constants.py +0 -68
- core/exceptions.py +0 -190
- core/http.py +0 -268
- core/payme/errors.py +0 -25
- core/utils.py +0 -192
- gateways/__init__.py +0 -0
- gateways/click/__init__.py +0 -0
- gateways/click/client.py +0 -199
- gateways/click/merchant.py +0 -265
- gateways/click/webhook.py +0 -227
- gateways/payme/__init__.py +0 -0
- gateways/payme/cards.py +0 -222
- gateways/payme/client.py +0 -262
- gateways/payme/receipts.py +0 -336
- gateways/payme/webhook.py +0 -379
- integrations/__init__.py +0 -0
- integrations/django/__init__.py +0 -4
- integrations/django/admin.py +0 -78
- integrations/django/apps.py +0 -21
- integrations/django/migrations/0001_initial.py +0 -51
- integrations/django/migrations/__init__.py +0 -3
- integrations/django/models.py +0 -174
- integrations/django/signals.py +0 -46
- integrations/django/views.py +0 -102
- integrations/django/webhooks.py +0 -884
- integrations/fastapi/__init__.py +0 -21
- integrations/fastapi/models.py +0 -183
- integrations/fastapi/routes.py +0 -1038
- integrations/fastapi/schemas.py +0 -116
- paytechuz-0.2.20.dist-info/RECORD +0 -67
- paytechuz-0.2.20.dist-info/top_level.txt +0 -4
integrations/fastapi/__init__.py
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
FastAPI integration for PayTechUZ.
|
|
3
|
-
"""
|
|
4
|
-
# These imports are available for users of the package
|
|
5
|
-
from .models import Base, PaymentTransaction # noqa: F401
|
|
6
|
-
from .schemas import ( # noqa: F401
|
|
7
|
-
PaymentTransactionBase,
|
|
8
|
-
PaymentTransactionCreate,
|
|
9
|
-
PaymentTransaction as PaymentTransactionSchema,
|
|
10
|
-
PaymentTransactionList,
|
|
11
|
-
PaymeWebhookRequest,
|
|
12
|
-
PaymeWebhookResponse,
|
|
13
|
-
PaymeWebhookErrorResponse,
|
|
14
|
-
ClickWebhookRequest,
|
|
15
|
-
ClickWebhookResponse
|
|
16
|
-
)
|
|
17
|
-
from .routes import ( # noqa: F401
|
|
18
|
-
router,
|
|
19
|
-
PaymeWebhookHandler,
|
|
20
|
-
ClickWebhookHandler
|
|
21
|
-
)
|
integrations/fastapi/models.py
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
FastAPI models for PayTechUZ.
|
|
3
|
-
"""
|
|
4
|
-
from datetime import datetime, timezone
|
|
5
|
-
from typing import Dict, Any, Optional
|
|
6
|
-
|
|
7
|
-
from sqlalchemy import Column, Integer, String, Float, DateTime, JSON
|
|
8
|
-
from sqlalchemy.ext.declarative import declarative_base
|
|
9
|
-
|
|
10
|
-
Base = declarative_base()
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class PaymentTransaction(Base):
|
|
14
|
-
"""
|
|
15
|
-
Payment transaction model for storing payment information.
|
|
16
|
-
"""
|
|
17
|
-
__tablename__ = "payments"
|
|
18
|
-
|
|
19
|
-
# Payment gateway choices
|
|
20
|
-
PAYME = 'payme'
|
|
21
|
-
CLICK = 'click'
|
|
22
|
-
|
|
23
|
-
# Transaction states
|
|
24
|
-
CREATED = 0
|
|
25
|
-
INITIATING = 1
|
|
26
|
-
SUCCESSFULLY = 2
|
|
27
|
-
CANCELLED = -2
|
|
28
|
-
CANCELLED_DURING_INIT = -1
|
|
29
|
-
|
|
30
|
-
id = Column(Integer, primary_key=True, index=True)
|
|
31
|
-
gateway = Column(String(10), index=True) # 'payme' or 'click'
|
|
32
|
-
transaction_id = Column(String(255), index=True)
|
|
33
|
-
account_id = Column(String(255), index=True)
|
|
34
|
-
amount = Column(Float)
|
|
35
|
-
state = Column(Integer, default=CREATED, index=True)
|
|
36
|
-
reason = Column(Integer, nullable=True) # Reason for cancellation
|
|
37
|
-
extra_data = Column(JSON, default={})
|
|
38
|
-
created_at = Column(
|
|
39
|
-
DateTime, default=lambda: datetime.now(timezone.utc), index=True
|
|
40
|
-
)
|
|
41
|
-
updated_at = Column(
|
|
42
|
-
DateTime,
|
|
43
|
-
default=lambda: datetime.now(timezone.utc),
|
|
44
|
-
onupdate=lambda: datetime.now(timezone.utc),
|
|
45
|
-
index=True
|
|
46
|
-
)
|
|
47
|
-
performed_at = Column(DateTime, nullable=True, index=True)
|
|
48
|
-
cancelled_at = Column(DateTime, nullable=True, index=True)
|
|
49
|
-
|
|
50
|
-
@classmethod
|
|
51
|
-
def create_transaction(
|
|
52
|
-
cls,
|
|
53
|
-
db,
|
|
54
|
-
transaction_data: Dict[str, Any]
|
|
55
|
-
) -> "PaymentTransaction":
|
|
56
|
-
"""
|
|
57
|
-
Create a new transaction or get an existing one.
|
|
58
|
-
|
|
59
|
-
Args:
|
|
60
|
-
db: Database session
|
|
61
|
-
transaction_data: Dictionary containing transaction data with keys:
|
|
62
|
-
- gateway: Payment gateway (payme or click)
|
|
63
|
-
- transaction_id: Transaction ID from the payment system
|
|
64
|
-
- account_id: Account or order ID
|
|
65
|
-
- amount: Payment amount
|
|
66
|
-
- extra_data: Additional data for the transaction (optional)
|
|
67
|
-
|
|
68
|
-
Returns:
|
|
69
|
-
PaymentTransaction instance
|
|
70
|
-
"""
|
|
71
|
-
gateway = transaction_data.get('gateway')
|
|
72
|
-
transaction_id = transaction_data.get('transaction_id')
|
|
73
|
-
|
|
74
|
-
# Check if transaction already exists
|
|
75
|
-
transaction = db.query(cls).filter(
|
|
76
|
-
cls.gateway == gateway,
|
|
77
|
-
cls.transaction_id == transaction_id
|
|
78
|
-
).first()
|
|
79
|
-
|
|
80
|
-
if transaction:
|
|
81
|
-
return transaction
|
|
82
|
-
|
|
83
|
-
# Create new transaction
|
|
84
|
-
transaction = cls(
|
|
85
|
-
gateway=gateway,
|
|
86
|
-
transaction_id=transaction_id,
|
|
87
|
-
account_id=str(transaction_data.get('account_id')),
|
|
88
|
-
amount=transaction_data.get('amount'),
|
|
89
|
-
state=cls.CREATED,
|
|
90
|
-
extra_data=transaction_data.get('extra_data', {})
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
db.add(transaction)
|
|
94
|
-
db.commit()
|
|
95
|
-
db.refresh(transaction)
|
|
96
|
-
|
|
97
|
-
return transaction
|
|
98
|
-
|
|
99
|
-
def mark_as_paid(self, db) -> "PaymentTransaction":
|
|
100
|
-
"""
|
|
101
|
-
Mark the transaction as paid.
|
|
102
|
-
|
|
103
|
-
Args:
|
|
104
|
-
db: Database session
|
|
105
|
-
|
|
106
|
-
Returns:
|
|
107
|
-
PaymentTransaction instance
|
|
108
|
-
"""
|
|
109
|
-
if self.state != self.SUCCESSFULLY:
|
|
110
|
-
self.state = self.SUCCESSFULLY
|
|
111
|
-
self.performed_at = datetime.now(timezone.utc)
|
|
112
|
-
|
|
113
|
-
db.commit()
|
|
114
|
-
db.refresh(self)
|
|
115
|
-
|
|
116
|
-
return self
|
|
117
|
-
|
|
118
|
-
def mark_as_cancelled(
|
|
119
|
-
self, db, reason: Optional[str] = None
|
|
120
|
-
) -> "PaymentTransaction":
|
|
121
|
-
"""
|
|
122
|
-
Mark the transaction as cancelled.
|
|
123
|
-
|
|
124
|
-
Args:
|
|
125
|
-
db: Database session
|
|
126
|
-
reason: Reason for cancellation
|
|
127
|
-
|
|
128
|
-
Returns:
|
|
129
|
-
PaymentTransaction instance
|
|
130
|
-
"""
|
|
131
|
-
# If reason is not provided, use default reason (5)
|
|
132
|
-
if reason is None:
|
|
133
|
-
# Default reason 5 (fund returned)
|
|
134
|
-
reason_code = 5
|
|
135
|
-
else:
|
|
136
|
-
# Convert reason to int if it's a string
|
|
137
|
-
if isinstance(reason, str) and reason.isdigit():
|
|
138
|
-
reason_code = int(reason)
|
|
139
|
-
else:
|
|
140
|
-
reason_code = reason
|
|
141
|
-
|
|
142
|
-
# Only update state if not already cancelled
|
|
143
|
-
if self.state not in [self.CANCELLED, self.CANCELLED_DURING_INIT]:
|
|
144
|
-
# Always set state to CANCELLED (-2) for Payme API compatibility
|
|
145
|
-
# regardless of the current state
|
|
146
|
-
self.state = self.CANCELLED
|
|
147
|
-
self.cancelled_at = datetime.now(timezone.utc)
|
|
148
|
-
|
|
149
|
-
# Store the reason directly in the reason column
|
|
150
|
-
self.reason = reason_code
|
|
151
|
-
|
|
152
|
-
# For backward compatibility, also store in extra_data
|
|
153
|
-
extra_data = self.extra_data or {}
|
|
154
|
-
extra_data['cancel_reason'] = reason_code
|
|
155
|
-
self.extra_data = extra_data
|
|
156
|
-
|
|
157
|
-
db.commit()
|
|
158
|
-
db.refresh(self)
|
|
159
|
-
|
|
160
|
-
return self
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
def run_migrations(engine: Any) -> None:
|
|
164
|
-
"""
|
|
165
|
-
Run database migrations for PayTechUZ FastAPI integration.
|
|
166
|
-
|
|
167
|
-
This function creates all necessary tables in the database for the
|
|
168
|
-
PayTechUZ payment system. Call this function when setting up your FastAPI
|
|
169
|
-
application to ensure all required database tables are created.
|
|
170
|
-
|
|
171
|
-
Example:
|
|
172
|
-
```python
|
|
173
|
-
from sqlalchemy import create_engine
|
|
174
|
-
from paytechuz.integrations.fastapi.models import run_migrations
|
|
175
|
-
|
|
176
|
-
engine = create_engine("sqlite:///./payments.db")
|
|
177
|
-
run_migrations(engine)
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
Args:
|
|
181
|
-
engine: SQLAlchemy engine instance
|
|
182
|
-
"""
|
|
183
|
-
Base.metadata.create_all(bind=engine)
|