If you want to call custom create method if method is not defined then follow the following code in your .py file.
if values.get('acquirer_id'):
acquirer = self.pool['payment.acquirer'].browse(cr, uid, values.get('acquirer_id'), context=context)
# compute fees
custom_method_name = '%s_compute_fees' % acquirer.provider
if hasattr(Acquirer, custom_method_name):
fees = getattr(Acquirer, custom_method_name)(
cr, uid, acquirer.id, values.get('amount', 0.0), values.get('currency_id'), values.get('country_id'), context=None)
values['fees'] = float_round(fees, 2)
# custom create
custom_method_name = '%s_create' % acquirer.provider
if hasattr(self, custom_method_name):
values.update(getattr(self, custom_method_name)(cr, uid, values, context=context))
return super(PaymentTransaction, self).create(cr, uid, values, context=context)
def on_change_partner_id(self, cr, uid, ids, partner_id, context=None):
partner = None
if partner_id:
partner = self.pool['res.partner'].browse(cr, uid, partner_id, context=context)
return {'values': {
'partner_name': partner and partner.name or False,
'partner_lang': partner and partner.lang or 'en_US',
'partner_email': partner and partner.email or False,
'partner_zip': partner and partner.zip or False,
'partner_address': _partner_format_address(partner and partner.street or '', partner and partner.street2 or ''),
'partner_city': partner and partner.city or False,
'partner_country_id': partner and partner.country_id.id or False,
'partner_phone': partner and partner.phone or False,
}}
def form_feedback(self, cr, uid, data, acquirer_name, context=None):
invalid_parameters, tx = None, None
tx_find_method_name = '_%s_form_get_tx_from_data' % acquirer_name
if hasattr(self, tx_find_method_name):
tx = getattr(self, tx_find_method_name)(cr, uid, data, context=context)
invalid_param_method_name = '_%s_form_get_invalid_parameters' % acquirer_name
if hasattr(self, invalid_param_method_name):
invalid_parameters = getattr(self, invalid_param_method_name)(cr, uid, tx, data, context=context)
if invalid_parameters:
_error_message = '%s: incorrect tx data:\n' % (acquirer_name)
for item in invalid_parameters:
_error_message += '\t%s: received %s instead of %s\n' % (item[0], item[1], item[2])
_logger.error(_error_message)
return False
feedback_method_name = '_%s_form_validate' % acquirer_name
if hasattr(self, feedback_method_name):
return getattr(self, feedback_method_name)(cr, uid, tx, data, context=context)
return True
def s2s_create(self, cr, uid, values, cc_values, context=None):
tx_id, tx_result = self.s2s_send(cr, uid, values, cc_values, context=context)
self.s2s_feedback(cr, uid, tx_id, tx_result, context=context)
return tx_id
def s2s_send(self, cr, uid, values, cc_values, context=None):
""" Create and send server-to-server transaction.
:param dict values: transaction values
:param dict cc_values: credit card values that are not stored into the
payment.transaction object. Acquirers should
handle receiving void or incorrect cc values.
Should contain :
- holder_name
- number
- cvc
- brand
- expiry_date
- expiry_date_yy
- expiry_date_mm
"""
tx_id, result = None, None
if values.get('acquirer_id'):
acquirer = self.pool['payment.acquirer'].browse(cr, uid, values.get('acquirer_id'), context=context)
custom_method_name = '_%s_s2s_send' % acquirer.provider
if hasattr(self, custom_method_name):
tx_id, result = getattr(self, custom_method_name)(cr, uid, values, cc_values, context=context)
if tx_id is None and result is None:
tx_id = super(PaymentTransaction, self).create(cr, uid, values, context=context)
return (tx_id, result)
def s2s_feedback(self, cr, uid, tx_id, data, context=None):
""" Handle the feedback of a server-to-server transaction. """
tx = self.browse(cr, uid, tx_id, context=context)
invalid_parameters = None
invalid_param_method_name = '_%s_s2s_get_invalid_parameters' % tx.acquirer_id.provider
if hasattr(self, invalid_param_method_name):
invalid_parameters = getattr(self, invalid_param_method_name)(cr, uid, tx, data, context=context)
if invalid_parameters:
_error_message = '%s: incorrect tx data:\n' % (tx.acquirer_id.name)
for item in invalid_parameters:
_error_message += '\t%s: received %s instead of %s\n' % (item[0], item[1], item[2])
_logger.error(_error_message)
return False
feedback_method_name = '_%s_s2s_validate' % tx.acquirer_id.provider
if hasattr(self, feedback_method_name):
return getattr(self, feedback_method_name)(cr, uid, tx, data, context=context)
return True
def s2s_get_tx_status(self, cr, uid, tx_id, context=None):
""" Get the tx status. """
tx = self.browse(cr, uid, tx_id, context=context)
invalid_param_method_name = '_%s_s2s_get_tx_status' % tx.acquirer_id.provider
if hasattr(self, invalid_param_method_name):
return getattr(self, invalid_param_method_name)(cr, uid, tx, context=context)
return True
0 Comment(s)