コード例 #1
0
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)
コード例 #2
0
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()
コード例 #3
0
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()
コード例 #4
0
def before_request():
    if 'cart' not in session:
        session['cart'] = Cart().to_dict()
コード例 #5
0
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()
コード例 #6
0
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()