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):
|
class TransactionAdmin(admin.ModelAdmin):
|
||||||
fields = [
|
fields = [
|
||||||
'code',
|
'uuid',
|
||||||
'amount',
|
'amount',
|
||||||
'payer',
|
'payer',
|
||||||
'payee',
|
'payee',
|
||||||
|
|
@ -15,7 +15,7 @@ class TransactionAdmin(admin.ModelAdmin):
|
||||||
'detail_id',
|
'detail_id',
|
||||||
'application_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)
|
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 datetime
|
||||||
import random
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
@ -40,7 +39,6 @@ class TransactionManager(models.Manager):
|
||||||
if state:
|
if state:
|
||||||
transaction.state = state
|
transaction.state = state
|
||||||
|
|
||||||
transaction.set_code()
|
|
||||||
transaction.save()
|
transaction.save()
|
||||||
return transaction
|
return transaction
|
||||||
|
|
||||||
|
|
@ -54,7 +52,6 @@ class Transaction(models.Model):
|
||||||
(5, 'done', 'done'),
|
(5, 'done', 'done'),
|
||||||
)
|
)
|
||||||
uuid = models.UUIDField(primary_key=True, editable=False, default=uuid.uuid4, unique=True, db_index=True) # reserve_code
|
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)
|
amount = models.IntegerField(_('amount'), blank=False)
|
||||||
delay = models.IntegerField(default=0, blank=True) # number of days for delayed payments
|
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)
|
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:
|
class Meta:
|
||||||
unique_together = ('application_id', 'detail_id',)
|
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):
|
def pay(self, payer=None):
|
||||||
if not self.payer and not payer:
|
if not self.payer and not payer:
|
||||||
raise APIException('payer identification error')
|
raise APIException('payer identification error')
|
||||||
|
|
@ -136,4 +121,4 @@ class Transaction(models.Model):
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
def __str__(self):
|
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:
|
class Meta:
|
||||||
model = Transaction
|
model = Transaction
|
||||||
fields = ('payer',
|
fields = ('uuid',
|
||||||
|
'payer',
|
||||||
'payee',
|
'payee',
|
||||||
"create",
|
"create",
|
||||||
"state",
|
"state",
|
||||||
"code",
|
|
||||||
'amount',
|
'amount',
|
||||||
'delay',
|
'delay',
|
||||||
'last_update',
|
'last_update',
|
||||||
|
|
@ -24,7 +24,7 @@ class TransactionSerializer(serializers.ModelSerializer):
|
||||||
'application_id'
|
'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):
|
def create(self, validated_data):
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class TransactionList(generics.ListCreateAPIView):
|
||||||
class TransactionDetail(generics.RetrieveAPIView):
|
class TransactionDetail(generics.RetrieveAPIView):
|
||||||
permission_classes = [permissions.IsAuthenticated, IsAuthenticatedOrTokenHasScope]
|
permission_classes = [permissions.IsAuthenticated, IsAuthenticatedOrTokenHasScope]
|
||||||
serializer_class = TransactionSerializer
|
serializer_class = TransactionSerializer
|
||||||
lookup_field = 'code'
|
lookup_field = 'uuid'
|
||||||
required_scopes = []
|
required_scopes = []
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
|
|
@ -42,7 +42,7 @@ class TransactionDetail(generics.RetrieveAPIView):
|
||||||
class TransactionPay(generics.RetrieveAPIView):
|
class TransactionPay(generics.RetrieveAPIView):
|
||||||
permission_classes = [permissions.IsAuthenticated, IsAuthenticatedOrTokenHasScope]
|
permission_classes = [permissions.IsAuthenticated, IsAuthenticatedOrTokenHasScope]
|
||||||
serializer_class = TransactionSerializer
|
serializer_class = TransactionSerializer
|
||||||
lookup_field = 'code'
|
lookup_field = 'uuid'
|
||||||
required_scopes = []
|
required_scopes = []
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
|
|
@ -59,7 +59,7 @@ class TransactionPay(generics.RetrieveAPIView):
|
||||||
class TransactionReceipt(generics.RetrieveAPIView):
|
class TransactionReceipt(generics.RetrieveAPIView):
|
||||||
permission_classes = [permissions.IsAuthenticated, IsAuthenticatedOrTokenHasScope]
|
permission_classes = [permissions.IsAuthenticated, IsAuthenticatedOrTokenHasScope]
|
||||||
serializer_class = TransactionSerializer
|
serializer_class = TransactionSerializer
|
||||||
lookup_field = 'code'
|
lookup_field = 'uuid'
|
||||||
required_scopes = []
|
required_scopes = []
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
|
|
|
||||||
|
|
@ -34,16 +34,16 @@ urlpatterns = [
|
||||||
|
|
||||||
path('oauth2/', include('oauth2_provider.urls', namespace='oauth2_provider')),
|
path('oauth2/', include('oauth2_provider.urls', namespace='oauth2_provider')),
|
||||||
|
|
||||||
|
path('account/', AccountView.as_view(), name='account'),
|
||||||
path('users/', UserListView.as_view()),
|
path('users/', UserListView.as_view()),
|
||||||
path('users/<uuid>/', UserDetailView.as_view(), name='user_detail'),
|
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('request_otp/', RequestOTPView.as_view(), name='register'),
|
||||||
path('change_password/', ChangePasswordView.as_view(), name='change_password'),
|
path('change_password/', ChangePasswordView.as_view(), name='change_password'),
|
||||||
|
|
||||||
path('transactions/', TransactionList.as_view(), name='transactions'),
|
path('transactions/', TransactionList.as_view(), name='transactions'),
|
||||||
path('transactions/<code>', TransactionDetail.as_view(), name='transaction_detail'),
|
path('transactions/<uuid>', TransactionDetail.as_view(), name='transaction_detail'),
|
||||||
path('transactions/<code>/pay', TransactionPay.as_view(), name='transaction_pay'),
|
path('transactions/<uuid>/pay', TransactionPay.as_view(), name='transaction_pay'),
|
||||||
path('transactions/<code>/receipt', TransactionReceipt.as_view(), name='transaction_receipt'),
|
path('transactions/<uuid>/receipt', TransactionReceipt.as_view(), name='transaction_receipt'),
|
||||||
]
|
]
|
||||||
|
|
||||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
</head>
|
</head>
|
||||||
<body class="font-vazir" style="direction: rtl; text-align: right">
|
<body class="font-vazir" style="direction: rtl; text-align: right">
|
||||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
<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"
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
|
||||||
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||||
<span class="navbar-toggler-icon"></span>
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue