Add API route for vending card balance
This commit is contained in:
parent
50a210a9b2
commit
0257a8cd63
|
@ -1082,8 +1082,6 @@ class ProtocoinViewSet(Base):
|
||||||
source_user_balance = source_user.transactions.aggregate(Sum('protocoin'))['protocoin__sum']
|
source_user_balance = source_user.transactions.aggregate(Sum('protocoin'))['protocoin__sum']
|
||||||
source_user_balance = float(source_user_balance)
|
source_user_balance = float(source_user_balance)
|
||||||
|
|
||||||
print(source_user_balance)
|
|
||||||
|
|
||||||
if source_user_balance != balance:
|
if source_user_balance != balance:
|
||||||
raise exceptions.ValidationError(dict(balance='Incorrect current balance.'))
|
raise exceptions.ValidationError(dict(balance='Incorrect current balance.'))
|
||||||
|
|
||||||
|
@ -1125,6 +1123,24 @@ class ProtocoinViewSet(Base):
|
||||||
|
|
||||||
return Response(200)
|
return Response(200)
|
||||||
|
|
||||||
|
@action(detail=True, methods=['get'])
|
||||||
|
def card_vend_balance(self, request, pk=None):
|
||||||
|
auth_token = request.META.get('HTTP_AUTHORIZATION', '')
|
||||||
|
if secrets.VEND_API_TOKEN and auth_token != 'Bearer ' + secrets.VEND_API_TOKEN:
|
||||||
|
raise exceptions.PermissionDenied()
|
||||||
|
|
||||||
|
card = get_object_or_404(models.Card, card_number=pk)
|
||||||
|
user = card.user
|
||||||
|
|
||||||
|
user_balance = user.transactions.aggregate(Sum('protocoin'))['protocoin__sum']
|
||||||
|
user_balance = float(user_balance)
|
||||||
|
|
||||||
|
res = dict(
|
||||||
|
balance=user_balance,
|
||||||
|
first_name=user.member.first_name,
|
||||||
|
)
|
||||||
|
return Response(res)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RegistrationView(RegisterView):
|
class RegistrationView(RegisterView):
|
||||||
|
|
|
@ -56,6 +56,12 @@ AUTH_API_KEY = ''
|
||||||
# head /dev/urandom | base32 | head -c 40
|
# head /dev/urandom | base32 | head -c 40
|
||||||
DOOR_API_TOKEN = ''
|
DOOR_API_TOKEN = ''
|
||||||
|
|
||||||
|
# Vending machine cards API token
|
||||||
|
# Set this to random characters
|
||||||
|
# For example, use the output of this:
|
||||||
|
# head /dev/urandom | base32 | head -c 40
|
||||||
|
VEND_API_TOKEN = ''
|
||||||
|
|
||||||
# Protospace general info
|
# Protospace general info
|
||||||
DOOR_CODE = ''
|
DOOR_CODE = ''
|
||||||
WIFI_PASS = ''
|
WIFI_PASS = ''
|
||||||
|
|
|
@ -92,7 +92,7 @@ export function Paymaster(props) {
|
||||||
<Header size='medium'>Protocoin</Header>
|
<Header size='medium'>Protocoin</Header>
|
||||||
<p>Protocoin is used to buy things from Protospace's vending machines.</p>
|
<p>Protocoin is used to buy things from Protospace's vending machines.</p>
|
||||||
|
|
||||||
<p>Current balance: ₱ {user.member.protocoin}</p>
|
<p>Current balance: ₱ {user.member.protocoin.toFixed(2)}</p>
|
||||||
|
|
||||||
<Grid stackable padded columns={2}>
|
<Grid stackable padded columns={2}>
|
||||||
<Grid.Column width={5}>
|
<Grid.Column width={5}>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user