Skip to content

Commit bd66e3d

Browse files
committed
fix: update account_id field type
1 parent bf05edf commit bd66e3d

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

payme/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class PaymeTransactionsUI(admin.ModelAdmin):
88
"""
99
Custom admin interface for PaymeTransactions model.
1010
"""
11-
list_display = ('id', 'state', 'cancel_reason', 'created_at')
11+
list_display = ('pk', 'state', 'cancel_reason', 'created_at')
1212
list_filter = ('state', 'cancel_reason', 'created_at')
1313
search_fields = ('transaction_id', 'account_id')
1414
ordering = ('-created_at',)

payme/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class PaymeTransactions(models.Model):
2626
]
2727

2828
transaction_id = models.CharField(max_length=50)
29-
account_id = models.BigIntegerField(null=False)
29+
account_id = models.CharField(max_length=256, null=False)
3030
amount = models.DecimalField(max_digits=10, decimal_places=2)
3131
state = models.IntegerField(choices=STATE, default=CREATED)
3232
fiscal_data = models.JSONField(default=dict)

payme/views.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from decimal import Decimal
55

66
from django.conf import settings
7+
from django.core.exceptions import ValidationError
78
from django.utils.module_loading import import_string
89
from rest_framework import views
910
from rest_framework.response import Response
@@ -33,6 +34,9 @@ def wrapper(*args, **kwargs):
3334
logger.error(f"Account does not exist: {exc} {args} {kwargs}")
3435
raise exceptions.AccountDoesNotExist(str(exc)) from exc
3536

37+
except ValidationError:
38+
raise exceptions.AccountDoesNotExist("Invalid account identifier.")
39+
3640
except PaymeTransactions.DoesNotExist as exc:
3741
logger.error(f"Transaction does not exist: {exc} {args} {kwargs}")
3842
raise exceptions.AccountDoesNotExist(str(exc)) from exc
@@ -112,17 +116,11 @@ def fetch_account(self, params: dict):
112116
"""
113117
Fetch account based on settings and params.
114118
"""
115-
account_field = settings.PAYME_ACCOUNT_FIELD
116-
117-
account_value = params['account'].get(account_field)
119+
account_value = params["account"].get(settings.PAYME_ACCOUNT_FIELD)
118120
if not account_value:
119121
raise exceptions.InvalidAccount("Missing account field in parameters.")
120122

121-
# hard change
122-
if account_field == "order_id":
123-
account_field = "id"
124-
125-
account = AccountModel.objects.get(**{account_field: account_value})
123+
account = AccountModel.objects.get(pk=account_value)
126124

127125
return account
128126

@@ -169,13 +167,13 @@ def create_transaction(self, params) -> response.CreateTransaction:
169167
defaults = {
170168
"amount": amount,
171169
"state": PaymeTransactions.INITIATING,
172-
"account_id": account.id,
170+
"account_id": account.pk,
173171
}
174172

175173
# Handle already existing transaction with the same ID for one-time payments
176174
if settings.PAYME_ONE_TIME_PAYMENT:
177175
# Check for an existing transaction with a different transaction_id for the given account
178-
if PaymeTransactions.objects.filter(account_id=account.id).exclude(transaction_id=transaction_id).exists():
176+
if PaymeTransactions.objects.filter(account_id=account.pk).exclude(transaction_id=transaction_id).exists():
179177
message = f"Transaction {transaction_id} already exists (Payme)."
180178
logger.warning(message)
181179
raise exceptions.TransactionAlreadyExists(message)

0 commit comments

Comments
 (0)