uuid instead of code in payments
This commit is contained in:
parent
eefd2ecef6
commit
84149c03f4
7 changed files with 31 additions and 29 deletions
|
|
@ -4,7 +4,7 @@ from .models import Transaction
|
|||
|
||||
class TransactionAdmin(admin.ModelAdmin):
|
||||
fields = [
|
||||
'code',
|
||||
'uuid',
|
||||
'amount',
|
||||
'payer',
|
||||
'payee',
|
||||
|
|
@ -15,7 +15,7 @@ class TransactionAdmin(admin.ModelAdmin):
|
|||
'detail_id',
|
||||
'application_id'
|
||||
]
|
||||
readonly_fields = ['last_update', 'create', 'detail_id', 'application_id']
|
||||
readonly_fields = ['uuid', 'last_update', 'create', 'detail_id', 'application_id']
|
||||
|
||||
|
||||
admin.site.register(Transaction, TransactionAdmin)
|
||||
|
|
|
|||
17
apps/transactions/migrations/0003_remove_transaction_code.py
Normal file
17
apps/transactions/migrations/0003_remove_transaction_code.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# Generated by Django 3.0.4 on 2020-04-04 06:53
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('transactions', '0002_auto_20200308_1113'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='transaction',
|
||||
name='code',
|
||||
),
|
||||
]
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
import datetime
|
||||
import random
|
||||
import uuid
|
||||
|
||||
from django.db import models
|
||||
|
|
@ -40,7 +39,6 @@ class TransactionManager(models.Manager):
|
|||
if state:
|
||||
transaction.state = state
|
||||
|
||||
transaction.set_code()
|
||||
transaction.save()
|
||||
return transaction
|
||||
|
||||
|
|
@ -54,7 +52,6 @@ class Transaction(models.Model):
|
|||
(5, 'done', 'done'),
|
||||
)
|
||||
uuid = models.UUIDField(primary_key=True, editable=False, default=uuid.uuid4, unique=True, db_index=True) # reserve_code
|
||||
code = models.IntegerField(_('code'), blank=False, unique=True, db_index=True) # unique random number
|
||||
amount = models.IntegerField(_('amount'), blank=False)
|
||||
delay = models.IntegerField(default=0, blank=True) # number of days for delayed payments
|
||||
payer = models.ForeignKey(User, on_delete=models.PROTECT, related_name='payments', blank=True, null=True)
|
||||
|
|
@ -70,18 +67,6 @@ class Transaction(models.Model):
|
|||
class Meta:
|
||||
unique_together = ('application_id', 'detail_id',)
|
||||
|
||||
def set_code(self):
|
||||
# TODO: set infinite algorithm
|
||||
for code in random.sample(range(10000, 100000), 90000):
|
||||
try:
|
||||
code = str(code)
|
||||
self.code = code
|
||||
return self.save()
|
||||
except:
|
||||
pass
|
||||
|
||||
raise APIException('system error')
|
||||
|
||||
def pay(self, payer=None):
|
||||
if not self.payer and not payer:
|
||||
raise APIException('payer identification error')
|
||||
|
|
@ -136,4 +121,4 @@ class Transaction(models.Model):
|
|||
self.save()
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.payer} -> {self.payee} ({self.code}): {self.amount}"
|
||||
return f"{self.payer} -> {self.payee} ({self.uuid}): {self.amount}"
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@ class TransactionSerializer(serializers.ModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = Transaction
|
||||
fields = ('payer',
|
||||
fields = ('uuid',
|
||||
'payer',
|
||||
'payee',
|
||||
"create",
|
||||
"state",
|
||||
"code",
|
||||
'amount',
|
||||
'delay',
|
||||
'last_update',
|
||||
|
|
@ -24,7 +24,7 @@ class TransactionSerializer(serializers.ModelSerializer):
|
|||
'application_id'
|
||||
)
|
||||
|
||||
read_only_fields = ['last_update', 'code', 'state', 'create', 'detail_id', 'application_id']
|
||||
read_only_fields = ['uuid', 'last_update', 'state', 'create', 'detail_id', 'application_id']
|
||||
|
||||
def create(self, validated_data):
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class TransactionList(generics.ListCreateAPIView):
|
|||
class TransactionDetail(generics.RetrieveAPIView):
|
||||
permission_classes = [permissions.IsAuthenticated, IsAuthenticatedOrTokenHasScope]
|
||||
serializer_class = TransactionSerializer
|
||||
lookup_field = 'code'
|
||||
lookup_field = 'uuid'
|
||||
required_scopes = []
|
||||
|
||||
def get_queryset(self):
|
||||
|
|
@ -42,7 +42,7 @@ class TransactionDetail(generics.RetrieveAPIView):
|
|||
class TransactionPay(generics.RetrieveAPIView):
|
||||
permission_classes = [permissions.IsAuthenticated, IsAuthenticatedOrTokenHasScope]
|
||||
serializer_class = TransactionSerializer
|
||||
lookup_field = 'code'
|
||||
lookup_field = 'uuid'
|
||||
required_scopes = []
|
||||
|
||||
def get_queryset(self):
|
||||
|
|
@ -59,7 +59,7 @@ class TransactionPay(generics.RetrieveAPIView):
|
|||
class TransactionReceipt(generics.RetrieveAPIView):
|
||||
permission_classes = [permissions.IsAuthenticated, IsAuthenticatedOrTokenHasScope]
|
||||
serializer_class = TransactionSerializer
|
||||
lookup_field = 'code'
|
||||
lookup_field = 'uuid'
|
||||
required_scopes = []
|
||||
|
||||
def get_queryset(self):
|
||||
|
|
|
|||
|
|
@ -34,16 +34,16 @@ urlpatterns = [
|
|||
|
||||
path('oauth2/', include('oauth2_provider.urls', namespace='oauth2_provider')),
|
||||
|
||||
path('account/', AccountView.as_view(), name='account'),
|
||||
path('users/', UserListView.as_view()),
|
||||
path('users/<uuid>/', UserDetailView.as_view(), name='user_detail'),
|
||||
path('account/', AccountView.as_view(), name='account'),
|
||||
path('request_otp/', RequestOTPView.as_view(), name='register'),
|
||||
path('change_password/', ChangePasswordView.as_view(), name='change_password'),
|
||||
|
||||
path('transactions/', TransactionList.as_view(), name='transactions'),
|
||||
path('transactions/<code>', TransactionDetail.as_view(), name='transaction_detail'),
|
||||
path('transactions/<code>/pay', TransactionPay.as_view(), name='transaction_pay'),
|
||||
path('transactions/<code>/receipt', TransactionReceipt.as_view(), name='transaction_receipt'),
|
||||
path('transactions/<uuid>', TransactionDetail.as_view(), name='transaction_detail'),
|
||||
path('transactions/<uuid>/pay', TransactionPay.as_view(), name='transaction_pay'),
|
||||
path('transactions/<uuid>/receipt', TransactionReceipt.as_view(), name='transaction_receipt'),
|
||||
]
|
||||
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
</head>
|
||||
<body class="font-vazir" style="direction: rtl; text-align: right">
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<a class="navbar-brand" href="#">Toomar</a>
|
||||
<a class="navbar-brand" href="#">{{ site_title }}</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
|
||||
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue