Example #1
0
def transaction_():
    if request.method == "POST":
        fromWallet = request.json['from']
        toWallet = request.json['to']
        amount = request.json['amount']
        fromBalance = int(wallet.find_by_id(fromWallet)['balance'])
        toBalance = int(wallet.find_by_id(toWallet)['balance'])
        amountVal = int(amount)

        # get award

        if (fromBalance >= amountVal):
            fromBalance -= amountVal
            toBalance += amountVal
            wallet.update(fromWallet, {'balance': fromBalance})
            wallet.update(toWallet, {'balance': toBalance})
            transaction.create({
                'fromWallet': fromWallet,
                'toWallet': toWallet,
                'amount': amount,
                'status': "done"
            })
            response = "transaction is completed"
        else:
            response = "not enough money"
            transaction.create({
                'fromWallet': fromWallet,
                'toWallet': toWallet,
                'amount': amount,
                'status': "failed"
            })

        return response
Example #2
0
def withdraw(wallet_id):
    if request.method == "PUT":
        # customerID = request.json['customerID']
        # VIP = request.json['VIP']
        amount = request.json['amount']
        if (int(wallet.find_by_id(wallet_id)['balance']) > int(amount)):
            balance = int(
                wallet.find_by_id(wallet_id)['balance']) - int(amount)
            response = wallet.update(wallet_id, {'balance': balance})
            return response, 201
        else:
            response = "not available"
            return response, 201
Example #3
0
def charge_wallet(wallet_id):
    if request.method == "PUT":
        # customerID = request.json['customerID']
        # VIP = request.json['VIP']
        charge = request.json['charge']
        balance = int(wallet.find_by_id(wallet_id)['balance']) + int(charge)
        # add transfer to table
        response = wallet.update(wallet_id, {'balance': balance})
        return response, 201
Example #4
0
def query2():
    if ('role' in session):
        if (session['role'] == "admin"):
            walletId = request.json['walId']
            return str((datetime.now() - wallet.find_by_id(walletId)['created']
                        ).total_seconds() / 3600) + "  hours"
        else:
            return ("warning!! your role is :" + session['role'])

    else:
        return ("not permitted")
Example #5
0
def query5():
    if ('role' in session):
        if (session['role'] == "guest"):
            walId = request.json['wid']
            return "your balance:   " + str(
                wallet.find_by_id(walId)['balance'])
Example #6
0
def get_wallet(wallet_id):
    return wallet.find_by_id(wallet_id), 200