Example #1
0
    def add_item(self,
                 menu_item,
                 quantity,
                 price_level=None,
                 comment=None,
                 modifiers=None,
                 discounts=None):
        data = {'menu_item': menu_item.id, 'quantity': quantity}

        if price_level:
            price_level_ids = [pl.id for pl in menu_item.price_levels]
            if price_level not in price_level_ids:
                raise error.APIError('Unknown price level for item {}'.format(
                    menu_item.id))

            data['price_level'] = price_level

        if comment:
            if not isinstance(comment, str):
                raise error.APIError('Comment must be an ascii string')
            if len(comment) > 20:
                raise error.APIError('Max comment length is 20 characters')

            data['comment'] = comment

        if modifiers:
            data['modifiers'] = modifiers

        if discounts:
            data['discounts'] = discounts

        res = client.post(TicketItem.list_url(self.location_id, self.id), data)

        self.refresh_from(**res)
Example #2
0
def handle_error_code(json, status_code, headers):
    if status_code == 400:
        err = json.get('error', 'Bad request')
        raise error.InvalidRequestError(err, status_code, headers)
    elif status_code == 401:
        err = json.get('error', 'Not authorized')
        raise error.AuthenticationError(err, status_code, headers)
    elif status_code == 404:
        err = json.get('error', 'Not found')
        raise error.InvalidRequestError(err, status_code, headers)
    elif status_code == 500:
        err = json.get('error', 'Internal server error')
        raise error.APIError(err, status_code, headers)
    else:
        err = json.get('error', 'Unknown status code ({})'.format(status_code))
        raise error.APIError(err, status_code, headers)
Example #3
0
    def pay(self, type, amount, tip, **kwargs):
        if type not in Payment.types:
            msg = 'Unknown payment type: \'{}\'. Allowed types: {}'.format(
                type, Payment.types)
            raise error.APIError(msg)

        if type == '3rd_party':
            if 'tender_type' not in kwargs or 'payment_source' not in kwargs:
                msg = 'Missing tender_type or payment_source for payment'
                raise error.APIError(msg)
        else:
            if 'card_info' not in kwargs:
                # TODO: verify required card_info fields
                raise error.APIError('Missing card_info for payment')

        data = dict(type=type, amount=amount, tip=tip, **kwargs)

        res = client.post(Payment.list_url(self.location_id, self.id), data)

        self.refresh_from(**res.pop('ticket'))
        return res
Example #4
0
def handle_parse_error(e, url, status_code=None, headers=None):
    err = '{}: {}'.format(type(e).__name__, str(e))
    msg = 'Error parsing Omnivore JSON response. url \n\n{} {}'.format(err, url)
    raise error.APIError(msg, status_code, headers)