示例#1
0
def checkout_cart(cart_id):
    body = request.get_json()

    required_params = ["payment_method"]
    try:
        check_parameters(params=body,
                         required=required_params,
                         possible=required_params)
    except exceptions.ParamsError as e:
        return {"message": e.message}, 400

    try:
        cart = cart_service.checkout_cart(
            body, cart_id, request.headers.environ.get('HTTP_AUTHORIZATION'))
    except exceptions.PaymentError:
        return {"message": "Payment error"}, 500
    except exceptions.CartNotFoundException:
        return "", 404
    except (exceptions.StorageServerError, exceptions.UserAuthServerError):
        return "", 500
    except exceptions.InvalidPaymentMethod:
        return {
            "message": "Invalid payment method " + body['payment_method']
        }, 400
    return cart_mapper.get_cart(cart), 200
示例#2
0
def add_item(cart_id, item_id):
    try:
        cart = cart_service.add_item_to_cart(cart_id, item_id)
    except exceptions.CartNotFoundException:
        return {"message": "Cart " + str(cart_id) + " not found"}, 404
    except exceptions.ItemNotFoundException:
        return {"message": "Item " + str(item_id) + " not found"}, 404
    return cart_mapper.get_cart(cart), 200
示例#3
0
def add_item(cart_id, item_id):
    try:
        cart = cart_service.add_item_to_cart(cart_id, item_id)
    except exceptions.CartOrItemNotFoundException as e:
        return {"message": e.message}, 404
    except exceptions.StorageServerError:
        return "", 500
    return cart_mapper.get_cart(cart), 200
示例#4
0
def get_cart(cart_id):
    try:
        cart = cart_service.get_cart(cart_id)
    except exceptions.CartNotFoundException:
        return "", 404
    except exceptions.StorageServerError:
        return "", 500
    return cart_mapper.get_cart(cart)
示例#5
0
def update_cart(cart_id):
    body = request.get_json()

    possible_params = ["status", "payment_method", "total_amount", "username"]
    try:
        check_parameters(params=body,
                         required=possible_params,
                         possible=possible_params)
    except exceptions.ParamsError as e:
        return {"message": e.message}, 400
    try:
        cart = cart_service.update_cart(cart_id, **body)
    except exceptions.CartNotFoundException:
        return "", 404
    return cart_mapper.get_cart(cart), 200
示例#6
0
def get_cart(cart_id):
    try:
        cart = cart_service.get_cart(cart_id)
    except exceptions.CartNotFoundException:
        return "", 404
    return cart_mapper.get_cart(cart), 200