From f26524e7dd60645cc391936e5f177a84229230c9 Mon Sep 17 00:00:00 2001 From: sheetalPatil Date: Mon, 9 Jul 2018 18:44:39 +0530 Subject: [PATCH] [ADD]:Added Upstream patch for payment_authorize --- addons/payment_authorize/__init__.py | 1 + addons/payment_authorize/__manifest__.py | 1 + addons/payment_authorize/models/payment.py | 17 +++++++++++++---- .../payment_authorize/tests/test_authorize.py | 4 ++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/addons/payment_authorize/__init__.py b/addons/payment_authorize/__init__.py index 81ea421d..96f1329b 100644 --- a/addons/payment_authorize/__init__.py +++ b/addons/payment_authorize/__init__.py @@ -3,3 +3,4 @@ from . import models from . import controllers +from flectra.addons.payment.models.payment_acquirer import create_missing_journal_for_acquirers diff --git a/addons/payment_authorize/__manifest__.py b/addons/payment_authorize/__manifest__.py index f4eef11e..da68fb11 100644 --- a/addons/payment_authorize/__manifest__.py +++ b/addons/payment_authorize/__manifest__.py @@ -14,4 +14,5 @@ 'data/payment_acquirer_data.xml', ], 'installable': True, + 'post_init_hook': 'create_missing_journal_for_acquirers', } diff --git a/addons/payment_authorize/models/payment.py b/addons/payment_authorize/models/payment.py index 31126e82..5fa28aac 100644 --- a/addons/payment_authorize/models/payment.py +++ b/addons/payment_authorize/models/payment.py @@ -11,7 +11,7 @@ import time from flectra import _, api, fields, models from flectra.addons.payment.models.payment_acquirer import ValidationError from flectra.addons.payment_authorize.controllers.main import AuthorizeController -from flectra.tools.float_utils import float_compare +from flectra.tools.float_utils import float_compare, float_repr from flectra.tools.safe_eval import safe_eval _logger = logging.getLogger(__name__) @@ -59,12 +59,21 @@ class PaymentAcquirerAuthorize(models.Model): @api.multi def authorize_form_generate_values(self, values): self.ensure_one() + # State code is only supported in US, use state name by default + # See https://developer.authorize.net/api/reference/ + state = values['partner_state'].name if values.get('partner_state') else '' + if values.get('partner_country') and values.get('partner_country') == self.env.ref('base.us', False): + state = values['partner_state'].code if values.get('partner_state') else '' + billing_state = values['billing_partner_state'].name if values.get('billing_partner_state') else '' + if values.get('billing_partner_country') and values.get('billing_partner_country') == self.env.ref('base.us', False): + billing_state = values['billing_partner_state'].code if values.get('billing_partner_state') else '' + base_url = self.env['ir.config_parameter'].get_param('web.base.url') authorize_tx_values = dict(values) temp_authorize_tx_values = { 'x_login': self.authorize_login, 'x_trans_key': self.authorize_transaction_key, - 'x_amount': str(values['amount']), + 'x_amount': float_repr(values['amount'], values['currency'].decimal_places if values['currency'] else 2), 'x_show_form': 'PAYMENT_FORM', 'x_type': 'AUTH_CAPTURE' if not self.capture_manually else 'AUTH_ONLY', 'x_method': 'CC', @@ -83,7 +92,7 @@ class PaymentAcquirerAuthorize(models.Model): 'first_name': values.get('partner_first_name'), 'last_name': values.get('partner_last_name'), 'phone': values.get('partner_phone'), - 'state': values.get('partner_state') and values['partner_state'].code or '', + 'state': state, 'billing_address': values.get('billing_partner_address'), 'billing_city': values.get('billing_partner_city'), 'billing_country': values.get('billing_partner_country') and values.get('billing_partner_country').name or '', @@ -92,7 +101,7 @@ class PaymentAcquirerAuthorize(models.Model): 'billing_first_name': values.get('billing_partner_first_name'), 'billing_last_name': values.get('billing_partner_last_name'), 'billing_phone': values.get('billing_partner_phone'), - 'billing_state': values.get('billing_partner_state') and values['billing_partner_state'].code or '', + 'billing_state': billing_state, } temp_authorize_tx_values['returndata'] = authorize_tx_values.pop('return_url', '') temp_authorize_tx_values['x_fp_hash'] = self._authorize_generate_hashing(temp_authorize_tx_values) diff --git a/addons/payment_authorize/tests/test_authorize.py b/addons/payment_authorize/tests/test_authorize.py index 6e5b8152..a5e436ee 100644 --- a/addons/payment_authorize/tests/test_authorize.py +++ b/addons/payment_authorize/tests/test_authorize.py @@ -51,7 +51,7 @@ class AuthorizeForm(AuthorizeCommon): form_values = { 'x_login': self.authorize.authorize_login, 'x_trans_key': self.authorize.authorize_transaction_key, - 'x_amount': '320.0', + 'x_amount': '56.16', 'x_show_form': 'PAYMENT_FORM', 'x_type': 'AUTH_CAPTURE', 'x_method': 'CC', @@ -87,7 +87,7 @@ class AuthorizeForm(AuthorizeCommon): form_values['x_fp_hash'] = self._authorize_generate_hashing(form_values) # render the button - res = self.authorize.render('SO004', 320.0, self.currency_usd.id, values=self.buyer_values) + res = self.authorize.render('SO004', 56.16, self.currency_usd.id, values=self.buyer_values) # check form result tree = objectify.fromstring(res)