[IMP] payment modules: added provider selection field that is different

from the name. This allows to distinguish name and provider. Provider is a more
technical field, used to call some specific methods (<provider>_method_name). The
name field is used for display on the website.

Code and views udpated accordingly.

bzr revid: tde@openerp.com-20140319144608-0i4rv520l0bh53f0
This commit is contained in:
Thibault Delavallée 2014-03-19 15:46:08 +01:00
parent 10babec89d
commit 38ae695d00
14 changed files with 63 additions and 31 deletions

View File

@ -52,8 +52,15 @@ class PaymentAcquirer(osv.Model):
_name = 'payment.acquirer'
_description = 'Payment Acquirer'
def _get_providers(self, cr, uid, context=None):
return []
# indirection to ease inheritance
_provider_selection = lambda self, *args, **kwargs: self._get_providers(*args, **kwargs)
_columns = {
'name': fields.char('Name', required=True),
'provider': fields.selection(_provider_selection, string='Provider', required=True),
'company_id': fields.many2one('res.company', 'Company', required=True),
'pre_msg': fields.html('Message', help='Message displayed to explain and help the payment process.'),
'post_msg': fields.html('Thanks Message', help='Message displayed after having done the payment process.'),
@ -84,10 +91,10 @@ class PaymentAcquirer(osv.Model):
}
def _check_required_if_provider(self, cr, uid, ids, context=None):
""" If the field has 'required_if_provider="<name>"' attribute, then it
required if record.name is <name>. """
""" If the field has 'required_if_provider="<provider>"' attribute, then it
required if record.provider is <provider>. """
for acquirer in self.browse(cr, uid, ids, context=context):
if any(c for c, f in self._all_columns.items() if getattr(f.column, 'required_if_provider', None) == acquirer.name and not acquirer[c]):
if any(c for c, f in self._all_columns.items() if getattr(f.column, 'required_if_provider', None) == acquirer.provider and not acquirer[c]):
return False
return True
@ -98,8 +105,8 @@ class PaymentAcquirer(osv.Model):
def get_form_action_url(self, cr, uid, id, context=None):
""" Returns the form action URL, for form-based acquirer implementations. """
acquirer = self.browse(cr, uid, id, context=context)
if hasattr(self, '%s_get_form_action_url' % acquirer.name):
return getattr(self, '%s_get_form_action_url' % acquirer.name)(cr, uid, id, context=context)
if hasattr(self, '%s_get_form_action_url' % acquirer.provider):
return getattr(self, '%s_get_form_action_url' % acquirer.provider)(cr, uid, id, context=context)
return False
def form_preprocess_values(self, cr, uid, id, reference, amount, currency_id, tx_id, partner_id, partner_values, tx_values, context=None):
@ -178,7 +185,7 @@ class PaymentAcquirer(osv.Model):
})
# compute fees
fees_method_name = '%s_compute_fees' % acquirer.name
fees_method_name = '%s_compute_fees' % acquirer.provider
if hasattr(self, fees_method_name):
fees = getattr(self, fees_method_name)(
cr, uid, id, tx_data['amount'], tx_data['currency_id'], partner_data['country_id'], context=None)
@ -237,7 +244,7 @@ class PaymentAcquirer(osv.Model):
partner_values, tx_values, context=context)
# call <name>_form_generate_values to update the tx dict with acqurier specific values
cust_method_name = '%s_form_generate_values' % (acquirer.name)
cust_method_name = '%s_form_generate_values' % (acquirer.provider)
if hasattr(self, cust_method_name):
method = getattr(self, cust_method_name)
partner_values, tx_values = method(cr, uid, id, partner_values, tx_values, context=context)
@ -383,14 +390,14 @@ class PaymentTransaction(osv.Model):
acquirer = self.pool['payment.acquirer'].browse(cr, uid, values.get('acquirer_id'), context=context)
# compute fees
custom_method_name = '%s_compute_fees' % acquirer.name
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.name
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))
@ -469,7 +476,7 @@ class PaymentTransaction(osv.Model):
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.name
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)
@ -482,7 +489,7 @@ class PaymentTransaction(osv.Model):
tx = self.browse(cr, uid, tx_id, context=context)
invalid_parameters = None
invalid_param_method_name = '_%s_s2s_get_invalid_parameters' % tx.acquirer_id.name
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)
@ -493,7 +500,7 @@ class PaymentTransaction(osv.Model):
_logger.error(_error_message)
return False
feedback_method_name = '_%s_s2s_validate' % tx.acquirer_id.name
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)
@ -503,7 +510,7 @@ class PaymentTransaction(osv.Model):
""" 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.name
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)

View File

@ -16,6 +16,7 @@
<group name="acquirer_base">
<group>
<field name="name"/>
<field name="provider"/>
<field name="company_id"/>
<field name="website_published"/>
<field name="env"/>
@ -66,6 +67,7 @@
<field name="arch" type="xml">
<tree string="Payment Acquirers">
<field name="name"/>
<field name="provider"/>
<field name="website_published"/>
<field name="env"/>
</tree>
@ -77,6 +79,10 @@
<field name="arch" type="xml">
<search>
<field name="name"/>
<field name="provider"/>
<group expand="0" string="Group By...">
<filter string="Provider" name="provider" domain="[]" context="{'group_by': 'provider'}"/>
</group>
</search>
</field>
</record>

View File

@ -3,7 +3,8 @@
<data noupdate="1">
<record id="payment_acquirer_adyen" model="payment.acquirer">
<field name="name">adyen</field>
<field name="name">Adyen</field>
<field name="provider">adyen</field>
<field name="company_id" ref="base.main_company"/>
<field name="view_template_id" ref="adyen_acquirer_button"/>
<field name="env">test</field>

View File

@ -26,14 +26,14 @@ class AcquirerAdyen(osv.Model):
- yhpp: hosted payment page: pay.shtml for single, select.shtml for multiple
"""
if env == 'prod':
return {
'adyen_form_url': 'https://prod.adyen.com/hpp/pay.shtml',
}
else:
return {
'adyen_form_url': 'https://test.adyen.com/hpp/pay.shtml',
}
return {
'adyen_form_url': 'https://%s.adyen.com/hpp/pay.shtml' % env,
}
def _get_providers(self, cr, uid, context=None):
providers = super(AcquirerAdyen, self)._get_providers(cr, uid, context=context)
providers.append(['adyen', 'Adyen'])
return providers
_columns = {
'adyen_merchant_account': fields.char('Merchant Account', required_if_provider='adyen'),
@ -54,7 +54,7 @@ class AcquirerAdyen(osv.Model):
:return string: shasign
"""
assert inout in ('in', 'out')
assert acquirer.name == 'adyen'
assert acquirer.provider == 'adyen'
if inout == 'in':
keys = "paymentAmount currencyCode shipBeforeDate merchantReference skinCode merchantAccount sessionValidity shopperEmail shopperReference recurringContract allowedMethods blockedMethods shopperStatement merchantReturnData billingAddressType deliveryAddressType offset".split()

View File

@ -8,7 +8,7 @@
<field name="inherit_id" ref="payment.acquirer_form"/>
<field name="arch" type="xml">
<xpath expr='//group[@name="acquirer_display"]' position='after'>
<group attrs="{'invisible': [('name', '!=', 'adyen')]}">
<group attrs="{'invisible': [('provider', '!=', 'adyen')]}">
<field name="adyen_merchant_account"/>
<field name="adyen_skin_code"/>
<field name="adyen_skin_hmac_key"/>

View File

@ -3,7 +3,8 @@
<data noupdate="1">
<record id="payment_acquirer_ogone" model="payment.acquirer">
<field name="name">ogone</field>
<field name="name">Credit Card</field>
<field name="provider">ogone</field>
<field name="company_id" ref="base.main_company"/>
<field name="view_template_id" ref="ogone_acquirer_button"/>
<field name="env">test</field>

View File

@ -36,6 +36,11 @@ class PaymentAcquirerOgone(osv.Model):
'ogone_afu_agree_url': 'https://secure.ogone.com/ncol/%s/AFU_agree.asp' % (env,),
}
def _get_providers(self, cr, uid, context=None):
providers = super(PaymentAcquirerOgone, self)._get_providers(cr, uid, context=context)
providers.append(['ogone', 'Ogone'])
return providers
_columns = {
'ogone_pspid': fields.char('PSPID', required_if_provider='ogone'),
'ogone_userid': fields.char('API User ID', required_if_provider='ogone'),
@ -57,7 +62,7 @@ class PaymentAcquirerOgone(osv.Model):
:return string: shasign
"""
assert inout in ('in', 'out')
assert acquirer.name == 'ogone'
assert acquirer.provider == 'ogone'
key = getattr(acquirer, 'ogone_shakey_' + inout)
def filter_key(key):

View File

@ -8,7 +8,7 @@
<field name="inherit_id" ref="payment.acquirer_form"/>
<field name="arch" type="xml">
<xpath expr='//group[@name="acquirer_display"]' position='after'>
<group attrs="{'invisible': [('name', '!=', 'ogone')]}">
<group attrs="{'invisible': [('provider', '!=', 'ogone')]}">
<field name="ogone_pspid"/>
<field name="ogone_userid"/>
<field name="ogone_password"/>

View File

@ -3,7 +3,8 @@
<data noupdate="1">
<record id="payment_acquirer_paypal" model="payment.acquirer">
<field name="name">paypal</field>
<field name="name">Paypal</field>
<field name="provider">paypal</field>
<field name="company_id" ref="base.main_company"/>
<field name="view_template_id" ref="paypal_acquirer_button"/>
<field name="env">test</field>

View File

@ -34,6 +34,11 @@ class AcquirerPaypal(osv.Model):
'paypal_rest_url': 'https://api.sandbox.paypal.com/v1/oauth2/token',
}
def _get_providers(self, cr, uid, context=None):
providers = super(AcquirerPaypal, self)._get_providers(cr, uid, context=context)
providers.append(['paypal', 'Paypal'])
return providers
_columns = {
'paypal_email_account': fields.char('Paypal Email ID', required_if_provider='paypal'),
'paypal_seller_account': fields.char(

View File

@ -8,7 +8,7 @@
<field name="inherit_id" ref="payment.acquirer_form"/>
<field name="arch" type="xml">
<xpath expr='//group[@name="acquirer_display"]' position='after'>
<group attrs="{'invisible': [('name', '!=', 'paypal')]}">
<group attrs="{'invisible': [('provider', '!=', 'paypal')]}">
<group>
<group>
<field name="paypal_email_account"/>

View File

@ -3,7 +3,8 @@
<data noupdate="1">
<record id="payment_acquirer_transfer" model="payment.acquirer">
<field name="name">transfer</field>
<field name="name">Transfer</field>
<field name="provider">transfer</field>
<field name="company_id" ref="base.main_company"/>
<field name="view_template_id" ref="transfer_acquirer_button"/>
<field name="validation">manual</field>

View File

@ -14,6 +14,11 @@ _logger = logging.getLogger(__name__)
class TransferPaymentAcquirer(osv.Model):
_inherit = 'payment.acquirer'
def _get_providers(self, cr, uid, context=None):
providers = super(TransferPaymentAcquirer, self)._get_providers(cr, uid, context=context)
providers.append(['transfer', 'Transfer'])
return providers
def transfer_get_form_action_url(self, cr, uid, id, context=None):
return '/payment/transfer/feedback'

View File

@ -956,7 +956,7 @@
<input t-att-value="acquirer.id" type="radio" name="acquirer" t-att-checked="acquirers[0] == acquirer"/>
<img class="media-object" style="width: 60px; display: inline-block;"
t-att-title="acquirer.name"
t-att-src="'/payment_%s/static/src/img/%s_icon.png' % (acquirer.name, acquirer.name)"/>
t-att-src="'/payment_%s/static/src/img/%s_icon.png' % (acquirer.provider, acquirer.provider)"/>
<span t-field="acquirer.name"/>
</label>
</li>