Skip to content

Commit afa6274

Browse files
small fix and improvements
1 parent e407abe commit afa6274

File tree

7 files changed

+107
-2
lines changed

7 files changed

+107
-2
lines changed

payme/exceptions/webhook.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,42 @@ class TransactionAlreadyExists(BasePaymeException):
116116
}
117117

118118

119+
class InvalidFiscalParams(BasePaymeException):
120+
"""
121+
InvalidFiscalParams APIException.
122+
123+
Raised when the provided fiscal parameters are invalid.
124+
"""
125+
status_code = 200
126+
error_code = -32602
127+
message = {
128+
"uz": "Fiskal parameterlarida kamchiliklar bor",
129+
"ru": "Неверные фискальные параметры.",
130+
"en": "Invalid fiscal parameters."
131+
}
132+
133+
134+
class InvalidAccount(BasePaymeException):
135+
"""
136+
InvalidAccount APIException.
137+
138+
Raised when the provided account is invalid.
139+
"""
140+
status_code = 200
141+
error_code = -32400
142+
message = {
143+
"uz": "Hisob nomida kamchilik bor",
144+
"ru": "Неверный номер счета.",
145+
"en": "Invalid account."
146+
}
147+
148+
119149
exception_whitelist = (
120150
IncorrectAmount,
121151
MethodNotFound,
122152
PermissionDenied,
123153
AccountDoesNotExist,
124-
TransactionAlreadyExists
154+
TransactionAlreadyExists,
155+
InvalidFiscalParams,
156+
InvalidAccount
125157
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class PaymeTransactions(models.Model):
2929
account_id = models.BigIntegerField(null=False)
3030
amount = models.DecimalField(max_digits=10, decimal_places=2)
3131
state = models.IntegerField(choices=STATE, default=CREATED)
32+
fiscal_data = models.JSONField(default=dict)
3233
cancel_reason = models.IntegerField(null=True, blank=True)
3334
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
3435
updated_at = models.DateTimeField(auto_now=True, db_index=True)

payme/types/response/webhook.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,11 @@ class GetStatement(CommonResponse):
134134
The check perform transactions response
135135
"""
136136
transactions: List[str]
137+
138+
139+
@dataclass
140+
class SetFiscalData(CommonResponse):
141+
"""
142+
The set fiscal data request
143+
"""
144+
success: bool

payme/views.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def post(self, request, *args, **kwargs):
6666
"CreateTransaction": self.create_transaction,
6767
"CheckTransaction": self.check_transaction,
6868
"CheckPerformTransaction": self.check_perform_transaction,
69+
"SetFiscalData": self.set_fiscal_data,
6970
}
7071

7172
try:
@@ -300,6 +301,33 @@ def get_statement(self, params) -> response.GetStatement:
300301

301302
return result.as_resp()
302303

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+
303331
def _cancel_response(self, transaction):
304332
"""
305333
Helper method to generate cancel transaction response.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name='payme-pkg',
11-
version='3.0.21',
11+
version='3.0.23',
1212
license='MIT',
1313
author="Muhammadali Akbarov",
1414
author_email='muhammadali17abc@gmail.com',

0 commit comments

Comments
 (0)