def __init__(self, seller, config):
        self.amount = None
        self.active = True
        self.currency = 'USD'
        self.seller = seller
        self.recurrence = None
        self.img = ('https://raw.githubusercontent.com/mozilla'
                    '/payments-config/master/payments_config'
                    '/assets/default.png')

        for k in self.required:
            if k not in config:
                raise ValueError('Missing {} on product'.format(k))

        for k, v in config.items():
            setattr(self, k, v)

        self.id = seller.id + '-' + config['id']

        if self.recurrence and self.recurrence not in ['monthly']:
            raise ValueError('Recurrence should be not set or monthly: {}'.
                             format(self.recurrence))

        if (self.user_identification not in self.valid_user_identifications):
            raise ValueError('user_identification must be one of: {}'.
                             format(self.valid_user_identifications))

        if self.amount:
            self.amount = Decimal(self.amount)

        self.price = self.format_prices(ready_locales)
Beispiel #2
0
    def __init__(self, seller, config):
        self.amount = None
        self.active = True
        self.currency = 'USD'
        self.seller = seller
        self.recurrence = None
        self.img = ('https://raw.githubusercontent.com/mozilla'
                    '/payments-config/master/payments_config'
                    '/assets/default.png')

        for k in self.required:
            if k not in config:
                raise ValueError('Missing {} on product'.format(k))

        for k, v in config.items():
            setattr(self, k, v)

        self.id = seller.id + '-' + config['id']

        if self.recurrence and self.recurrence not in ['monthly']:
            raise ValueError(
                'Recurrence should be not set or monthly: {}'.format(
                    self.recurrence))

        if (self.user_identification not in self.valid_user_identifications):
            raise ValueError('user_identification must be one of: {}'.format(
                self.valid_user_identifications))

        if self.amount:
            self.amount = Decimal(self.amount)

        self.price = self.format_prices(ready_locales)
Beispiel #3
0
    def __init__(self, id, config):
        self.id = id
        self.products = [Product(self.id, p) for p in config.pop('products')]

        # Check ids are unique.
        if self.id in sellers:
            raise ValueError('Repeated seller uid: {}'.format(self.id))

        for k, v in config.items():
            setattr(self, k, v)

        sellers[self.id] = self
    def __init__(self, id, config):
        self.id = id

        for k in self.required:
            if k not in config:
                raise ValueError('Missing {} on seller'.format(k))

        for k, v in config.items():
            setattr(self, k, v)

        self.products = [Product(self, p) for p in config['products']]

        if self.kind not in ['products', 'donations']:
            raise ValueError('Unknown kind of seller: {}'.format(self.kind))
Beispiel #5
0
    def __init__(self, id, config):
        self.id = id

        for k in self.required:
            if k not in config:
                raise ValueError('Missing {} on seller'.format(k))

        for k, v in config.items():
            setattr(self, k, v)

        self.products = [Product(self, p) for p in config['products']]

        if self.kind not in ['products', 'donations']:
            raise ValueError('Unknown kind of seller: {}'.format(self.kind))
    def __init__(self, id, config):
        # Provide some defaults.
        self.active = True
        self.currency = 'USD'
        self.img = ('https://raw.githubusercontent.com/mozilla'
                    '/payments-config/master/config/assets/brick.png')

        self.id = id + '-' + config.pop('id')

        # Check ids are unique.
        if self.id in products:
            raise ValueError('Repeated product uid: {}'.format(self.id))

        for k, v in config.items():
            setattr(self, k, v)

        self.amount = Decimal(self.amount)
        products[self.id] = self
Beispiel #7
0
            raise ValueError('Repeated product uid: {}'.format(self.id))

        for k, v in config.items():
            setattr(self, k, v)

        self.amount = Decimal(self.amount)

        self.price = self.format_prices(ready_locales)

        products[self.id] = self

    def format_prices(self, locales):
        prices = {}
        for locale in locales:
            try:
                prices[locale] = numbers.format_currency(
                    self.amount, self.currency, locale=locale)
            except babel.core.UnknownLocaleError:
                print 'Ignoring unknown locale: {}'.format(locale)
                continue

        return prices

    def to_dump(self):
        return self.__dict__


if not products and not sellers:
    for key, seller in config.items():
        Seller(key, seller)