def deletePayment(): print("In Delete") if not request.is_json: print("Missing JSON") return jsonify({"msg": "Missing JSON in request"}), 400 params = request.get_json() print(params) _mask = params.get('mask', None) _name = params.get('type', None) print("_mask:" + str(_mask)) print("_type:" + str(_name)) uid = get_jwt_identity() user = get_model().readUser(uid) for i in range(5): payQuery = "_payment" + str(i + 1) paymentId = user[str(payQuery)] print("Delete: " + str(paymentId)) if paymentId != None: payment = get_model().readPayment(paymentId) if payment["_name"] == _name: print("Type Match") if payment["_mask"] == _mask or payment["_mask"] == None: print("Mask Match") deletedPay = get_model().deletePayment(paymentId) user[str(payQuery)] = None if user["_preffered"] == paymentId: user["_preffered"] = None updatedUser = get_model().updateUser(user, uid) return jsonify({"status": 1}), 200 return jsonify({"status": -1}), 200
def edit(id): book = get_model().read(id) if request.method == 'POST': data = request.form.to_dict(flat=True) book = get_model().update(data, id) return redirect(url_for('.view', id=book['id'])) return render_template("form.html", action="Edit", book=book)
def list(): token = request.args.get('page_token', None) if token: token = token.encode('utf-8') books, next_page_token = get_model().list(cursor=token) return render_template('error.html')
def add(): if request.method == 'POST': data = request.form.to_dict(flat=True) print("Data: " + str(data)) book = get_model().create(data) return redirect(url_for('.view', id=book['id'])) return render_template("form.html", action="Add", book={})
def deposit(): #Charge client from database stripe token if not request.is_json: print("Missing JSON") return jsonify({"msg": "Missing JSON in request"}), 400 params = request.get_json() amount = params.get('amount', None) print('amount') uid = get_jwt_identity() user = get_model().readUser(uid) payment = get_model().readPayment(user["_preffered"]) print("deposit") #Charge Client print(Decimal(amount)) charge = stripe.Charge.create(amount=int(float(amount) * 100), currency='usd', description='PayUp Deposit', customer=payment["_stripeToken"]) print("After Charge") return jsonify({"charge": str(charge)}), 200
def newToken(): print("New Token") if not request.is_json: print("Missing JSON") return jsonify({"msg": "Missing JSON in request"}), 400 params = request.get_json() print(params) PLAID_LINK_PUBLIC_TOKEN = params.get('public_token', None) ACCOUNT_ID = params.get('id', None) bankName = params.get('type', None) mask = params.get('mask', None) print(PLAID_LINK_PUBLIC_TOKEN) print(ACCOUNT_ID) print(bankName) print(mask) exchange_token_response = client.Item.public_token.exchange( PLAID_LINK_PUBLIC_TOKEN) access_token = exchange_token_response['access_token'] stripe_response = client.Processor.stripeBankAccountTokenCreate( access_token, ACCOUNT_ID) bank_account_token = stripe_response['stripe_bank_account_token'] uid = get_jwt_identity() customer = stripe.Customer.create(source=bank_account_token, description=uid) print("Costumer: " + str(customer)) #TODO: Add new method to database data = { '_type': "Bank", '_name': bankName, '_stripeToken': customer.id, '_dateAdded': datetime.datetime.now(), '_plaidToken': PLAID_LINK_PUBLIC_TOKEN, '_mask': mask, '_uid': uid } print("newToken: " + str(data)) newPayment = get_model().createPayment(data) addPaymentToUser(uid, newPayment['id']) return jsonify({"success": "success"}), 200
def addPaymentToUser(uid, paymentId): user = get_model().readUser(uid) print("User " + str(user)) if user == None: data = { "_uid": uid, "_payment1": paymentId, "_payment2": None, "_payment3": None, "_payment4": None, "_payment5": None, "_preffered": paymentId } get_model().createUser(data) elif user['_payment1'] == None: user['_payment1'] = paymentId user['_preffered'] = paymentId data = get_model().updateUser(user, uid) elif user['_payment2'] == None: user['_payment2'] = paymentId user['_preffered'] = paymentId print('Payment 2:' + str(user)) data = get_model().updateUser(user, uid) elif user['_payment3'] == None: print('Payment 3:' + str(user)) user['_payment3'] = paymentId user['_preffered'] = paymentId data = get_model().updateUser(user, uid) elif user['_payment4'] == None: user['_payment4'] = paymentId user['_preffered'] = paymentId print('Payment 4:' + str(user)) data = get_model().updateUser(user, uid) else: user['_payment5'] = paymentId user['_preffered'] = paymentId print('Payment 5:' + str(user)) data = get_model().updateUser(user, uid)
def delete(id): get_model().delete(id) return redirect(url_for('.list'))
def view(id): book = get_model().read(id) return render_template("view.html", book=book)