Esempio n. 1
0
def charge(email):
    if request.method == 'POST':
        from models.order import Order
        card = request.form['stripeToken'] # get the token from buyer form
        order = Order.find_by_email(email)
        success = order.charge_with_stripe(card)
        if success:
            order.email_to_seller()
            order.email_to_buyer()
            order.delete_from_db()
            return render_template('confirmation.html', amount=order.price, email=order.email)
        else:
            return render_template('confirmation.html', text="購買失敗")
    return redirect(url_for('home'))
Esempio n. 2
0
def order():
    if request.method == 'POST':
        from models.order import Order
        name = request.form['name']
        email = request.form['email']
        phone = request.form['phone']
        address = request.form['address']
        letters = request.form['letters']
        key_holder = request.form['key_holder']
        item_type = request.form['order_type']
        order = Order(name, email, phone, address, letters, key_holder, item_type)
        if item_type == 'single':
            order.single_letter_calc_price()
        else:
            order.multi_letter_calc_price()
        try:
            order.save_to_db() # we are tring to store this, even this already exisit
        except:
            old_order = Order.find_by_email(email)
            old_order.delete_from_db()
            order.save_to_db()
        return render_template("checkout.html", order=order, key=os.environ['PUBLISHABLE_KEY'])
    return render_template("order.html")