paytechuz 0.1.4__tar.gz → 0.2.0b0__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.

Potentially problematic release.


This version of paytechuz might be problematic. Click here for more details.

Files changed (76) hide show
  1. {paytechuz-0.1.4/src/paytechuz.egg-info → paytechuz-0.2.0b0}/PKG-INFO +20 -9
  2. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/README.md +19 -8
  3. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/pyproject.toml +3 -4
  4. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/setup.py +4 -6
  5. paytechuz-0.2.0b0/src/paytechuz/__init__.py +90 -0
  6. paytechuz-0.2.0b0/src/paytechuz/core/__init__.py +0 -0
  7. paytechuz-0.2.0b0/src/paytechuz/core/base.py +97 -0
  8. paytechuz-0.2.0b0/src/paytechuz/core/constants.py +68 -0
  9. paytechuz-0.2.0b0/src/paytechuz/core/exceptions.py +190 -0
  10. paytechuz-0.2.0b0/src/paytechuz/core/http.py +268 -0
  11. paytechuz-0.2.0b0/src/paytechuz/core/payme/errors.py +25 -0
  12. paytechuz-0.2.0b0/src/paytechuz/core/utils.py +192 -0
  13. paytechuz-0.2.0b0/src/paytechuz/gateways/__init__.py +0 -0
  14. paytechuz-0.2.0b0/src/paytechuz/gateways/click/__init__.py +2 -0
  15. paytechuz-0.2.0b0/src/paytechuz/gateways/click/client.py +202 -0
  16. paytechuz-0.2.0b0/src/paytechuz/gateways/click/merchant.py +264 -0
  17. paytechuz-0.2.0b0/src/paytechuz/gateways/click/webhook.py +227 -0
  18. paytechuz-0.2.0b0/src/paytechuz/gateways/payme/__init__.py +2 -0
  19. paytechuz-0.2.0b0/src/paytechuz/gateways/payme/cards.py +222 -0
  20. paytechuz-0.2.0b0/src/paytechuz/gateways/payme/client.py +262 -0
  21. paytechuz-0.2.0b0/src/paytechuz/gateways/payme/receipts.py +336 -0
  22. paytechuz-0.2.0b0/src/paytechuz/gateways/payme/webhook.py +379 -0
  23. paytechuz-0.2.0b0/src/paytechuz/integrations/__init__.py +0 -0
  24. paytechuz-0.2.0b0/src/paytechuz/integrations/django/__init__.py +4 -0
  25. paytechuz-0.2.0b0/src/paytechuz/integrations/django/admin.py +78 -0
  26. paytechuz-0.2.0b0/src/paytechuz/integrations/django/apps.py +21 -0
  27. paytechuz-0.2.0b0/src/paytechuz/integrations/django/migrations/0001_initial.py +51 -0
  28. paytechuz-0.2.0b0/src/paytechuz/integrations/django/migrations/__init__.py +3 -0
  29. paytechuz-0.2.0b0/src/paytechuz/integrations/django/models.py +174 -0
  30. paytechuz-0.2.0b0/src/paytechuz/integrations/django/signals.py +46 -0
  31. paytechuz-0.2.0b0/src/paytechuz/integrations/django/views.py +100 -0
  32. paytechuz-0.2.0b0/src/paytechuz/integrations/django/webhooks.py +880 -0
  33. paytechuz-0.2.0b0/src/paytechuz/integrations/fastapi/__init__.py +21 -0
  34. paytechuz-0.2.0b0/src/paytechuz/integrations/fastapi/models.py +151 -0
  35. paytechuz-0.2.0b0/src/paytechuz/integrations/fastapi/routes.py +1028 -0
  36. paytechuz-0.2.0b0/src/paytechuz/integrations/fastapi/schemas.py +99 -0
  37. {paytechuz-0.1.4 → paytechuz-0.2.0b0/src/paytechuz.egg-info}/PKG-INFO +20 -9
  38. paytechuz-0.2.0b0/src/paytechuz.egg-info/SOURCES.txt +72 -0
  39. paytechuz-0.2.0b0/src/paytechuz.egg-info/top_level.txt +1 -0
  40. paytechuz-0.1.4/src/paytechuz.egg-info/SOURCES.txt +0 -40
  41. paytechuz-0.1.4/src/paytechuz.egg-info/top_level.txt +0 -3
  42. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/MANIFEST.in +0 -0
  43. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/setup.cfg +0 -0
  44. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/__init__.py +0 -0
  45. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/core/__init__.py +0 -0
  46. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/core/base.py +0 -0
  47. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/core/constants.py +0 -0
  48. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/core/exceptions.py +0 -0
  49. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/core/http.py +0 -0
  50. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/core/payme/errors.py +0 -0
  51. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/core/utils.py +0 -0
  52. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/gateways/__init__.py +0 -0
  53. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/gateways/click/__init__.py +0 -0
  54. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/gateways/click/client.py +0 -0
  55. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/gateways/click/merchant.py +0 -0
  56. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/gateways/click/webhook.py +0 -0
  57. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/gateways/payme/__init__.py +0 -0
  58. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/gateways/payme/cards.py +0 -0
  59. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/gateways/payme/client.py +0 -0
  60. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/gateways/payme/receipts.py +0 -0
  61. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/gateways/payme/webhook.py +0 -0
  62. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/integrations/__init__.py +0 -0
  63. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/integrations/django/__init__.py +0 -0
  64. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/integrations/django/admin.py +0 -0
  65. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/integrations/django/apps.py +0 -0
  66. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/integrations/django/migrations/0001_initial.py +0 -0
  67. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/integrations/django/migrations/__init__.py +0 -0
  68. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/integrations/django/models.py +0 -0
  69. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/integrations/django/signals.py +0 -0
  70. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/integrations/django/views.py +0 -0
  71. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/integrations/django/webhooks.py +0 -0
  72. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/integrations/fastapi/__init__.py +0 -0
  73. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/integrations/fastapi/models.py +0 -0
  74. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/integrations/fastapi/routes.py +0 -0
  75. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/integrations/fastapi/schemas.py +0 -0
  76. {paytechuz-0.1.4 → paytechuz-0.2.0b0}/src/paytechuz.egg-info/dependency_links.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: paytechuz
3
- Version: 0.1.4
3
+ Version: 0.2.0b0
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
@@ -41,23 +41,34 @@ pip install paytechuz[fastapi]
41
41
  ### Generate Payment Links
42
42
 
43
43
  ```python
44
- from paytechuz.gateways.payme import PaymeGateway
45
- from paytechuz.gateways.click import ClickGateway
44
+ from paytechuz import create_gateway, PaymentGateway
46
45
 
47
46
  # Initialize gateways
48
- payme = PaymeGateway()
49
- click = ClickGateway()
47
+ payme = create_gateway(PaymentGateway.PAYME.value,
48
+ payme_id="your_payme_id",
49
+ payme_key="your_payme_key",
50
+ is_test_mode=True
51
+ )
52
+
53
+ click = create_gateway(PaymentGateway.CLICK.value,
54
+ service_id="your_service_id",
55
+ merchant_id="your_merchant_id",
56
+ merchant_user_id="your_merchant_user_id",
57
+ secret_key="your_secret_key",
58
+ is_test_mode=True
59
+ )
50
60
 
51
61
  # Generate payment links
52
- payme_link = payme.generate_payment_link(
62
+ payme_link = payme.create_payment(
53
63
  id="order_123",
54
64
  amount=150000, # amount in UZS
55
65
  return_url="https://example.com/return"
56
66
  )
57
67
 
58
- click_link = click.generate_payment_link(
59
- id="order_123",
68
+ click_link = click.create_payment(
60
69
  amount=150000, # amount in UZS
70
+ account_id="order_123",
71
+ description="Test payment",
61
72
  return_url="https://example.com/return"
62
73
  )
63
74
  ```
@@ -99,7 +110,7 @@ class PaymeWebhookView(PaymeWebhookView):
99
110
  order = Order.objects.get(id=transaction.account_id)
100
111
  order.status = 'paid'
101
112
  order.save()
102
-
113
+
103
114
  def cancelled_payment(self, params, transaction):
104
115
  order = Order.objects.get(id=transaction.account_id)
105
116
  order.status = 'cancelled'
@@ -26,23 +26,34 @@ pip install paytechuz[fastapi]
26
26
  ### Generate Payment Links
27
27
 
28
28
  ```python
29
- from paytechuz.gateways.payme import PaymeGateway
30
- from paytechuz.gateways.click import ClickGateway
29
+ from paytechuz import create_gateway, PaymentGateway
31
30
 
32
31
  # Initialize gateways
33
- payme = PaymeGateway()
34
- click = ClickGateway()
32
+ payme = create_gateway(PaymentGateway.PAYME.value,
33
+ payme_id="your_payme_id",
34
+ payme_key="your_payme_key",
35
+ is_test_mode=True
36
+ )
37
+
38
+ click = create_gateway(PaymentGateway.CLICK.value,
39
+ service_id="your_service_id",
40
+ merchant_id="your_merchant_id",
41
+ merchant_user_id="your_merchant_user_id",
42
+ secret_key="your_secret_key",
43
+ is_test_mode=True
44
+ )
35
45
 
36
46
  # Generate payment links
37
- payme_link = payme.generate_payment_link(
47
+ payme_link = payme.create_payment(
38
48
  id="order_123",
39
49
  amount=150000, # amount in UZS
40
50
  return_url="https://example.com/return"
41
51
  )
42
52
 
43
- click_link = click.generate_payment_link(
44
- id="order_123",
53
+ click_link = click.create_payment(
45
54
  amount=150000, # amount in UZS
55
+ account_id="order_123",
56
+ description="Test payment",
46
57
  return_url="https://example.com/return"
47
58
  )
48
59
  ```
@@ -84,7 +95,7 @@ class PaymeWebhookView(PaymeWebhookView):
84
95
  order = Order.objects.get(id=transaction.account_id)
85
96
  order.status = 'paid'
86
97
  order.save()
87
-
98
+
88
99
  def cancelled_payment(self, params, transaction):
89
100
  order = Order.objects.get(id=transaction.account_id)
90
101
  order.status = 'cancelled'
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "paytechuz"
7
- version = "0.1.4"
7
+ version = "0.2.0-beta"
8
8
  description = "Unified Python package for Uzbekistan payment gateways"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.7"
@@ -13,6 +13,5 @@ license = {text = "MIT"}
13
13
  [tool.setuptools]
14
14
  package-dir = {"" = "src"}
15
15
 
16
- [tool.setuptools.packages.find]
17
- where = ["src"]
18
- include = ["paytechuz*", "core*", "gateways*", "integrations*"]
16
+ [tool.setuptools.packages]
17
+ find = {where = ["src"], include = ["paytechuz*"]}
@@ -1,14 +1,14 @@
1
1
  """Setup script for PayTechUZ package."""
2
2
 
3
3
  import pathlib
4
- from setuptools import setup, find_namespace_packages
4
+ from setuptools import setup, find_packages
5
5
 
6
6
  here = pathlib.Path(__file__).parent.resolve()
7
7
  long_description = (here / "README.md").read_text(encoding="utf-8")
8
8
 
9
9
  setup(
10
10
  name='paytechuz',
11
- version='0.1.4',
11
+ version='0.1.6',
12
12
  license='MIT',
13
13
  author="Muhammadali Akbarov",
14
14
  author_email='muhammadali17abc@gmail.com',
@@ -17,10 +17,8 @@ setup(
17
17
  long_description_content_type="text/markdown",
18
18
  url='https://github.com/Muhammadali-Akbarov/paytechuz',
19
19
 
20
- packages=find_namespace_packages(include=['paytechuz*']),
21
- package_dir={
22
- 'paytechuz': 'src',
23
- },
20
+ packages=find_packages(where='src'),
21
+ package_dir={'': 'src'},
24
22
  include_package_data=True,
25
23
  package_data={
26
24
  '': ['*.py'],
@@ -0,0 +1,90 @@
1
+ """
2
+ PayTechUZ - Unified payment library for Uzbekistan payment systems.
3
+
4
+ This library provides a unified interface for working with Payme and Click
5
+ payment systems in Uzbekistan. It supports Django, Flask, and FastAPI.
6
+ """
7
+ from typing import Any
8
+
9
+ __version__ = '0.2.0-beta'
10
+
11
+ # Import framework integrations - these imports are used to check availability
12
+ # of frameworks, not for direct usage
13
+ try:
14
+ import django # noqa: F401 - Used for availability check
15
+ HAS_DJANGO = True
16
+ except ImportError:
17
+ HAS_DJANGO = False
18
+
19
+ try:
20
+ import fastapi # noqa: F401 - Used for availability check
21
+ HAS_FASTAPI = True
22
+ except ImportError:
23
+ HAS_FASTAPI = False
24
+
25
+ try:
26
+ import flask # noqa: F401 - Used for availability check
27
+ HAS_FLASK = True
28
+ except ImportError:
29
+ HAS_FLASK = False
30
+
31
+
32
+ # Import the main classes for easier access
33
+ try:
34
+ from paytechuz.gateways.payme.client import PaymeGateway # noqa: E402
35
+ from paytechuz.gateways.click.client import ClickGateway # noqa: E402
36
+ from paytechuz.core.constants import PaymentGateway # noqa: E402
37
+ except ImportError:
38
+ # Fallback for development mode
39
+ try:
40
+ from .gateways.payme.client import PaymeGateway # noqa: E402
41
+ from .gateways.click.client import ClickGateway # noqa: E402
42
+ from .core.constants import PaymentGateway # noqa: E402
43
+ except ImportError:
44
+ # Dummy classes to avoid import errors
45
+ class PaymeGateway:
46
+ """Dummy PaymeGateway class to avoid import errors."""
47
+ def __init__(self, **kwargs):
48
+ pass
49
+
50
+ def create_payment(self, **kwargs):
51
+ return "https://test.paycom.uz/dummy-payment-url"
52
+
53
+ class ClickGateway:
54
+ """Dummy ClickGateway class to avoid import errors."""
55
+ def __init__(self, **kwargs):
56
+ pass
57
+
58
+ def create_payment(self, **kwargs):
59
+ return {"payment_url": "https://my.click.uz/dummy-payment-url"}
60
+
61
+ class PaymentGateway:
62
+ """Dummy PaymentGateway enum to avoid import errors."""
63
+ class PAYME:
64
+ value = 'payme'
65
+
66
+ class CLICK:
67
+ value = 'click'
68
+
69
+
70
+ def create_gateway(gateway_type: str, **kwargs) -> Any:
71
+ """
72
+ Create a payment gateway instance.
73
+
74
+ Args:
75
+ gateway_type: Type of gateway ('payme' or 'click')
76
+ **kwargs: Gateway-specific configuration
77
+
78
+ Returns:
79
+ Payment gateway instance
80
+
81
+ Raises:
82
+ ValueError: If the gateway type is not supported
83
+ ImportError: If the required gateway module is not available
84
+ """
85
+ if gateway_type.lower() == PaymentGateway.PAYME.value:
86
+ return PaymeGateway(**kwargs)
87
+ if gateway_type.lower() == PaymentGateway.CLICK.value:
88
+ return ClickGateway(**kwargs)
89
+
90
+ raise ValueError(f"Unsupported gateway type: {gateway_type}")
File without changes
@@ -0,0 +1,97 @@
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
+ amount: Union[int, float, str],
30
+ account_id: Union[int, str],
31
+ **kwargs
32
+ ) -> Dict[str, Any]:
33
+ """
34
+ Create a payment.
35
+
36
+ Args:
37
+ amount: The payment amount
38
+ account_id: The account ID or order ID
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
@@ -0,0 +1,68 @@
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
@@ -0,0 +1,190 @@
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
+ )