Skip to content

Commit bb7bd5e

Browse files
Merge pull request #36 from hoosnick/master
fix: account_id field
2 parents 63b932c + be82f20 commit bb7bd5e

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.2.5 on 2025-08-25 19:12
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("payme", "0003_alter_paymetransactions_fiscal_data"),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name="paymetransactions",
15+
name="account_id",
16+
field=models.CharField(max_length=256),
17+
),
18+
]

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: 12 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,17 @@ 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 (
177+
PaymeTransactions.objects.filter(account_id=account.pk)
178+
.exclude(transaction_id=transaction_id)
179+
.exists()
180+
):
179181
message = f"Transaction {transaction_id} already exists (Payme)."
180182
logger.warning(message)
181183
raise exceptions.TransactionAlreadyExists(message)

0 commit comments

Comments
 (0)