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
|
@@ -989,42 +989,47 @@ class ClickWebhookHandler:
|
|
|
989
989
|
"""
|
|
990
990
|
Check authentication using signature.
|
|
991
991
|
"""
|
|
992
|
-
if
|
|
992
|
+
if not all([self.service_id, self.secret_key]):
|
|
993
993
|
raise HTTPException(
|
|
994
994
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
995
|
-
detail="
|
|
995
|
+
detail="Missing required settings: service_id or secret_key"
|
|
996
996
|
)
|
|
997
997
|
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
998
|
+
if str(params.get("service_id")) != self.service_id:
|
|
999
|
+
raise HTTPException(
|
|
1000
|
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
1001
|
+
detail="Invalid service ID"
|
|
1002
|
+
)
|
|
1002
1003
|
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
1006
|
-
detail="Missing signature parameters"
|
|
1007
|
-
)
|
|
1004
|
+
sign_string = params.get("sign_string")
|
|
1005
|
+
sign_time = params.get("sign_time")
|
|
1008
1006
|
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
f"{self.secret_key}"
|
|
1014
|
-
f"{params.get('merchant_trans_id')}"
|
|
1015
|
-
f"{params.get('amount')}"
|
|
1016
|
-
f"{params.get('action')}"
|
|
1017
|
-
f"{sign_time}"
|
|
1007
|
+
if not sign_string or not sign_time:
|
|
1008
|
+
raise HTTPException(
|
|
1009
|
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
1010
|
+
detail="Missing signature parameters"
|
|
1018
1011
|
)
|
|
1019
1012
|
|
|
1020
|
-
|
|
1021
|
-
|
|
1013
|
+
# Prepare signature components
|
|
1014
|
+
text_parts = [
|
|
1015
|
+
str(params.get("click_trans_id") or ""),
|
|
1016
|
+
str(params.get("service_id") or ""),
|
|
1017
|
+
str(self.secret_key or ""),
|
|
1018
|
+
str(params.get("merchant_trans_id") or ""),
|
|
1019
|
+
str(params.get("merchant_prepare_id") or ""),
|
|
1020
|
+
str(params.get("amount") or ""),
|
|
1021
|
+
str(params.get("action") or ""),
|
|
1022
|
+
str(sign_time)
|
|
1023
|
+
]
|
|
1024
|
+
|
|
1025
|
+
# Calculate hash
|
|
1026
|
+
calculated_hash = hashlib.md5("".join(text_parts).encode("utf-8")).hexdigest()
|
|
1022
1027
|
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
+
if calculated_hash != sign_string:
|
|
1029
|
+
raise HTTPException(
|
|
1030
|
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
1031
|
+
detail="Invalid signature"
|
|
1032
|
+
)
|
|
1028
1033
|
|
|
1029
1034
|
def _find_account(self, merchant_trans_id: str) -> Any:
|
|
1030
1035
|
"""
|
|
@@ -1,42 +1,17 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: paytechuz
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.22
|
|
4
4
|
Summary: Unified Python package for Uzbekistan payment gateways
|
|
5
5
|
Home-page: https://github.com/Muhammadali-Akbarov/paytechuz
|
|
6
6
|
Author: Muhammadali Akbarov
|
|
7
7
|
Author-email: muhammadali17abc@gmail.com
|
|
8
8
|
License: MIT
|
|
9
|
-
Keywords: paytechuz,payme,click,uzbekistan,payment,gateway,payment-gateway,payment-processing,django,flask,fastapi
|
|
10
|
-
Platform: UNKNOWN
|
|
11
|
-
Classifier: Development Status :: 4 - Beta
|
|
12
|
-
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: Programming Language :: Python :: 3
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.6
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
22
|
-
Classifier: Operating System :: OS Independent
|
|
23
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
9
|
Requires-Python: >=3.6
|
|
25
10
|
Description-Content-Type: text/markdown
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Requires-Dist: djangorestframework<4.0,>=3.0; extra == "django"
|
|
31
|
-
Provides-Extra: fastapi
|
|
32
|
-
Requires-Dist: fastapi<1.0.0,>=0.68.0; extra == "fastapi"
|
|
33
|
-
Requires-Dist: sqlalchemy<3.0,>=1.4; extra == "fastapi"
|
|
34
|
-
Requires-Dist: httpx<1.0,>=0.20; extra == "fastapi"
|
|
35
|
-
Requires-Dist: python-multipart==0.0.20; extra == "fastapi"
|
|
36
|
-
Requires-Dist: pydantic<2.0,>=1.8; extra == "fastapi"
|
|
37
|
-
Provides-Extra: flask
|
|
38
|
-
Requires-Dist: flask<3.0,>=2.0; extra == "flask"
|
|
39
|
-
Requires-Dist: flask-sqlalchemy<3.0,>=2.5; extra == "flask"
|
|
11
|
+
Dynamic: author
|
|
12
|
+
Dynamic: author-email
|
|
13
|
+
Dynamic: home-page
|
|
14
|
+
Dynamic: requires-python
|
|
40
15
|
|
|
41
16
|
# paytechuz
|
|
42
17
|
|
|
@@ -357,5 +332,3 @@ Contributions are welcome! Please feel free to submit a Pull Request.
|
|
|
357
332
|
## License
|
|
358
333
|
|
|
359
334
|
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
360
|
-
|
|
361
|
-
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
paytechuz/__init__.py,sha256=d-9AjWthchZAE_ykEjoBZ79o32gzqM1jZkkAQd-jB8s,1754
|
|
2
|
+
paytechuz/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
paytechuz/core/base.py,sha256=Es6eEGNgDjQJe-kEJVAHSAh8AWbgtIuQMm0xn7qfjl4,2549
|
|
4
|
+
paytechuz/core/constants.py,sha256=P2zeZ_cfZIttdC1vqkpIngkfRFh6loWzJYEgzQb5cKA,1660
|
|
5
|
+
paytechuz/core/exceptions.py,sha256=XMJkqiponTkvhjoh3S2iFNuU3UbBdFW4130kd0hpudg,5489
|
|
6
|
+
paytechuz/core/http.py,sha256=1PFv_Fo62GtfyYKUK2nsT4AaeQNuMgZlFUFL1q9p2MI,7672
|
|
7
|
+
paytechuz/core/utils.py,sha256=EbNtDweR1ABOtCu4D6cYlolM0t_fbiE3gNoc_qfcKKA,4704
|
|
8
|
+
paytechuz/core/payme/errors.py,sha256=CZE62MbYDMsRfNIX23Syt6of_tPMMGLnXhYMii4hw3A,542
|
|
9
|
+
paytechuz/gateways/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
paytechuz/gateways/click/__init__.py,sha256=35RPIrZYHgMWDzxjQkJMZYjzHDa8cY_BqQztCdZZmBM,90
|
|
11
|
+
paytechuz/gateways/click/client.py,sha256=NwsPGfXacO0tWvZCA0V9KZ9XhFV7AnyHBmtxsWAvci8,6736
|
|
12
|
+
paytechuz/gateways/click/merchant.py,sha256=tvHUwNr_eiDz_ED4-m2GNBh_LXN0b5lwtq1jw1e0zAQ,7191
|
|
13
|
+
paytechuz/gateways/click/webhook.py,sha256=rph-NmjjnBKMW4rcxQTXrHHdK-uMrU39kXnbqK56leo,7936
|
|
14
|
+
paytechuz/gateways/payme/__init__.py,sha256=KcVkYvAEblL4ASVAOrUofRBwywAkTZIgRXoBaCbYtv8,90
|
|
15
|
+
paytechuz/gateways/payme/cards.py,sha256=iyitnAIQ_BUNmF273ErSLe3GOs5LYp3pWHxdb_FtOzs,5421
|
|
16
|
+
paytechuz/gateways/payme/client.py,sha256=fmFHbgWX0UG7246JgA8tWougzAbw75QTWC9mw_TgvZI,7808
|
|
17
|
+
paytechuz/gateways/payme/receipts.py,sha256=DFIoD2EW65sStgeNP75GrUCcuvn7H7PPc415pw4S79g,8905
|
|
18
|
+
paytechuz/gateways/payme/webhook.py,sha256=-0O8vzMtiu4U8FWFKDA6EfyoX4NEGqcEq-T0yNtVhM4,12374
|
|
19
|
+
paytechuz/integrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
|
+
paytechuz/integrations/django/__init__.py,sha256=fNs4c2IWpCe78-_Yvgz59TdKbHiYRYDkLR33QOBf-Ok,356
|
|
21
|
+
paytechuz/integrations/django/admin.py,sha256=6fs6GiKcdc-hGlLxJ0BthY7TFo_2RVVJRhQwhxMroCY,2664
|
|
22
|
+
paytechuz/integrations/django/apps.py,sha256=Q9wG2osL7_Ip2BcAkq7lmmhu4UKJAg6UtSsSq_RgHlc,640
|
|
23
|
+
paytechuz/integrations/django/models.py,sha256=x3cVLY812Xts5oNk4VmCzK3zjb0FXQON9WV41PCtxaw,5696
|
|
24
|
+
paytechuz/integrations/django/signals.py,sha256=VtNYEAnu13wi9PqadEaCU9LY_k2tY26AS4bnPIAqw7M,1319
|
|
25
|
+
paytechuz/integrations/django/views.py,sha256=TL-LNbwrLvYjoBvGxm_yZjMVLBqelorgKjr4l3sKH1Y,3037
|
|
26
|
+
paytechuz/integrations/django/webhooks.py,sha256=6GlLgLEizMjkD7dYR3AoLcLmZnMPwi3IaqB0Kln7dSk,31759
|
|
27
|
+
paytechuz/integrations/django/migrations/0001_initial.py,sha256=SWHIUuwq91crzaxa9v1UK0kay8CxsjUo6t4bqg7j0Gw,1896
|
|
28
|
+
paytechuz/integrations/django/migrations/__init__.py,sha256=KLQ5NdjOMLDS21-u3b_g08G1MjPMMhG95XI_N8m4FSo,41
|
|
29
|
+
paytechuz/integrations/fastapi/__init__.py,sha256=DLnhAZQZf2ghu8BuFFfE7FzbNKWQQ2SLG8qxldRuwR4,565
|
|
30
|
+
paytechuz/integrations/fastapi/models.py,sha256=9IqrsndIVuIDwDbijZ89biJxEWQASXRBfWVShxgerAc,5113
|
|
31
|
+
paytechuz/integrations/fastapi/routes.py,sha256=t8zbqhMZsaJmEvMDgmF-NoRmbqksfX_AvIrx-3kCjg8,37845
|
|
32
|
+
paytechuz/integrations/fastapi/schemas.py,sha256=PgRqviJiD4-u3_CIkUOX8R7L8Yqn8L44WLte7968G0E,3887
|
|
33
|
+
paytechuz-0.2.22.dist-info/METADATA,sha256=JNeDz3IQeu9uOtMOt48IsarEErU6mMLAv6GWndyBgW4,10084
|
|
34
|
+
paytechuz-0.2.22.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
35
|
+
paytechuz-0.2.22.dist-info/top_level.txt,sha256=oloyKGNVj9Z2h3wpKG5yPyTlpdpWW0-CWr-j-asCWBc,10
|
|
36
|
+
paytechuz-0.2.22.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
paytechuz
|
core/__init__.py
DELETED
|
File without changes
|
core/base.py
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Base classes for payment gateways.
|
|
3
|
-
"""
|
|
4
|
-
from abc import ABC, abstractmethod
|
|
5
|
-
from typing import Dict, Any, Optional, Union
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class BasePaymentGateway(ABC):
|
|
9
|
-
"""
|
|
10
|
-
Base class for all payment gateways.
|
|
11
|
-
|
|
12
|
-
This abstract class defines the common interface that all payment gateways
|
|
13
|
-
must implement. It provides a consistent API for creating, checking, and
|
|
14
|
-
canceling payments regardless of the underlying payment provider.
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
def __init__(self, is_test_mode: bool = False):
|
|
18
|
-
"""
|
|
19
|
-
Initialize the payment gateway.
|
|
20
|
-
|
|
21
|
-
Args:
|
|
22
|
-
is_test_mode (bool): Whether to use the test environment
|
|
23
|
-
"""
|
|
24
|
-
self.is_test_mode = is_test_mode
|
|
25
|
-
|
|
26
|
-
@abstractmethod
|
|
27
|
-
def create_payment(
|
|
28
|
-
self,
|
|
29
|
-
id: Union[int, str],
|
|
30
|
-
amount: Union[int, float, str],
|
|
31
|
-
**kwargs
|
|
32
|
-
) -> Dict[str, Any]:
|
|
33
|
-
"""
|
|
34
|
-
Create a payment.
|
|
35
|
-
|
|
36
|
-
Args:
|
|
37
|
-
id: The account ID or order ID
|
|
38
|
-
amount: The payment amount
|
|
39
|
-
**kwargs: Additional parameters specific to the payment gateway
|
|
40
|
-
|
|
41
|
-
Returns:
|
|
42
|
-
Dict containing payment details including transaction ID
|
|
43
|
-
"""
|
|
44
|
-
raise NotImplementedError
|
|
45
|
-
|
|
46
|
-
@abstractmethod
|
|
47
|
-
def check_payment(self, transaction_id: str) -> Dict[str, Any]:
|
|
48
|
-
"""
|
|
49
|
-
Check payment status.
|
|
50
|
-
|
|
51
|
-
Args:
|
|
52
|
-
transaction_id: The transaction ID to check
|
|
53
|
-
|
|
54
|
-
Returns:
|
|
55
|
-
Dict containing payment status and details
|
|
56
|
-
"""
|
|
57
|
-
raise NotImplementedError
|
|
58
|
-
|
|
59
|
-
@abstractmethod
|
|
60
|
-
def cancel_payment(
|
|
61
|
-
self,
|
|
62
|
-
transaction_id: str,
|
|
63
|
-
reason: Optional[str] = None
|
|
64
|
-
) -> Dict[str, Any]:
|
|
65
|
-
"""
|
|
66
|
-
Cancel payment.
|
|
67
|
-
|
|
68
|
-
Args:
|
|
69
|
-
transaction_id: The transaction ID to cancel
|
|
70
|
-
reason: Optional reason for cancellation
|
|
71
|
-
|
|
72
|
-
Returns:
|
|
73
|
-
Dict containing cancellation status and details
|
|
74
|
-
"""
|
|
75
|
-
raise NotImplementedError
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
class BaseWebhookHandler(ABC):
|
|
79
|
-
"""
|
|
80
|
-
Base class for payment gateway webhook handlers.
|
|
81
|
-
|
|
82
|
-
This abstract class defines the common interface for handling webhook
|
|
83
|
-
callbacks from payment gateways.
|
|
84
|
-
"""
|
|
85
|
-
|
|
86
|
-
@abstractmethod
|
|
87
|
-
def handle_webhook(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
|
88
|
-
"""
|
|
89
|
-
Handle webhook data from payment gateway.
|
|
90
|
-
|
|
91
|
-
Args:
|
|
92
|
-
data: The webhook data received from the payment gateway
|
|
93
|
-
|
|
94
|
-
Returns:
|
|
95
|
-
Dict containing the response to be sent back to the payment gateway
|
|
96
|
-
"""
|
|
97
|
-
raise NotImplementedError
|
core/constants.py
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Constants for payment gateways.
|
|
3
|
-
"""
|
|
4
|
-
from enum import Enum
|
|
5
|
-
|
|
6
|
-
class TransactionState(Enum):
|
|
7
|
-
"""Transaction states."""
|
|
8
|
-
CREATED = 0
|
|
9
|
-
INITIATING = 1
|
|
10
|
-
SUCCESSFULLY = 2
|
|
11
|
-
CANCELED = -2
|
|
12
|
-
CANCELED_DURING_INIT = -1
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class PaymentGateway(Enum):
|
|
16
|
-
"""Payment gateway types."""
|
|
17
|
-
PAYME = "payme"
|
|
18
|
-
CLICK = "click"
|
|
19
|
-
|
|
20
|
-
class PaymeEndpoints:
|
|
21
|
-
"""Payme API endpoints."""
|
|
22
|
-
RECEIPTS_CREATE = "receipts/create"
|
|
23
|
-
RECEIPTS_PAY = "receipts/pay"
|
|
24
|
-
RECEIPTS_SEND = "receipts/send"
|
|
25
|
-
RECEIPTS_CHECK = "receipts/check"
|
|
26
|
-
RECEIPTS_CANCEL = "receipts/cancel"
|
|
27
|
-
RECEIPTS_GET = "receipts/get"
|
|
28
|
-
CARDS_CREATE = "cards/create"
|
|
29
|
-
CARDS_VERIFY = "cards/verify"
|
|
30
|
-
CARDS_CHECK = "cards/check"
|
|
31
|
-
CARDS_REMOVE = "cards/remove"
|
|
32
|
-
CARDS_GET_VERIFY_CODE = "cards/get_verify_code"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
class PaymeNetworks:
|
|
36
|
-
"""Payme API networks."""
|
|
37
|
-
TEST_NET = "https://checkout.test.paycom.uz/api"
|
|
38
|
-
PROD_NET = "https://checkout.paycom.uz/api"
|
|
39
|
-
|
|
40
|
-
class ClickEndpoints:
|
|
41
|
-
"""Click API endpoints."""
|
|
42
|
-
PREPARE = "prepare"
|
|
43
|
-
COMPLETE = "complete"
|
|
44
|
-
MERCHANT_API = "merchant/api"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
class ClickNetworks:
|
|
48
|
-
"""Click API networks."""
|
|
49
|
-
TEST_NET = "https://api.click.uz/v2/merchant"
|
|
50
|
-
PROD_NET = "https://api.click.uz/v2/merchant"
|
|
51
|
-
|
|
52
|
-
class ClickActions:
|
|
53
|
-
"""Click API actions."""
|
|
54
|
-
PREPARE = 0
|
|
55
|
-
COMPLETE = 1
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
class PaymeCancelReason:
|
|
59
|
-
"""Payme cancel reason codes."""
|
|
60
|
-
REASON_USER_NOT_FOUND = 1
|
|
61
|
-
REASON_DEBIT_OPERATION_FAILED = 2
|
|
62
|
-
REASON_EXECUTION_ERROR = 3
|
|
63
|
-
REASON_TIMEOUT = 4
|
|
64
|
-
REASON_FUND_RETURNED = 5
|
|
65
|
-
REASON_UNKNOWN = 6
|
|
66
|
-
REASON_CANCELLED_BY_USER = 7
|
|
67
|
-
REASON_SUSPICIOUS_OPERATION = 8
|
|
68
|
-
REASON_MERCHANT_DECISION = 9
|
core/exceptions.py
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Exceptions for payment gateways.
|
|
3
|
-
"""
|
|
4
|
-
from typing import Optional, Dict, Any
|
|
5
|
-
|
|
6
|
-
class PaymentException(Exception):
|
|
7
|
-
"""Base exception for all payment exceptions."""
|
|
8
|
-
code = "payment_error"
|
|
9
|
-
message = "Payment error occurred"
|
|
10
|
-
data: Dict[str, Any] = {}
|
|
11
|
-
|
|
12
|
-
def __init__(self, message: Optional[str] = None, code: Optional[str] = None, data: Optional[Dict[str, Any]] = None):
|
|
13
|
-
"""
|
|
14
|
-
Initialize the exception.
|
|
15
|
-
|
|
16
|
-
Args:
|
|
17
|
-
message: Custom error message
|
|
18
|
-
code: Custom error code
|
|
19
|
-
data: Additional error data
|
|
20
|
-
"""
|
|
21
|
-
self.message = message or self.message
|
|
22
|
-
self.code = code or self.code
|
|
23
|
-
self.data = data or self.data
|
|
24
|
-
super().__init__(self.message)
|
|
25
|
-
|
|
26
|
-
def as_dict(self) -> Dict[str, Any]:
|
|
27
|
-
"""
|
|
28
|
-
Convert the exception to a dictionary.
|
|
29
|
-
|
|
30
|
-
Returns:
|
|
31
|
-
Dict containing error details
|
|
32
|
-
"""
|
|
33
|
-
return {
|
|
34
|
-
"code": self.code,
|
|
35
|
-
"message": self.message,
|
|
36
|
-
"data": self.data
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
# Authentication and Authorization Exceptions
|
|
40
|
-
class AuthenticationError(PaymentException):
|
|
41
|
-
"""Exception raised when authentication fails."""
|
|
42
|
-
code = "authentication_error"
|
|
43
|
-
message = "Authentication failed"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
class InvalidCredentials(AuthenticationError):
|
|
48
|
-
"""Exception raised when credentials are invalid."""
|
|
49
|
-
code = "invalid_credentials"
|
|
50
|
-
message = "Invalid credentials provided"
|
|
51
|
-
|
|
52
|
-
class PermissionDenied(AuthenticationError):
|
|
53
|
-
"""Exception raised when permission is denied."""
|
|
54
|
-
code = "permission_denied"
|
|
55
|
-
message = "Permission denied"
|
|
56
|
-
|
|
57
|
-
# Transaction Exceptions
|
|
58
|
-
class TransactionError(PaymentException):
|
|
59
|
-
"""Base exception for transaction errors."""
|
|
60
|
-
code = "transaction_error"
|
|
61
|
-
message = "Transaction error occurred"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
class TransactionNotFound(TransactionError):
|
|
65
|
-
"""Exception raised when a transaction is not found."""
|
|
66
|
-
code = "transaction_not_found"
|
|
67
|
-
message = "Transaction not found"
|
|
68
|
-
|
|
69
|
-
class TransactionAlreadyExists(TransactionError):
|
|
70
|
-
"""Exception raised when a transaction already exists."""
|
|
71
|
-
code = "transaction_already_exists"
|
|
72
|
-
message = "Transaction already exists"
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
class TransactionCancelled(TransactionError):
|
|
76
|
-
"""Exception raised when a transaction is cancelled."""
|
|
77
|
-
code = "transaction_cancelled"
|
|
78
|
-
message = "Transaction has been cancelled"
|
|
79
|
-
|
|
80
|
-
class TransactionInProgress(TransactionError):
|
|
81
|
-
"""Exception raised when a transaction is in progress."""
|
|
82
|
-
code = "transaction_in_progress"
|
|
83
|
-
message = "Transaction is in progress"
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
class TransactionCompleted(TransactionError):
|
|
87
|
-
"""Exception raised when a transaction is already completed."""
|
|
88
|
-
code = "transaction_completed"
|
|
89
|
-
message = "Transaction is already completed"
|
|
90
|
-
|
|
91
|
-
# Account Exceptions
|
|
92
|
-
class AccountError(PaymentException):
|
|
93
|
-
"""Base exception for account errors."""
|
|
94
|
-
code = "account_error"
|
|
95
|
-
message = "Account error occurred"
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
class AccountNotFound(AccountError):
|
|
99
|
-
"""Exception raised when an account is not found."""
|
|
100
|
-
code = "account_not_found"
|
|
101
|
-
message = "Account not found"
|
|
102
|
-
|
|
103
|
-
class InvalidAccount(AccountError):
|
|
104
|
-
"""Exception raised when an account is invalid."""
|
|
105
|
-
code = "invalid_account"
|
|
106
|
-
message = "Invalid account"
|
|
107
|
-
|
|
108
|
-
# Amount Exceptions
|
|
109
|
-
class AmountError(PaymentException):
|
|
110
|
-
"""Base exception for amount errors."""
|
|
111
|
-
code = "amount_error"
|
|
112
|
-
message = "Amount error occurred"
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
class InvalidAmount(AmountError):
|
|
116
|
-
"""Exception raised when an amount is invalid."""
|
|
117
|
-
code = "invalid_amount"
|
|
118
|
-
message = "Invalid amount"
|
|
119
|
-
|
|
120
|
-
class InsufficientFunds(AmountError):
|
|
121
|
-
"""Exception raised when there are insufficient funds."""
|
|
122
|
-
code = "insufficient_funds"
|
|
123
|
-
message = "Insufficient funds"
|
|
124
|
-
|
|
125
|
-
# Method Exceptions
|
|
126
|
-
class MethodError(PaymentException):
|
|
127
|
-
"""Base exception for method errors."""
|
|
128
|
-
code = "method_error"
|
|
129
|
-
message = "Method error occurred"
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
class MethodNotFound(MethodError):
|
|
133
|
-
"""Exception raised when a method is not found."""
|
|
134
|
-
code = "method_not_found"
|
|
135
|
-
message = "Method not found"
|
|
136
|
-
|
|
137
|
-
class UnsupportedMethod(MethodError):
|
|
138
|
-
"""Exception raised when a method is not supported."""
|
|
139
|
-
code = "unsupported_method"
|
|
140
|
-
message = "Method not supported"
|
|
141
|
-
|
|
142
|
-
# System Exceptions
|
|
143
|
-
class SystemError(PaymentException):
|
|
144
|
-
"""Base exception for system errors."""
|
|
145
|
-
code = "system_error"
|
|
146
|
-
message = "System error occurred"
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
class InternalServiceError(SystemError):
|
|
150
|
-
"""Exception raised when an internal service error occurs."""
|
|
151
|
-
code = "internal_service_error"
|
|
152
|
-
message = "Internal service error"
|
|
153
|
-
|
|
154
|
-
class ExternalServiceError(SystemError):
|
|
155
|
-
"""Exception raised when an external service error occurs."""
|
|
156
|
-
code = "external_service_error"
|
|
157
|
-
message = "External service error"
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
class TimeoutError(SystemError):
|
|
161
|
-
"""Exception raised when a timeout occurs."""
|
|
162
|
-
code = "timeout_error"
|
|
163
|
-
message = "Operation timed out"
|
|
164
|
-
|
|
165
|
-
# Create a list of exceptions that should not be wrapped
|
|
166
|
-
exception_whitelist = (
|
|
167
|
-
PaymentException,
|
|
168
|
-
AuthenticationError,
|
|
169
|
-
InvalidCredentials,
|
|
170
|
-
PermissionDenied,
|
|
171
|
-
TransactionError,
|
|
172
|
-
TransactionNotFound,
|
|
173
|
-
TransactionAlreadyExists,
|
|
174
|
-
TransactionCancelled,
|
|
175
|
-
TransactionInProgress,
|
|
176
|
-
TransactionCompleted,
|
|
177
|
-
AccountError,
|
|
178
|
-
AccountNotFound,
|
|
179
|
-
InvalidAccount,
|
|
180
|
-
AmountError,
|
|
181
|
-
InvalidAmount,
|
|
182
|
-
InsufficientFunds,
|
|
183
|
-
MethodError,
|
|
184
|
-
MethodNotFound,
|
|
185
|
-
UnsupportedMethod,
|
|
186
|
-
SystemError,
|
|
187
|
-
InternalServiceError,
|
|
188
|
-
ExternalServiceError,
|
|
189
|
-
TimeoutError,
|
|
190
|
-
)
|