diff --git a/apiserver/apiserver/api/views.py b/apiserver/apiserver/api/views.py index feed24c..785eafb 100644 --- a/apiserver/apiserver/api/views.py +++ b/apiserver/apiserver/api/views.py @@ -1082,8 +1082,6 @@ class ProtocoinViewSet(Base): source_user_balance = source_user.transactions.aggregate(Sum('protocoin'))['protocoin__sum'] source_user_balance = float(source_user_balance) - print(source_user_balance) - if source_user_balance != balance: raise exceptions.ValidationError(dict(balance='Incorrect current balance.')) @@ -1125,6 +1123,24 @@ class ProtocoinViewSet(Base): 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): diff --git a/apiserver/apiserver/secrets.py.example b/apiserver/apiserver/secrets.py.example index 6ebd629..40ad4be 100644 --- a/apiserver/apiserver/secrets.py.example +++ b/apiserver/apiserver/secrets.py.example @@ -56,6 +56,12 @@ AUTH_API_KEY = '' # head /dev/urandom | base32 | head -c 40 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 DOOR_CODE = '' WIFI_PASS = '' diff --git a/webclient/src/Paymaster.js b/webclient/src/Paymaster.js index 022bc97..79e8438 100644 --- a/webclient/src/Paymaster.js +++ b/webclient/src/Paymaster.js @@ -92,7 +92,7 @@ export function Paymaster(props) {
Protocoin

Protocoin is used to buy things from Protospace's vending machines.

-

Current balance: ₱ {user.member.protocoin}

+

Current balance: ₱ {user.member.protocoin.toFixed(2)}