def confirm(): """Check a transaction confirmation status""" gopay = Gopay.load(TOKEN) transaction_id = int(request.form["id"]) limit = int(request.form["limit"]) try: transaction = Transaction.get(Transaction.id == transaction_id, Transaction.created_at == date.today()) except: return jsonify({"status": "error", "detail": "transaction not found"}) if transaction.status is True: # Already confirmed return jsonify({"status": "success", "confirmed": True}) history = gopay.history(limit) found = False i = 0 while not found and i < len(history): trx = history[i] if (trx["amount"] == (transaction.amount)) and (trx["type"] == "credit"): found = True i += 1 if not found: return jsonify({"status": "fail", "confirmed": False}) transaction.status = True transaction.save() return jsonify({"status": "success", "confirmed": True})
def confirm(): '''Check a transaction confirmation status''' gopay = Gopay.load(TOKEN) transaction_id = int(request.form['id']) limit = int(request.form['limit']) try: transaction = Transaction.get(Transaction.id == transaction_id , \ Transaction.created_at == date.today()) except: return jsonify({'status': 'error', 'detail': 'transaction not found'}) if transaction.status is True: #Already confirmed return jsonify({'status': 'success', 'confirmed': True}) history = gopay.history(limit) found = False i = 0 while not found and i < len(history): trx = history[i] if (trx['amount'] == (transaction.amount)) and (trx['type'] == 'credit'): found = True i += 1 if not found: return jsonify({'status': 'fail', 'confirmed': False}) transaction.status = True transaction.save() return jsonify({'status': 'success', 'confirmed': True})
def isValidTransaction(key, hash, user): # Check that the parameters exist if not key or not hash: return False # Check that the transaction exists tr = Transaction.get(key) if not tr: return False # Check that the current user is involved in the transaction if user != tr.fromUser and user != tr.toUser: return False # Check that the hash if valid if not tr.isValidHash(hash): return return tr