Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
@app.route("/basket/payment", methods=["GET", "POST"])
def pay():
"""
Fake paymeent.
YOU DO NOT NEED TO IMPLEMENT PAYMENT
"""
if not flask.session["user"]:
flask.flash("You need to be logged in")
return flask.redirect(flask.url_for("index"))
#Get the total cost
cost = 0
#Fetch USer ID from Sssion
theQry = "Select * FROM User WHERE id = {0}".format(flask.session["user"])
theUser = query_db(theQry, one=True)
#Add products to the user
sessionBasket = flask.session.get("basket", None)
theDate = datetime.datetime.utcnow()
for key in sessionBasket:
#As we should have a trustworthy key in the basket.
theQry = "INSERT INTO PURCHASE (userID, productID, date) VALUES ({0},{1},'{2}')".format(theUser['id'],
key,
theDate)
theQry2 = f"SELECT * FROM product WHERE id = {key}"
theItem = query_db(theQry2, one=True)
quantity = int(sessionBasket[key])
thePrice = theItem["price"] * quantity
cost += thePrice
app.logger.debug(theQry)
write_db(theQry)
#Clear the Session
flask.session.pop("basket", None)
return flask.render_template("pay.html",
total=cost)