diff --git a/payment_forte/__manifest__.py b/payment_forte/__manifest__.py index 927f5df0..8d0fbd8d 100644 --- a/payment_forte/__manifest__.py +++ b/payment_forte/__manifest__.py @@ -3,7 +3,7 @@ 'author': 'Hibou Corp. ', 'category': 'Accounting', 'summary': 'Payment Acquirer: Forte Implementation', - 'version': '11.0.1.0.0', + 'version': '15.0.1.0.0', 'description': """Forte Payment Acquirer""", 'depends': ['payment'], 'data': [ diff --git a/payment_forte/data/payment_acquirer_data.xml b/payment_forte/data/payment_acquirer_data.xml index 2106e9d1..7ca6a85a 100644 --- a/payment_forte/data/payment_acquirer_data.xml +++ b/payment_forte/data/payment_acquirer_data.xml @@ -2,12 +2,13 @@ - + Forte forte - test + test 1000 + 1001 dummy dummy diff --git a/payment_forte/models/payment.py b/payment_forte/models/payment.py index 1bbb7e8a..3b16830a 100644 --- a/payment_forte/models/payment.py +++ b/payment_forte/models/payment.py @@ -11,13 +11,14 @@ def forte_get_api(acquirer): return ForteAPI(acquirer.forte_organization_id, acquirer.forte_access_id, acquirer.forte_secure_key, - acquirer.environment) + acquirer.state) class PaymentAcquirerForte(models.Model): _inherit = 'payment.acquirer' - provider = fields.Selection(selection_add=[('forte', 'Forte')]) + provider = fields.Selection(selection_add=[('forte', 'Forte')], + ondelete={'forte': 'set default'}) forte_organization_id = fields.Char(string='Organization ID') forte_location_id = fields.Char(string='Location ID') # Probably move to Journal... forte_access_id = fields.Char(string='Access ID') @@ -39,7 +40,6 @@ class PaymentAcquirerForte(models.Model): res['tokenize'].append('authorize') return res - @api.multi def forte_test_credentials(self): self.ensure_one() api = forte_get_api(self) diff --git a/payment_forte/tests/test_forte.py b/payment_forte/tests/test_forte.py index 01ee8d9f..42f4bd3c 100644 --- a/payment_forte/tests/test_forte.py +++ b/payment_forte/tests/test_forte.py @@ -1,25 +1,51 @@ -from odoo.addons.payment.tests.common import PaymentAcquirerCommon +from odoo.addons.payment.tests.common import PaymentCommon from odoo.exceptions import ValidationError +from odoo.tests import tagged -class ForteCommon(PaymentAcquirerCommon): - def setUp(self): - super(ForteCommon, self).setUp() - self.currency_usd = self.env['res.currency'].search([('name', '=', 'USD')], limit=1)[0] - self.forte = self.env.ref('payment.payment_acquirer_forte') - self.method = self.env['account.payment.method'].search([('code', '=', 'electronic')], limit=1)[0] - self.journal = self.env['account.journal'].search([], limit=1)[0] +class ForteCommon(PaymentCommon): + + @classmethod + def setUpClass(cls, chart_template_ref=None): + super().setUpClass(chart_template_ref=chart_template_ref) + + cls.currency_usd = cls._prepare_currency('USD') + cls.forte = cls._prepare_acquirer('forte', update_values={ + 'fees_active': False, # Only activate fees in dedicated tests + 'forte_organization_id': '366035', + 'forte_location_id': '223008', + 'forte_access_id': 'a7b45fe9ff8d1d5406ae6f98791958da', + 'forte_secure_key': '20ee1d1f5a4afbf9db03af2c81f067c5', + }) + + # override defaults for helpers + cls.acquirer = cls.forte + cls.currency = cls.currency_usd + cls.forte = cls.acquirer + cls.method = cls.env['account.payment.method'].search([('code', '=', 'electronic')], limit=1)[0] + cls.journal = cls.env['account.journal'].search([], limit=1)[0] + cls.journal.write({ + 'inbound_payment_method_line_ids': [(0, 0, { + 'name': 'Electronic', + 'payment_method_id': cls.method.id, + })], + }) + cls.method_line = cls.journal.inbound_payment_method_line_ids.filtered(lambda l: l.payment_method_id == cls.method) + cls.buyer = cls.env['res.partner'].search([('customer_rank', '>=', 1)], limit=1)[0] +@tagged('post_install', '-at_install') class ForteACH(ForteCommon): + def test_10_forte_api(self): - self.assertEqual(self.forte.environment, 'test', 'Must test with test environment.') + self.assertEqual(self.forte.state, 'test', 'Must test with test environment.') response = self.forte.forte_test_credentials() # Create/Save a Payment Token. # Change Token numbers to real values if you want to try to get an approval. token = self.env['payment.token'].create({ - 'partner_id': self.buyer_id, + 'name': 'Test Token 1234', + 'partner_id': self.buyer.id, 'acquirer_id': self.forte.id, 'acquirer_ref': 'Test Token', 'forte_account_type': 'Checking', @@ -33,13 +59,17 @@ class ForteACH(ForteCommon): payment = self.env['account.payment'].create({ 'payment_type': 'inbound', 'journal_id': self.journal.id, - 'partner_id': self.buyer_id, + 'partner_id': self.buyer.id, 'payment_token_id': token.id, 'payment_method_id': self.method.id, + 'payment_method_line_id': self.method_line.id, 'amount': 22.00, }) + self.assertTrue(payment.payment_transaction_id) self.assertEqual(payment.payment_transaction_id.amount, 22.00) self.assertTrue(payment.payment_transaction_id.acquirer_reference) except ValidationError as e: - self.assertTrue(e.name.find('U02') >= 0) + # U02 account not authorized. + if e.name.find('U02') < 0: + raise e diff --git a/payment_forte/views/payment_views.xml b/payment_forte/views/payment_views.xml index 863b4fb8..9ca49e4f 100644 --- a/payment_forte/views/payment_views.xml +++ b/payment_forte/views/payment_views.xml @@ -3,7 +3,7 @@ acquirer.form.forte payment.acquirer - + @@ -19,7 +19,7 @@ payment.token.form payment.token - +