Exemplo n.º 1
0
    def _get_adapter(self):
        # FIXME: Check if payment_method is set.
        provider_name = re.sub('([a-z]+)([A-Z][a-z]+)', r'\1',
                               self.order_payment.payment_method)
        method_name = re.sub('([a-z]+)([A-Z][a-z]+)', r'\2',
                             self.order_payment.payment_method)
        app_name = 'payments_' + provider_name

        # First try to load the specific profile adapter
        class_name = provider_name.title() + method_name + 'PaymentAdapter'
        class_path = 'bluebottle.' + app_name + '.adapters.' + class_name
        try:
            adapter_class = get_class(class_path)
        except GetClassError:
            # Now try to load the generic provider adapter
            class_name = provider_name.title() + 'PaymentAdapter'
            class_path = 'bluebottle.' + app_name + '.adapters.' + class_name
            try:
                adapter_class = get_class(class_path)
            except GetClassError:
                raise PaymentException(
                    "Couldn't find an adapter for payment method '{0}'".format(
                        self.order_payment.payment_method))

        adapter = adapter_class(self.order_payment)
        return adapter
Exemplo n.º 2
0
def _process_handler(backend, timestamp, tags, fields):
    try:
        handler_class = backend['handler_class']
        handler = get_class(handler_class)(conf=backend)
        handler.process(timestamp, tags, fields)
    except Exception as exc:
        raise AnalyticsException(exc)
Exemplo n.º 3
0
def queue_analytics_record(timestamp, tags, fields):
    tags = tags or {}
    fields = fields or {}

    try:
        # TODO: logging to multiple backends could happen here, eg
        #       to influxdb and to log file.
        backend = settings.ANALYTICS_BACKENDS['default']
        handler_class = backend['handler_class']
    except AttributeError as e:
        logger.warning('Analytics backend not found: %s', e.message,
                       exc_info=1)
        return

    handler = get_class(handler_class)(conf=backend)
    handler.process(timestamp, tags, fields)
Exemplo n.º 4
0
    def _get_adapter(self):
        # FIXME: Check if payment_method is set.
        provider_name = re.sub('([a-z]+)([A-Z][a-z]+)', r'\1',
                               self.order_payment.payment_method)
        app_name = 'payments_' + provider_name
        class_name = provider_name.title() + 'PaymentAdapter'
        class_path = 'bluebottle.' + app_name + '.adapters.' + class_name

        try:
            adapter_class = get_class(class_path)
        except ImportError:
            raise PaymentException(
                "Couldn't find an adapter for payment method '{0}'".format(
                    self.order_payment.payment_method))

        adapter = adapter_class(self.order_payment)
        return adapter
Exemplo n.º 5
0
 def get_adapter(self):
     adapter_name = 'bluebottle.notifications.adapters.{}.{}MessageAdapter'.format(
         self.adapter, self.adapter.title())
     return get_class(adapter_name)
Exemplo n.º 6
0
 def to_representation(self, obj):
     """
     Project Add On Polymorphic serialization
     """
     AddOnSerializer = get_class(obj.serializer)
     return AddOnSerializer(obj, context=self.context).to_representation(obj)