def checkout_post(): for field in [ 'name', 'email', 'street', 'number', 'complement', 'district', 'postal_code', 'city', 'state' ]: if not request.form.get(field, False): return jsonify({'error_msg': 'Todos os campos são obrigatórios.'}) cart = Cart(session['cart']) if len(cart.items) == 0: return jsonify({'error_msg': 'Seu carrinho está vazio.'}) sender = { "name": request.form.get("name"), "email": request.form.get("email"), } shipping = { "street": request.form.get("street"), "number": request.form.get("number"), "complement": request.form.get("complement"), "district": request.form.get("district"), "postal_code": request.form.get("postal_code"), "city": request.form.get("city"), "state": request.form.get("state"), "country": 'BRL', } pagseguro = checkout_pg(sender, shipping, cart) response = pagseguro.checkout() return redirect(response.payment_url)
def remove_from_cart(item_id): cart = Cart(session['cart']) if cart.change_item(item_id, 'remove'): session['cart'] = cart.to_dict() return list_products()
def add_to_cart(item_id): """ Cart with Product """ cart = Cart(session['cart']) if cart.change_item(item_id, 'add'): session['cart'] = cart.to_dict() return list_products()
def before_request(): if 'cart' not in session: session['cart'] = Cart().to_dict()
def add_to_cart(item_id): cart = Cart(session['cart']) if cart.change_item(item_id, 'add'): session['cart'] = cart.to_dict() return list_products()