allow to specify the logger to user #2
This commit is contained in:
parent
315297d29f
commit
e9e0d19730
|
@ -62,10 +62,16 @@ class Payment(object):
|
|||
|
||||
'''
|
||||
|
||||
def __init__(self, kind, options, log_domain='eopayment'):
|
||||
self.logger = logging.getLogger(log_domain)
|
||||
def __init__(self, kind, options, logger=None):
|
||||
self.logger = logger
|
||||
self.kind = kind
|
||||
self.backend = get_backend(kind)(options, logger=self.logger)
|
||||
self.backend = get_backend(kind)(options, **self.__get_extra_args())
|
||||
|
||||
def __get_extra_args(self):
|
||||
if self.logger:
|
||||
return { 'logger': self.logger }
|
||||
else:
|
||||
return {}
|
||||
|
||||
def request(self, amount, email=None, next_url=None):
|
||||
'''Request a payment to the payment backend.
|
||||
|
@ -98,7 +104,8 @@ class Payment(object):
|
|||
# present the form in HTML to the user
|
||||
|
||||
'''
|
||||
return self.backend.request(amount, email=email, next_url=next_url, logger=self.logger)
|
||||
return self.backend.request(amount, email=email, next_url=next_url,
|
||||
**self.__get_extra_args())
|
||||
|
||||
def response(self, query_string):
|
||||
'''
|
||||
|
@ -133,7 +140,7 @@ class Payment(object):
|
|||
your site as a web service.
|
||||
|
||||
'''
|
||||
return self.backend.response(query_string, logger=self.logger)
|
||||
return self.backend.response(query_string, **self.__get_extra_args())
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
|
|
@ -50,8 +50,8 @@ class PaymentCommon(object):
|
|||
PATH = '/tmp'
|
||||
BANK_ID = '__bank_id'
|
||||
|
||||
def __init__(self, options):
|
||||
LOGGER.debug('initializing with options %s' % options)
|
||||
def __init__(self, options, logger=LOGGER):
|
||||
logger.debug('initializing with options %s' % options)
|
||||
for key, value in self.description['parameters'].iteritems():
|
||||
if 'default' in value:
|
||||
setattr(self, key, options.get(key, None) or value['default'])
|
||||
|
|
|
@ -161,7 +161,7 @@ class Payment(PaymentCommon):
|
|||
ctx_mode='PRODUCTION')
|
||||
|
||||
'''
|
||||
def __init__(self, options):
|
||||
def __init__(self, options, logger=LOGGER):
|
||||
self.secrets = options.pop('secrets')
|
||||
options = add_vads(options)
|
||||
self.options = options
|
||||
|
|
Loading…
Reference in New Issue