payme-pkg 3.0.22__py3-none-any.whl → 3.0.25b0__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 payme-pkg might be problematic. Click here for more details.

payme/admin.py CHANGED
@@ -1,3 +1,4 @@
1
+ from django.conf import settings
1
2
  from django.contrib import admin
2
3
 
3
4
  from payme.models import PaymeTransactions
@@ -13,4 +14,5 @@ class PaymeTransactionsUI(admin.ModelAdmin):
13
14
  ordering = ('-created_at',)
14
15
 
15
16
 
16
- admin.site.register(PaymeTransactions, PaymeTransactionsUI)
17
+ if not getattr(settings, 'PAYME_DISABLE_ADMIN', False):
18
+ admin.site.register(PaymeTransactions, PaymeTransactionsUI)
payme/classes/cards.py CHANGED
@@ -19,7 +19,7 @@ class Cards:
19
19
  services. It allows you to create new cards and retrieve verification
20
20
  codes for existing cards.
21
21
  """
22
- def __init__(self, url: str, payme_id: str) -> "Cards":
22
+ def __init__(self, url: str, payme_id: str) -> None:
23
23
  """
24
24
  Initialize the Cards client.
25
25
 
payme/classes/client.py CHANGED
@@ -1,5 +1,4 @@
1
-
2
- from typing import Union
1
+ import typing as t
3
2
 
4
3
  from payme.const import Networks
5
4
  from payme.classes.cards import Cards
@@ -11,14 +10,14 @@ class Payme:
11
10
  """
12
11
  The payme class provides a simple interface
13
12
  """
13
+
14
14
  def __init__(
15
15
  self,
16
16
  payme_id: str,
17
- fallback_id: Union[str, None] = None,
18
- payme_key: Union[str, None] = None,
19
- is_test_mode: bool = False
20
- ):
21
-
17
+ fallback_id: t.Optional[str] = None,
18
+ payme_key: t.Optional[str] = None,
19
+ is_test_mode: bool = False,
20
+ ) -> None:
22
21
  # initialize payme network
23
22
  url = Networks.PROD_NET.value
24
23
 
@@ -26,5 +25,8 @@ class Payme:
26
25
  url = Networks.TEST_NET.value
27
26
 
28
27
  self.cards = Cards(url=url, payme_id=payme_id)
29
- self.initializer = Initializer(payme_id=payme_id, fallback_id=fallback_id, is_test_mode=is_test_mode)
30
- self.receipts = Receipts(url=url, payme_id=payme_id, payme_key=payme_key) # noqa
28
+ self.initializer = Initializer(
29
+ payme_id=payme_id, fallback_id=fallback_id, is_test_mode=is_test_mode
30
+ )
31
+ if payme_key:
32
+ self.receipts = Receipts(url=url, payme_id=payme_id, payme_key=payme_key)
@@ -13,17 +13,14 @@ class Initializer:
13
13
  The Payme ID associated with your account
14
14
  """
15
15
 
16
- def __init__(self, payme_id: str = None, fallback_id: str = None, is_test_mode: bool = False):
16
+ def __init__(
17
+ self, payme_id: str = None, fallback_id: str = None, is_test_mode: bool = False
18
+ ) -> None:
17
19
  self.payme_id = payme_id
18
20
  self.fallback_id = fallback_id
19
21
  self.is_test_mode = is_test_mode
20
22
 
21
- def generate_pay_link(
22
- self,
23
- id: int,
24
- amount: int,
25
- return_url: str
26
- ) -> str:
23
+ def generate_pay_link(self, id: int, amount: int, return_url: str) -> str:
27
24
  """
28
25
  Generate a payment link for a specific order.
29
26
 
@@ -52,9 +49,7 @@ class Initializer:
52
49
  https://developer.help.paycom.uz/initsializatsiya-platezhey/
53
50
  """
54
51
  amount = amount * 100 # Convert amount to the smallest currency unit
55
- params = (
56
- f'm={self.payme_id};ac.{settings.PAYME_ACCOUNT_FIELD}={id};a={amount};c={return_url}'
57
- )
52
+ params = f"m={self.payme_id};ac.{settings.PAYME_ACCOUNT_FIELD}={id};a={amount};c={return_url}"
58
53
  params = base64.b64encode(params.encode("utf-8")).decode("utf-8")
59
54
 
60
55
  if self.is_test_mode is True:
payme/classes/receipts.py CHANGED
@@ -1,4 +1,4 @@
1
- from typing import Union, Optional
1
+ import typing as t
2
2
 
3
3
  from payme.classes.cards import Cards
4
4
  from payme.classes.http import HttpClient
@@ -20,7 +20,8 @@ class Receipts:
20
20
  """
21
21
  The Receipts class provides methods to interact with the Payme Receipts.
22
22
  """
23
- def __init__(self, payme_id: str, payme_key: str, url: str) -> "Receipts":
23
+
24
+ def __init__(self, payme_id: str, payme_key: str, url: str) -> None:
24
25
  """
25
26
  Initialize the Receipts client.
26
27
 
@@ -32,25 +33,25 @@ class Receipts:
32
33
 
33
34
  headers = {
34
35
  "X-Auth": f"{payme_id}:{payme_key}",
35
- "Content-Type": "application/json"
36
+ "Content-Type": "application/json",
36
37
  }
37
38
  self.http = HttpClient(url, headers)
38
39
 
39
40
  def create(
40
41
  self,
41
42
  account: dict,
42
- amount: Union[float, int],
43
- description: Optional[str] = None,
44
- detail: Optional[dict] = None,
45
- timeout: int = 10
43
+ amount: t.Union[float, int],
44
+ description: t.Optional[str] = None,
45
+ detail: t.Optional[t.Dict] = None,
46
+ timeout: int = 10,
46
47
  ) -> response.CreateResponse:
47
48
  """
48
49
  Create a new receipt.
49
50
 
50
51
  :param account: The account details for the receipt.
51
52
  :param amount: The amount of the receipt.
52
- :param description: Optional description for the receipt.
53
- :param detail: Optional additional details for the receipt.
53
+ :param description: t.Optional description for the receipt.
54
+ :param detail: t.Optional additional details for the receipt.
54
55
  :param timeout: The request timeout duration in seconds (default 10).
55
56
  """
56
57
  method = "receipts.create"
@@ -58,7 +59,7 @@ class Receipts:
58
59
  "amount": amount,
59
60
  "account": account,
60
61
  "description": description,
61
- "detail": detail
62
+ "detail": detail,
62
63
  }
63
64
  return self._post_request(method, params, timeout)
64
65
 
@@ -74,10 +75,7 @@ class Receipts:
74
75
  The request timeout duration in seconds (default is 10).
75
76
  """
76
77
  method = "receipts.pay"
77
- params = {
78
- "id": receipts_id,
79
- "token": token
80
- }
78
+ params = {"id": receipts_id, "token": token}
81
79
  return self._post_request(method, params, timeout)
82
80
 
83
81
  def send(
@@ -91,15 +89,10 @@ class Receipts:
91
89
  :param timeout: The request timeout duration in seconds (default 10).
92
90
  """
93
91
  method = "receipts.send"
94
- params = {
95
- "id": receipts_id,
96
- "phone": phone
97
- }
92
+ params = {"id": receipts_id, "phone": phone}
98
93
  return self._post_request(method, params, timeout)
99
94
 
100
- def cancel(
101
- self, receipts_id: str, timeout: int = 10
102
- ) -> response.CancelResponse:
95
+ def cancel(self, receipts_id: str, timeout: int = 10) -> response.CancelResponse:
103
96
  """
104
97
  Cancel the receipt.
105
98
 
@@ -107,14 +100,10 @@ class Receipts:
107
100
  :param timeout: The request timeout duration in seconds (default 10).
108
101
  """
109
102
  method = "receipts.cancel"
110
- params = {
111
- "id": receipts_id
112
- }
103
+ params = {"id": receipts_id}
113
104
  return self._post_request(method, params, timeout)
114
105
 
115
- def check(
116
- self, receipts_id: str, timeout: int = 10
117
- ) -> response.CheckResponse:
106
+ def check(self, receipts_id: str, timeout: int = 10) -> response.CheckResponse:
118
107
  """
119
108
  Check the status of a cheque.
120
109
 
@@ -122,14 +111,10 @@ class Receipts:
122
111
  :param timeout: The request timeout duration in seconds (default 10).
123
112
  """
124
113
  method = "receipts.check"
125
- params = {
126
- "id": receipts_id
127
- }
114
+ params = {"id": receipts_id}
128
115
  return self._post_request(method, params, timeout)
129
116
 
130
- def get(
131
- self, receipts_id: str, timeout: int = 10
132
- ) -> response.GetResponse:
117
+ def get(self, receipts_id: str, timeout: int = 10) -> response.GetResponse:
133
118
  """
134
119
  Get the details of a specific cheque.
135
120
 
@@ -137,30 +122,23 @@ class Receipts:
137
122
  :param timeout: The request timeout duration in seconds (default 10).
138
123
  """
139
124
  method = "receipts.get"
140
- params = {
141
- "id": receipts_id
142
- }
125
+ params = {"id": receipts_id}
143
126
  return self._post_request(method, params, timeout)
144
127
 
145
128
  def get_all(
146
129
  self, count: int, from_: int, to: int, offset: int, timeout: int = 10
147
130
  ) -> response.GetAllResponse:
148
131
  """
149
- Get all cheques for a specific account.
132
+ Get all cheques for a specific account.
150
133
 
151
- :param count: The number of cheques to retrieve.
152
- :param from_: The start index of the cheques to retrieve.
153
- :param to: The end index of the cheques to retrieve.
154
- :param offset: The offset for pagination.
155
- :param timeout: The request timeout duration in seconds (default 10).
134
+ :param count: The number of cheques to retrieve.
135
+ :param from_: The start index of the cheques to retrieve.
136
+ :param to: The end index of the cheques to retrieve.
137
+ :param offset: The offset for pagination.
138
+ :param timeout: The request timeout duration in seconds (default 10).
156
139
  """
157
140
  method = "receipts.get_all"
158
- params = {
159
- "count": count,
160
- "from": from_,
161
- "to": to,
162
- "offset": offset
163
- }
141
+ params = {"count": count, "from": from_, "to": to, "offset": offset}
164
142
  return self._post_request(method, params, timeout)
165
143
 
166
144
  def _post_request(
@@ -185,6 +163,7 @@ class Receipts:
185
163
  covering creation, payment, sending, cancellation, status checks,
186
164
  retrieval of a single receipt, and retrieval of multiple receipts.
187
165
  """
166
+
188
167
  # Helper to assert conditions with messaging
189
168
  def assert_condition(condition, message, test_case):
190
169
  self._assert_and_print(condition, message, test_case=test_case)
@@ -195,14 +174,14 @@ class Receipts:
195
174
  account={"id": 12345},
196
175
  amount=1000,
197
176
  description="Test receipt",
198
- detail={"key": "value"}
177
+ detail={"key": "value"},
199
178
  )
200
179
 
201
180
  # Test 1: Initialization check
202
181
  assert_condition(
203
182
  isinstance(self, Receipts),
204
183
  "Initialized Receipts class successfully.",
205
- test_case="Initialization Test"
184
+ test_case="Initialization Test",
206
185
  )
207
186
 
208
187
  # Test 2: Create and Pay Receipt
@@ -210,21 +189,19 @@ class Receipts:
210
189
  assert_condition(
211
190
  isinstance(create_response, response.CreateResponse),
212
191
  "Created a new receipt successfully.",
213
- test_case="Receipt Creation Test"
192
+ test_case="Receipt Creation Test",
214
193
  )
215
194
 
216
195
  # pylint: disable=W0212
217
196
  assert_condition(
218
197
  isinstance(create_response.result.receipt._id, str),
219
198
  "Created a valid receipt ID.",
220
- test_case="Receipt ID Test"
199
+ test_case="Receipt ID Test",
221
200
  )
222
201
 
223
202
  # Prepare card and verification
224
203
  cards_create_response = self.__cards.create(
225
- number="8600495473316478",
226
- expire="0399",
227
- save=True
204
+ number="8600495473316478", expire="0399", save=True
228
205
  )
229
206
  token = cards_create_response.result.card.token
230
207
  self.__cards.get_verify_code(token=token)
@@ -236,7 +213,7 @@ class Receipts:
236
213
  assert_condition(
237
214
  pay_response.result.receipt.state == 4,
238
215
  "Paid the receipt successfully.",
239
- test_case="Payment Test"
216
+ test_case="Payment Test",
240
217
  )
241
218
 
242
219
  # Test 3: Create and Send Receipt
@@ -246,7 +223,7 @@ class Receipts:
246
223
  assert_condition(
247
224
  send_response.result.success is True,
248
225
  "Sent the receipt successfully.",
249
- test_case="Send Test"
226
+ test_case="Send Test",
250
227
  )
251
228
 
252
229
  # Test 4: Create and Cancel Receipt
@@ -256,7 +233,7 @@ class Receipts:
256
233
  assert_condition(
257
234
  cancel_response.result.receipt.state == 50,
258
235
  "Cancelled the receipt successfully.",
259
- test_case="Cancel Test"
236
+ test_case="Cancel Test",
260
237
  )
261
238
 
262
239
  # Test 5: Check Receipt Status
@@ -264,7 +241,7 @@ class Receipts:
264
241
  assert_condition(
265
242
  check_response.result.state == 50,
266
243
  "Checked the receipt status successfully.",
267
- test_case="Check Test"
244
+ test_case="Check Test",
268
245
  )
269
246
 
270
247
  # Test 6: Get Receipt Details
@@ -272,27 +249,21 @@ class Receipts:
272
249
  assert_condition(
273
250
  get_response.result.receipt._id == receipt_id,
274
251
  "Retrieved the receipt details successfully.",
275
- test_case="Get Test"
252
+ test_case="Get Test",
276
253
  )
277
254
 
278
255
  # Test 7: Retrieve All Receipts
279
256
  get_all_response = self.get_all(
280
- count=1,
281
- from_=1730322122000,
282
- to=1730398982000,
283
- offset=0
257
+ count=1, from_=1730322122000, to=1730398982000, offset=0
284
258
  )
285
259
  assert_condition(
286
260
  isinstance(get_all_response.result, list),
287
261
  "Retrieved all receipts successfully.",
288
- test_case="Get All Test"
262
+ test_case="Get All Test",
289
263
  )
290
264
 
291
265
  # pylint: disable=W0212
292
266
  def _assert_and_print(
293
- self,
294
- condition: bool,
295
- success_message: str,
296
- test_case: Optional[str] = None
267
+ self, condition: bool, success_message: str, test_case: t.Optional[str] = None
297
268
  ):
298
269
  self.__cards._assert_and_print(condition, success_message, test_case)
@@ -1,28 +1,31 @@
1
1
  """
2
2
  Init Payme base exception.
3
3
  """
4
+
4
5
  import logging
6
+ import typing as t
7
+
8
+ from rest_framework import status
5
9
  from rest_framework.exceptions import APIException
6
10
 
7
11
  logger = logging.getLogger(__name__)
8
12
 
13
+ MessageT = t.Optional[t.Union[str, t.Dict[str, str]]]
14
+
9
15
 
10
16
  class BasePaymeException(APIException):
11
17
  """
12
18
  BasePaymeException inherits from APIException.
13
19
  """
14
- status_code = 200
15
- error_code = None
16
- message = None
20
+
21
+ status_code: int = status.HTTP_200_OK
22
+ error_code: t.Optional[int] = None
23
+ message: MessageT = None
17
24
 
18
25
  # pylint: disable=super-init-not-called
19
26
  def __init__(self, message: str = None):
20
27
  detail: dict = {
21
- "error": {
22
- "code": self.error_code,
23
- "message": self.message,
24
- "data": message
25
- }
28
+ "error": {"code": self.error_code, "message": self.message, "data": message}
26
29
  }
27
30
  logger.error(f"Payme error detail: {detail}")
28
31
  self.detail = detail
@@ -34,7 +37,8 @@ class PermissionDenied(BasePaymeException):
34
37
 
35
38
  Raised when the client is not allowed to access the server.
36
39
  """
37
- status_code = 200
40
+
41
+ status_code = status.HTTP_200_OK
38
42
  error_code = -32504
39
43
  message = "Permission denied."
40
44
 
@@ -45,12 +49,13 @@ class InternalServiceError(BasePaymeException):
45
49
 
46
50
  Raised when a transaction fails to perform.
47
51
  """
48
- status_code = 200
52
+
53
+ status_code = status.HTTP_200_OK
49
54
  error_code = -32400
50
55
  message = {
51
56
  "uz": "Tizimda xatolik yuzaga keldi.",
52
57
  "ru": "Внутренняя ошибка сервиса.",
53
- "en": "Internal service error."
58
+ "en": "Internal service error.",
54
59
  }
55
60
 
56
61
 
@@ -60,7 +65,8 @@ class MethodNotFound(BasePaymeException):
60
65
 
61
66
  Raised when the requested method does not exist.
62
67
  """
63
- status_code = 405
68
+
69
+ status_code = status.HTTP_405_METHOD_NOT_ALLOWED
64
70
  error_code = -32601
65
71
  message = "Method not found."
66
72
 
@@ -71,12 +77,13 @@ class AccountDoesNotExist(BasePaymeException):
71
77
 
72
78
  Raised when an account does not exist or has been deleted.
73
79
  """
74
- status_code = 200
80
+
81
+ status_code = status.HTTP_200_OK
75
82
  error_code = -31050
76
83
  message = {
77
84
  "uz": "Hisob topilmadi.",
78
85
  "ru": "Счет не найден.",
79
- "en": "Account does not exist."
86
+ "en": "Account does not exist.",
80
87
  }
81
88
 
82
89
 
@@ -86,12 +93,13 @@ class IncorrectAmount(BasePaymeException):
86
93
 
87
94
  Raised when the provided amount is incorrect.
88
95
  """
89
- status_code = 200
96
+
97
+ status_code = status.HTTP_200_OK
90
98
  error_code = -31001
91
99
  message = {
92
- 'ru': 'Неверная сумма.',
93
- 'uz': "Noto'g'ri summa.",
94
- 'en': 'Incorrect amount.'
100
+ "ru": "Неверная сумма.",
101
+ "uz": "Noto'g'ri summa.",
102
+ "en": "Incorrect amount.",
95
103
  }
96
104
 
97
105
 
@@ -107,12 +115,45 @@ class TransactionAlreadyExists(BasePaymeException):
107
115
  error_code (int): The specific error code for this exception.
108
116
  message (dict): A dictionary containing localized error messages.
109
117
  """
110
- status_code = 200
118
+
119
+ status_code = status.HTTP_200_OK
111
120
  error_code = -31099
112
121
  message = {
113
122
  "uz": "Tranzaksiya allaqachon mavjud.",
114
123
  "ru": "Транзакция уже существует.",
115
- "en": "Transaction already exists."
124
+ "en": "Transaction already exists.",
125
+ }
126
+
127
+
128
+ class InvalidFiscalParams(BasePaymeException):
129
+ """
130
+ InvalidFiscalParams APIException.
131
+
132
+ Raised when the provided fiscal parameters are invalid.
133
+ """
134
+
135
+ status_code = status.HTTP_200_OK
136
+ error_code = -32602
137
+ message = {
138
+ "uz": "Fiskal parameterlarida kamchiliklar bor",
139
+ "ru": "Неверные фискальные параметры.",
140
+ "en": "Invalid fiscal parameters.",
141
+ }
142
+
143
+
144
+ class InvalidAccount(BasePaymeException):
145
+ """
146
+ InvalidAccount APIException.
147
+
148
+ Raised when the provided account is invalid.
149
+ """
150
+
151
+ status_code = status.HTTP_200_OK
152
+ error_code = -32400
153
+ message = {
154
+ "uz": "Hisob nomida kamchilik bor",
155
+ "ru": "Неверный номер счета.",
156
+ "en": "Invalid account.",
116
157
  }
117
158
 
118
159
 
@@ -121,5 +162,7 @@ exception_whitelist = (
121
162
  MethodNotFound,
122
163
  PermissionDenied,
123
164
  AccountDoesNotExist,
124
- TransactionAlreadyExists
165
+ TransactionAlreadyExists,
166
+ InvalidFiscalParams,
167
+ InvalidAccount,
125
168
  )
@@ -0,0 +1,18 @@
1
+ # Generated by Django 5.1.2 on 2025-03-14 08:01
2
+
3
+ from django.db import migrations, models
4
+
5
+
6
+ class Migration(migrations.Migration):
7
+
8
+ dependencies = [
9
+ ("payme", "0001_initial"),
10
+ ]
11
+
12
+ operations = [
13
+ migrations.AddField(
14
+ model_name="paymetransactions",
15
+ name="fiscal_data",
16
+ field=models.JSONField(blank=True, null=True),
17
+ ),
18
+ ]
@@ -0,0 +1,18 @@
1
+ # Generated by Django 5.1.2 on 2025-03-14 08:20
2
+
3
+ from django.db import migrations, models
4
+
5
+
6
+ class Migration(migrations.Migration):
7
+
8
+ dependencies = [
9
+ ("payme", "0002_paymetransactions_fiscal_data"),
10
+ ]
11
+
12
+ operations = [
13
+ migrations.AlterField(
14
+ model_name="paymetransactions",
15
+ name="fiscal_data",
16
+ field=models.JSONField(default=dict),
17
+ ),
18
+ ]
payme/models.py CHANGED
@@ -29,6 +29,7 @@ class PaymeTransactions(models.Model):
29
29
  account_id = models.BigIntegerField(null=False)
30
30
  amount = models.DecimalField(max_digits=10, decimal_places=2)
31
31
  state = models.IntegerField(choices=STATE, default=CREATED)
32
+ fiscal_data = models.JSONField(default=dict)
32
33
  cancel_reason = models.IntegerField(null=True, blank=True)
33
34
  created_at = models.DateTimeField(auto_now_add=True, db_index=True)
34
35
  updated_at = models.DateTimeField(auto_now=True, db_index=True)
@@ -1,14 +1,15 @@
1
- from typing import Dict, Optional
1
+ import typing as t
2
2
  from dataclasses import dataclass
3
3
 
4
4
 
5
+ @dataclass
5
6
  class Common:
6
7
  """
7
8
  The common response structure.
8
9
  """
9
10
 
10
11
  @classmethod
11
- def from_dict(cls, data: Dict):
12
+ def from_dict(cls, data: t.Dict):
12
13
  """
13
14
  Prepare fields for nested dataclasses
14
15
  """
@@ -30,13 +31,14 @@ class Card(Common):
30
31
  """
31
32
  The card object represents a credit card.
32
33
  """
34
+
33
35
  number: str
34
36
  expire: str
35
37
  token: str
36
38
  recurrent: bool
37
39
  verify: bool
38
40
  type: str
39
- number_hash: Optional[str] = None
41
+ number_hash: t.Optional[str] = None
40
42
 
41
43
 
42
44
  @dataclass
@@ -44,6 +46,7 @@ class Result(Common):
44
46
  """
45
47
  The result object contains the created card.
46
48
  """
49
+
47
50
  card: Card
48
51
 
49
52
 
@@ -52,6 +55,7 @@ class CardsCreateResponse(Common):
52
55
  """
53
56
  The cards.create response.
54
57
  """
58
+
55
59
  jsonrpc: str
56
60
  result: Result
57
61
 
@@ -61,6 +65,7 @@ class VerifyResult(Common):
61
65
  """
62
66
  The result object for the verification response.
63
67
  """
68
+
64
69
  sent: bool
65
70
  phone: str
66
71
  wait: int
@@ -71,6 +76,7 @@ class GetVerifyResponse(Common):
71
76
  """
72
77
  The verification response structure.
73
78
  """
79
+
74
80
  jsonrpc: str
75
81
  result: VerifyResult
76
82
 
@@ -80,6 +86,7 @@ class VerifyResponse(Common):
80
86
  """
81
87
  The verification response structure.
82
88
  """
89
+
83
90
  jsonrpc: str
84
91
  result: Result
85
92
 
@@ -89,6 +96,7 @@ class RemoveCardResult(Common):
89
96
  """
90
97
  The result object for the removal response.
91
98
  """
99
+
92
100
  success: bool
93
101
 
94
102
 
@@ -97,6 +105,7 @@ class RemoveResponse(Common):
97
105
  """
98
106
  The remove response structure.
99
107
  """
108
+
100
109
  jsonrpc: str
101
110
  result: RemoveCardResult
102
111
 
@@ -106,5 +115,6 @@ class CheckResponse(Common):
106
115
  """
107
116
  The check response structure.
108
117
  """
118
+
109
119
  jsonrpc: str
110
120
  result: Result
@@ -1,16 +1,18 @@
1
+ import typing as t
1
2
  from dataclasses import dataclass
2
- from typing import Dict, Optional, Union
3
3
 
4
4
 
5
+ @dataclass
5
6
  class Common:
6
7
  """
7
8
  The common response structure.
8
9
  """
10
+
9
11
  jsonrpc: str
10
12
  id: int
11
13
 
12
14
  @classmethod
13
- def from_dict(cls, data: Dict):
15
+ def from_dict(cls, data: t.Dict):
14
16
  """
15
17
  Prepare fields for nested dataclasses
16
18
  """
@@ -32,6 +34,7 @@ class Account(Common):
32
34
  """
33
35
  The account object represents a user's banking account.
34
36
  """
37
+
35
38
  _id: str
36
39
  account_number: str
37
40
  account_name: str
@@ -46,10 +49,11 @@ class PaymentMethod(Common):
46
49
  """
47
50
  The payment method object represents a user's payment method.
48
51
  """
52
+
49
53
  name: str
50
54
  title: str
51
55
  value: str
52
- main: Optional[bool] = None
56
+ main: t.Optional[bool] = None
53
57
 
54
58
 
55
59
  @dataclass
@@ -57,9 +61,10 @@ class Detail(Common):
57
61
  """
58
62
  The detail object represents additional details for a receipt.
59
63
  """
60
- discount: Optional[str] = None
61
- shipping: Optional[str] = None
62
- items: Optional[str] = None
64
+
65
+ discount: t.Optional[str] = None
66
+ shipping: t.Optional[str] = None
67
+ items: t.Optional[str] = None
63
68
 
64
69
 
65
70
  # pylint: disable=C0103
@@ -68,6 +73,7 @@ class MerchantEpos(Common):
68
73
  """
69
74
  The merchantEpos object represents a user's ePOS.
70
75
  """
76
+
71
77
  eposId: str
72
78
  eposName: str
73
79
  eposType: str
@@ -79,9 +85,10 @@ class Meta(Common):
79
85
  """
80
86
  The meta object represents additional metadata for a receipt.
81
87
  """
82
- source: any = None
83
- owner: any = None
84
- host: any = None
88
+
89
+ source: t.Any = None
90
+ owner: t.Any = None
91
+ host: t.Any = None
85
92
 
86
93
 
87
94
  @dataclass
@@ -89,17 +96,18 @@ class Merchant:
89
96
  """
90
97
  The merchant object represents a user's merchant.
91
98
  """
99
+
92
100
  _id: str
93
101
  name: str
94
102
  organization: str
95
- address: Optional[str] = None
96
- business_id: Optional[str] = None
97
- epos: Optional[MerchantEpos] = None
98
- restrictions: Optional[str] = None
99
- date: Optional[int] = None
100
- logo: Optional[str] = None
101
- type: Optional[str] = None
102
- terms: Optional[str] = None
103
+ address: t.Optional[str] = None
104
+ business_id: t.Optional[str] = None
105
+ epos: t.Optional[MerchantEpos] = None
106
+ restrictions: t.Optional[str] = None
107
+ date: t.Optional[int] = None
108
+ logo: t.Optional[str] = None
109
+ type: t.Optional[str] = None
110
+ terms: t.Optional[str] = None
103
111
 
104
112
 
105
113
  @dataclass
@@ -107,6 +115,7 @@ class Payer(Common):
107
115
  """
108
116
  The payer object represents a user's payer.
109
117
  """
118
+
110
119
  phone: str
111
120
 
112
121
 
@@ -115,6 +124,7 @@ class Receipt(Common):
115
124
  """
116
125
  The receipt object represents a payment receipt.
117
126
  """
127
+
118
128
  _id: str
119
129
  create_time: int
120
130
  pay_time: int
@@ -123,19 +133,19 @@ class Receipt(Common):
123
133
  type: int
124
134
  external: bool
125
135
  operation: int
126
- error: any = None
127
- description: str = None
128
- detail: Detail = None
129
- currency: int = None
130
- commission: int = None
131
- card: str = None
132
- creator: str = None
133
- payer: Payer = None
134
- amount: Union[float, int] = None
135
- account: list[Account] = None
136
- merchant: Merchant = None
137
- processing_id: str = None
138
- meta: Meta = None
136
+ error: t.Any = None
137
+ description: t.Optional[str] = None
138
+ detail: t.Optional[Detail] = None
139
+ currency: t.Optional[int] = None
140
+ commission: t.Optional[int] = None
141
+ card: t.Optional[str] = None
142
+ creator: t.Optional[str] = None
143
+ payer: t.Optional[Payer] = None
144
+ amount: t.Optional[t.Union[float, int]] = None
145
+ account: t.Optional[t.List[Account]] = None
146
+ merchant: t.Optional[Merchant] = None
147
+ processing_id: t.Optional[str] = None
148
+ meta: t.Optional[Meta] = None
139
149
 
140
150
 
141
151
  @dataclass
@@ -143,6 +153,7 @@ class CreateResult(Common):
143
153
  """
144
154
  The result object for the create response.
145
155
  """
156
+
146
157
  receipt: Receipt
147
158
 
148
159
 
@@ -151,6 +162,7 @@ class CreateResponse(Common):
151
162
  """
152
163
  The create response structure.
153
164
  """
165
+
154
166
  result: CreateResult
155
167
 
156
168
 
@@ -166,6 +178,7 @@ class SendResult(Common):
166
178
  """
167
179
  The result object for the send response.
168
180
  """
181
+
169
182
  success: bool
170
183
 
171
184
 
@@ -174,6 +187,7 @@ class SendResponse(Common):
174
187
  """
175
188
  The send response structure.
176
189
  """
190
+
177
191
  result: SendResult
178
192
 
179
193
 
@@ -189,6 +203,7 @@ class CheckResult(Common):
189
203
  """
190
204
  The result object for the check response.
191
205
  """
206
+
192
207
  state: int
193
208
 
194
209
 
@@ -197,6 +212,7 @@ class CheckResponse(Common):
197
212
  """
198
213
  The check response structure.
199
214
  """
215
+
200
216
  result: CheckResult
201
217
 
202
218
 
@@ -212,4 +228,5 @@ class GetAllResponse(Common):
212
228
  """
213
229
  The result object for the get all response.
214
230
  """
215
- result: list[Receipt] = None
231
+
232
+ result: t.Optional[t.List[Receipt]] = None
@@ -1,15 +1,16 @@
1
+ import typing as t
1
2
  from dataclasses import dataclass, field
2
- from typing import List, Optional, Dict
3
3
 
4
4
 
5
5
  class CommonResponse:
6
6
  """
7
7
  The common response structure
8
8
  """
9
+
9
10
  def as_resp(self):
10
- response = {'result': {}}
11
+ response = {"result": {}}
11
12
  for key, value in self.__dict__.items():
12
- response['result'][key] = value
13
+ response["result"][key] = value
13
14
  return response
14
15
 
15
16
 
@@ -18,6 +19,7 @@ class Shipping(CommonResponse):
18
19
  """
19
20
  Shipping information response structure
20
21
  """
22
+
21
23
  title: str
22
24
  price: int
23
25
 
@@ -27,6 +29,7 @@ class Item(CommonResponse):
27
29
  """
28
30
  Item information response structure
29
31
  """
32
+
30
33
  discount: int
31
34
  title: str
32
35
  price: int
@@ -45,7 +48,7 @@ class Item(CommonResponse):
45
48
  "code": self.code,
46
49
  "units": self.units,
47
50
  "vat_percent": self.vat_percent,
48
- "package_code": self.package_code
51
+ "package_code": self.package_code,
49
52
  }
50
53
 
51
54
 
@@ -54,11 +57,12 @@ class CheckPerformTransaction(CommonResponse):
54
57
  """
55
58
  Receipt information response structure for transaction checks.
56
59
  """
60
+
57
61
  allow: bool
58
- additional: Optional[Dict[str, str]] = None
59
- receipt_type: Optional[int] = None
60
- shipping: Optional[Shipping] = None
61
- items: List[Item] = field(default_factory=list)
62
+ additional: t.Optional[t.Dict[str, str]] = None
63
+ receipt_type: t.Optional[int] = None
64
+ shipping: t.Optional[Shipping] = None
65
+ items: t.List[Item] = field(default_factory=list)
62
66
 
63
67
  def add_item(self, item: Item):
64
68
  self.items.append(item)
@@ -90,9 +94,10 @@ class CreateTransaction(CommonResponse):
90
94
  """
91
95
  The create transaction request
92
96
  """
97
+
93
98
  transaction: str
94
99
  state: str
95
- create_time: str
100
+ create_time: int
96
101
 
97
102
 
98
103
  @dataclass
@@ -100,9 +105,10 @@ class PerformTransaction(CommonResponse):
100
105
  """
101
106
  The perform transaction response
102
107
  """
108
+
103
109
  transaction: str
104
110
  state: str
105
- perform_time: str
111
+ perform_time: int
106
112
 
107
113
 
108
114
  @dataclass
@@ -110,6 +116,7 @@ class CancelTransaction(CommonResponse):
110
116
  """
111
117
  The cancel transaction request
112
118
  """
119
+
113
120
  transaction: str
114
121
  state: str
115
122
  cancel_time: str
@@ -120,12 +127,13 @@ class CheckTransaction(CommonResponse):
120
127
  """
121
128
  The check transaction request
122
129
  """
130
+
123
131
  transaction: str
124
132
  state: str
125
133
  reason: str
126
- create_time: str
127
- perform_time: Optional[str] = None
128
- cancel_time: Optional[str] = None
134
+ create_time: int
135
+ perform_time: t.Optional[int] = None
136
+ cancel_time: t.Optional[int] = None
129
137
 
130
138
 
131
139
  @dataclass
@@ -133,4 +141,14 @@ class GetStatement(CommonResponse):
133
141
  """
134
142
  The check perform transactions response
135
143
  """
136
- transactions: List[str]
144
+
145
+ transactions: t.List[t.Dict[str, str | int | t.Dict[str, str | int]]]
146
+
147
+
148
+ @dataclass
149
+ class SetFiscalData(CommonResponse):
150
+ """
151
+ The set fiscal data request
152
+ """
153
+
154
+ success: bool
payme/views.py CHANGED
@@ -66,6 +66,7 @@ class PaymeWebHookAPIView(views.APIView):
66
66
  "CreateTransaction": self.create_transaction,
67
67
  "CheckTransaction": self.check_transaction,
68
68
  "CheckPerformTransaction": self.check_perform_transaction,
69
+ "SetFiscalData": self.set_fiscal_data,
69
70
  }
70
71
 
71
72
  try:
@@ -300,6 +301,33 @@ class PaymeWebHookAPIView(views.APIView):
300
301
 
301
302
  return result.as_resp()
302
303
 
304
+ @handle_exceptions
305
+ def set_fiscal_data(self, params):
306
+ """
307
+ Set fiscal data for the given transaction.
308
+ """
309
+ transaction = PaymeTransactions.get_by_transaction_id(transaction_id=params["id"])
310
+
311
+ fiscal_data = params.get("fiscal_data")
312
+ if not fiscal_data:
313
+ raise exceptions.InvalidFiscalParams(
314
+ "Missing fiscal_data field in parameters."
315
+ )
316
+
317
+ fiscal_type = params.get("type")
318
+
319
+ if fiscal_type not in ("PERFORM", "CANCEL"):
320
+ raise exceptions.InvalidFiscalParams(
321
+ f"Invalid fiscal type. Expected 'PERFORM' or 'CANCEL', got: {fiscal_type}"
322
+ )
323
+
324
+ fiscal_data["type"] = fiscal_type
325
+ transaction.fiscal_data = fiscal_data
326
+ transaction.save()
327
+
328
+ result = response.SetFiscalData(success=True)
329
+ return result.as_resp()
330
+
303
331
  def _cancel_response(self, transaction):
304
332
  """
305
333
  Helper method to generate cancel transaction response.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: payme-pkg
3
- Version: 3.0.22
3
+ Version: 3.0.25b0
4
4
  Home-page: https://github.com/Muhammadali-Akbarov/payme-pkg
5
5
  Author: Muhammadali Akbarov
6
6
  Author-email: muhammadali17abc@gmail.com
@@ -89,6 +89,8 @@ PAYME_KEY = "your-payme-key"
89
89
  PAYME_ACCOUNT_FIELD = "id"
90
90
  PAYME_ACCOUNT_MODEL = "clients.models.Client"
91
91
  PAYME_ONE_TIME_PAYMENT = False
92
+
93
+ PAYME_DISABLE_ADMIN = False (optionally configuration if you want to disable change to True)
92
94
  ```
93
95
 
94
96
  Create a new View that about handling call backs
@@ -0,0 +1,32 @@
1
+ payme/__init__.py,sha256=dzLIyA9kQl0sO6z9nHkZDTjkfiI1BepdifKtJbjX2Cw,46
2
+ payme/admin.py,sha256=k4_kAX6k8993aQo_7xokIc7InUVw4LGZT5ROn-C9EYU,561
3
+ payme/apps.py,sha256=HHCY4zUNKPcjz25z0MahZcks0lsAxTGPS0Ml3U4DhZc,142
4
+ payme/const.py,sha256=azndfKR53fe7mDfGW82Q-kwWdMu3x4S1upKc4gkYdlA,214
5
+ payme/models.py,sha256=nOVmknNjQkBos7w069ddAp_wTBj14UssdTgO8w8sTdI,4179
6
+ payme/urls.py,sha256=_oUOwxW1Suc5TUmnj--lySYbotRg4yTDkDLJU20CGjE,145
7
+ payme/util.py,sha256=UFb4cEnaufS_hh9C_0z079CSgJGivYjIgOl2iAFrBMs,625
8
+ payme/views.py,sha256=gSQgctinjjAWhEO-kCIF4Jn01yapzHRi2ovtkc6JgJw,12873
9
+ payme/classes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ payme/classes/cards.py,sha256=hjg3Wg189INeStGArQUnoxAAutKFbB6BnwYtMGLA0x0,7621
11
+ payme/classes/client.py,sha256=HqJdFvgSBKxYsitAukYp6_UEa3J6ChVBUbUC1aGR2XM,904
12
+ payme/classes/http.py,sha256=OufMeHrj0jTomDJx_6go9GC1NtA6QpQCxIiM3ISy3Eo,3530
13
+ payme/classes/initializer.py,sha256=Pwb1oCUZzcW-ftFzaLMr8ySguC7fKsbeQ4vGmupYliw,2448
14
+ payme/classes/receipts.py,sha256=dnaK-cNcw09tC4x7d_dEdIIxas9YGPhlJCDgCKtKCgo,9789
15
+ payme/exceptions/__init__.py,sha256=HoBFnDA3eW_xWZiFlonJK4vhBDTsuik91tvgzXTy8KA,94
16
+ payme/exceptions/general.py,sha256=-rkzvuLi6VoITMLrszrP7c-gM8X6lM8AWttd770KSJc,7679
17
+ payme/exceptions/webhook.py,sha256=ZW6HnjxZDQScaX0WLXltcEllCwl1m0JuCtEnR28shME,4090
18
+ payme/migrations/0001_initial.py,sha256=jdtGB6bN-Za6N9XU8IuWsa5FbonGIRH5ro9xHwT7JmU,2128
19
+ payme/migrations/0002_paymetransactions_fiscal_data.py,sha256=z-gxPP3IgN-XNPx6DEZUQ4E1XZceVnnpvUTcSkcv70c,395
20
+ payme/migrations/0003_alter_paymetransactions_fiscal_data.py,sha256=Ish4Seup9pdEM0g4q4RQKrvUOWB2DXPN0RmIScKI2IQ,410
21
+ payme/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
+ payme/types/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
+ payme/types/request/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
+ payme/types/response/__init__.py,sha256=GAj5pjZ9oIO67T6YMiPd1fhTIvGrPfTv96tykfeChQc,81
25
+ payme/types/response/cards.py,sha256=ncGaE5NzI5AJLbrzR41G7jkUHXO71BnrIiaiV-lKsPo,2006
26
+ payme/types/response/receipts.py,sha256=nFTMwL2CEGo-7BcdZ9p3wiqYjzYHnMk5nZgsTi6KHcs,4271
27
+ payme/types/response/webhook.py,sha256=E8IVD683T7wra4OxUWq5T6y7HGpjwOVk8ak0tS0b-_o,3084
28
+ payme_pkg-3.0.25b0.dist-info/LICENSE.txt,sha256=75dBVYmbzWUhwtaB1MSZfj-M-PGaMmeT9UVPli2-ZJ0,1086
29
+ payme_pkg-3.0.25b0.dist-info/METADATA,sha256=GM8XhXu03CMEMt8nAfagFPue0LratiNjj_xYC2F5siA,5374
30
+ payme_pkg-3.0.25b0.dist-info/WHEEL,sha256=Mdi9PDNwEZptOjTlUcAth7XJDFtKrHYaQMPulZeBCiQ,91
31
+ payme_pkg-3.0.25b0.dist-info/top_level.txt,sha256=8mN-hGAa38pWbhrKHFs9CZywPCdidhMuwPKwuFJa0qw,6
32
+ payme_pkg-3.0.25b0.dist-info/RECORD,,
@@ -1,30 +0,0 @@
1
- payme/__init__.py,sha256=dzLIyA9kQl0sO6z9nHkZDTjkfiI1BepdifKtJbjX2Cw,46
2
- payme/admin.py,sha256=QW93VTNRZ3qr2eMySX0odyQDmBXJDMXVPCzJPLH78GI,468
3
- payme/apps.py,sha256=HHCY4zUNKPcjz25z0MahZcks0lsAxTGPS0Ml3U4DhZc,142
4
- payme/const.py,sha256=azndfKR53fe7mDfGW82Q-kwWdMu3x4S1upKc4gkYdlA,214
5
- payme/models.py,sha256=C0-dbXEpzZBx1-GsdBXwKQt7gJ6AvgPO6l-3VljfNtw,4130
6
- payme/urls.py,sha256=_oUOwxW1Suc5TUmnj--lySYbotRg4yTDkDLJU20CGjE,145
7
- payme/util.py,sha256=UFb4cEnaufS_hh9C_0z079CSgJGivYjIgOl2iAFrBMs,625
8
- payme/views.py,sha256=AYWXP9zJGcLkTM91RIiL6Ou4RHqLph3NyYIlzPAN3fU,11939
9
- payme/classes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- payme/classes/cards.py,sha256=dr3SQdKAhfQmECtwHYW2nmx8wXaNYQFkg5uQU9z8vs4,7624
11
- payme/classes/client.py,sha256=Fjck3vSRh8-NQ8HnxwytCn_qZm6UfwMKCBYDHtUSJAs,864
12
- payme/classes/http.py,sha256=OufMeHrj0jTomDJx_6go9GC1NtA6QpQCxIiM3ISy3Eo,3530
13
- payme/classes/initializer.py,sha256=TWJnlJTXefROMleIvJeT64xjIVWQU-LIXai8TZ_M7nw,2488
14
- payme/classes/receipts.py,sha256=KU4qyGHWZpWW88SjmmTD_N2Tz8pWOCvBbOPnw5tcS3Y,10094
15
- payme/exceptions/__init__.py,sha256=HoBFnDA3eW_xWZiFlonJK4vhBDTsuik91tvgzXTy8KA,94
16
- payme/exceptions/general.py,sha256=-rkzvuLi6VoITMLrszrP7c-gM8X6lM8AWttd770KSJc,7679
17
- payme/exceptions/webhook.py,sha256=f0J-fmCW_wpgsTmjGAOtyoZjIOoFpbQwkh_7cZUZkv0,3046
18
- payme/migrations/0001_initial.py,sha256=jdtGB6bN-Za6N9XU8IuWsa5FbonGIRH5ro9xHwT7JmU,2128
19
- payme/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
- payme/types/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
- payme/types/request/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
- payme/types/response/__init__.py,sha256=GAj5pjZ9oIO67T6YMiPd1fhTIvGrPfTv96tykfeChQc,81
23
- payme/types/response/cards.py,sha256=ilXFDUOPNabVsrQN1KWEzDiL6cDxdVvCbfEl6jCzGpU,1997
24
- payme/types/response/receipts.py,sha256=TlZeJyymRVHIorg0kbUaogy6MZxN1oq2jHGVRUnlY5A,4070
25
- payme/types/response/webhook.py,sha256=Br6Gr_-h7sCmOc3ag7H5yBryB8j-bm2mrt39Cy_Fy2E,2918
26
- payme_pkg-3.0.22.dist-info/LICENSE.txt,sha256=75dBVYmbzWUhwtaB1MSZfj-M-PGaMmeT9UVPli2-ZJ0,1086
27
- payme_pkg-3.0.22.dist-info/METADATA,sha256=c5D9qqGVK_qD6SPkvlpxEDePViDZVE0zK0S09KS1bGo,5278
28
- payme_pkg-3.0.22.dist-info/WHEEL,sha256=Mdi9PDNwEZptOjTlUcAth7XJDFtKrHYaQMPulZeBCiQ,91
29
- payme_pkg-3.0.22.dist-info/top_level.txt,sha256=8mN-hGAa38pWbhrKHFs9CZywPCdidhMuwPKwuFJa0qw,6
30
- payme_pkg-3.0.22.dist-info/RECORD,,