application_client_id
This commit is contained in:
parent
84149c03f4
commit
3d90035338
7 changed files with 73 additions and 28 deletions
|
|
@ -13,9 +13,9 @@ class TransactionAdmin(admin.ModelAdmin):
|
|||
'state',
|
||||
'delay',
|
||||
'detail_id',
|
||||
'application_id'
|
||||
'application_client_id'
|
||||
]
|
||||
readonly_fields = ['uuid', 'last_update', 'create', 'detail_id', 'application_id']
|
||||
readonly_fields = ['uuid', 'last_update', 'create', 'detail_id', 'application_client_id']
|
||||
|
||||
|
||||
admin.site.register(Transaction, TransactionAdmin)
|
||||
|
|
|
|||
22
apps/transactions/migrations/0004_auto_20200404_0942.py
Normal file
22
apps/transactions/migrations/0004_auto_20200404_0942.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# Generated by Django 3.0.4 on 2020-04-04 09:42
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('transactions', '0003_remove_transaction_code'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='transaction',
|
||||
old_name='application_id',
|
||||
new_name='application_client_id',
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='transaction',
|
||||
unique_together=set(),
|
||||
),
|
||||
]
|
||||
18
apps/transactions/migrations/0005_auto_20200404_0942.py
Normal file
18
apps/transactions/migrations/0005_auto_20200404_0942.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.0.4 on 2020-04-04 09:42
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('transactions', '0004_auto_20200404_0942'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='transaction',
|
||||
name='application_client_id',
|
||||
field=models.CharField(db_index=True, max_length=100, null=True),
|
||||
),
|
||||
]
|
||||
|
|
@ -18,7 +18,7 @@ class TransactionManager(models.Manager):
|
|||
payer: User = None,
|
||||
delay=0,
|
||||
detail_id=None,
|
||||
application_id=None,
|
||||
application_client_id=None,
|
||||
state=None):
|
||||
if not (isinstance(payer, User) or payer is None):
|
||||
raise ValidationError('payer type not valid')
|
||||
|
|
@ -34,7 +34,7 @@ class TransactionManager(models.Manager):
|
|||
amount=amount,
|
||||
delay=delay,
|
||||
detail_id=detail_id,
|
||||
application_id=application_id
|
||||
application_client_id=application_client_id
|
||||
)
|
||||
if state:
|
||||
transaction.state = state
|
||||
|
|
@ -59,13 +59,13 @@ class Transaction(models.Model):
|
|||
state = models.IntegerField(choices=STATE_CHOICES, default=STATE_CHOICES.created)
|
||||
create = models.DateTimeField(_('create'), blank=True, null=True, auto_now=True)
|
||||
last_update = models.DateTimeField(_('last update'), blank=True, null=True, auto_now=True)
|
||||
application_id = models.IntegerField("application ID", blank=True, null=True)
|
||||
application_client_id = models.CharField(max_length=100, db_index=True, null=True)
|
||||
detail_id = models.IntegerField(null=True, blank=True) # or better detail url or res number
|
||||
|
||||
objects = TransactionManager()
|
||||
|
||||
class Meta:
|
||||
unique_together = ('application_id', 'detail_id',)
|
||||
# class Meta:
|
||||
# unique_together = ('application_client_id', 'detail_id',)
|
||||
|
||||
def pay(self, payer=None):
|
||||
if not self.payer and not payer:
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from .models import Transaction
|
|||
class TransactionSerializer(serializers.ModelSerializer):
|
||||
payer = PublicUserSerializer(required=False)
|
||||
payee = PublicUserSerializer(required=False, read_only=True)
|
||||
# application_id = serializers.IntegerField(required=False, read_only=True)
|
||||
# application_client_id = serializers.IntegerField(required=False, read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Transaction
|
||||
|
|
@ -21,10 +21,10 @@ class TransactionSerializer(serializers.ModelSerializer):
|
|||
'delay',
|
||||
'last_update',
|
||||
'detail_id',
|
||||
'application_id'
|
||||
# 'application_client_id'
|
||||
)
|
||||
|
||||
read_only_fields = ['uuid', 'last_update', 'state', 'create', 'detail_id', 'application_id']
|
||||
read_only_fields = ['uuid', 'last_update', 'state', 'create', 'detail_id'] #, 'application_client_id']
|
||||
|
||||
def create(self, validated_data):
|
||||
|
||||
|
|
|
|||
|
|
@ -15,17 +15,22 @@ class TransactionList(generics.ListCreateAPIView):
|
|||
|
||||
def get_queryset(self):
|
||||
user = self.request.user
|
||||
return Transaction.objects.filter(Q(payee_id=user.id) | Q(payer_id=user.id)).all()
|
||||
return Transaction.objects.filter(Q(payee=user) | Q(payer=user)).all()
|
||||
|
||||
def perform_create(self, serializer):
|
||||
def get_application_client_id(self):
|
||||
try:
|
||||
application = self.request.auth.application
|
||||
application_id = application.id
|
||||
if application:
|
||||
application_client_id = application.client_id
|
||||
else:
|
||||
application_client_id = self.request.auth.detail.get('client_id')
|
||||
except:
|
||||
application_id = None
|
||||
application_client_id = None
|
||||
return application_client_id
|
||||
|
||||
def perform_create(self, serializer):
|
||||
user = self.request.user
|
||||
serializer.save(payee=user, application_id=application_id )
|
||||
serializer.save(payee=user, application_client_id=self.get_application_client_id())
|
||||
|
||||
|
||||
class TransactionDetail(generics.RetrieveAPIView):
|
||||
|
|
@ -36,7 +41,7 @@ class TransactionDetail(generics.RetrieveAPIView):
|
|||
|
||||
def get_queryset(self):
|
||||
user = self.request.user
|
||||
return Transaction.objects.filter(Q(payee_id=user.id) | Q(payer_id=user.id) | Q(payer__isnull=True)).all()
|
||||
return Transaction.objects.filter(Q(payee=user) | Q(payer=user) | Q(payer__isnull=True)).all()
|
||||
|
||||
|
||||
class TransactionPay(generics.RetrieveAPIView):
|
||||
|
|
@ -47,7 +52,7 @@ class TransactionPay(generics.RetrieveAPIView):
|
|||
|
||||
def get_queryset(self):
|
||||
user = self.request.user
|
||||
return Transaction.objects.filter(Q(payer_id=user.id) | Q(payer__isnull=True)).all()
|
||||
return Transaction.objects.filter(Q(payer=user) | Q(payer__isnull=True)).all()
|
||||
|
||||
def retrieve(self, request, *args, **kwargs):
|
||||
instance = self.get_object()
|
||||
|
|
@ -64,7 +69,7 @@ class TransactionReceipt(generics.RetrieveAPIView):
|
|||
|
||||
def get_queryset(self):
|
||||
user = self.request.user
|
||||
return Transaction.objects.filter(payer_id=user.id).all()
|
||||
return Transaction.objects.filter(payer=user).all()
|
||||
|
||||
def retrieve(self, request, *args, **kwargs):
|
||||
instance = self.get_object()
|
||||
|
|
|
|||
20
client.py
20
client.py
|
|
@ -111,8 +111,8 @@ class ApiClient():
|
|||
result = self._request(path=path, data=data, method='put')
|
||||
return result
|
||||
|
||||
def get_user_profile(self, code):
|
||||
path = f'users/{code}/'
|
||||
def get_user_profile(self, uuid):
|
||||
path = f'users/{uuid}/'
|
||||
result = self._request(path=path)
|
||||
return result
|
||||
|
||||
|
|
@ -124,8 +124,8 @@ class ApiClient():
|
|||
|
||||
return self._request(path=path)
|
||||
|
||||
def get_transaction(self, code):
|
||||
path = f'transactions/{code}'
|
||||
def get_transaction(self, uuid):
|
||||
path = f'transactions/{uuid}'
|
||||
return self._request(path=path)
|
||||
|
||||
def create_transaction(self, amount, delay, payer=None):
|
||||
|
|
@ -134,16 +134,16 @@ class ApiClient():
|
|||
'amount': amount
|
||||
}
|
||||
if payer:
|
||||
data.setdefault('payer', {'code': payer})
|
||||
data.setdefault('payer', {'uuid': payer})
|
||||
response = self._request('transactions/', method='post', data=data)
|
||||
return response and 'code' in response, response
|
||||
return response and 'uuid' in response, response
|
||||
|
||||
def pay_transaction(self, code):
|
||||
path = f'transactions/{code}/pay'
|
||||
def pay_transaction(self, uuid):
|
||||
path = f'transactions/{uuid}/pay'
|
||||
return self._request(path=path)
|
||||
|
||||
def receipt_transaction(self, code):
|
||||
path = f'transactions/{code}/receipt'
|
||||
def receipt_transaction(self, uuid):
|
||||
path = f'transactions/{uuid}/receipt'
|
||||
return self._request(path=path)
|
||||
|
||||
def get_introspection(self):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue