Exemplo n.º 1
0
    def onDeposit(self, event):
        destination = event.get('destination', False)
        if not destination: return malformedRequest()

        amount = event.get('amount', False)
        if not amount: return malformedRequest()

        return successRequest(json.dumps(
            {"destination": deposit(destination, amount).toDict()}),
                              status=201)
Exemplo n.º 2
0
    def post(self, request):
        asDict = requestToJson(request)

        event = asDict.get("type", False)
        if not event: return malformedRequest()

        if event == "deposit": return self.onDeposit(asDict)
        if event == "withdraw": return self.onWithdraw(asDict)
        if event == "transfer": return self.onTransfer(asDict)

        return malformedRequest()
Exemplo n.º 3
0
    def onWithdraw(self, event):
        origin = event.get('origin', False)
        if not origin: return malformedRequest()

        amount = event.get('amount', False)
        if not amount: return malformedRequest()

        success = withdraw(origin, amount)
        if not success: return notFound("0")

        return successRequest(json.dumps({"origin": success.toDict()}),
                              status=201)
Exemplo n.º 4
0
    def onTransfer(self, event):
        originId = event.get('origin', False)
        if not originId: return malformedRequest()

        destinationId = event.get('destination', False)
        if not destinationId: return malformedRequest()

        amount = event.get('amount', False)
        if not amount: return malformedRequest()

        originAccount = withdraw(originId, amount)
        if not originAccount: return notFound('0')

        destinationAccount = deposit(destinationId, amount)

        return successRequest(json.dumps({
            "origin":
            originAccount.toDict(),
            "destination":
            destinationAccount.toDict(),
        }),
                              status=201)
Exemplo n.º 5
0
    def get(self, request):
        accountId = request.GET.get("account_id", False)
        if not accountId: return malformedRequest()

        return self.getBalance(accountId)