From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/payment_test/__init__.py | 7 +++ addons/payment_test/__manifest__.py | 21 +++++++++ addons/payment_test/controllers/__init__.py | 3 ++ addons/payment_test/controllers/main.py | 26 +++++++++++ addons/payment_test/data/payment_acquirer_data.xml | 29 +++++++++++++ addons/payment_test/models/__init__.py | 4 ++ addons/payment_test/models/payment_acquirer.py | 48 +++++++++++++++++++++ addons/payment_test/static/description/icon.png | Bin 0 -> 6019 bytes addons/payment_test/static/src/img/test_logo.jpg | Bin 0 -> 4406 bytes .../payment_test/views/payment_test_templates.xml | 26 +++++++++++ 10 files changed, 164 insertions(+) create mode 100644 addons/payment_test/__init__.py create mode 100644 addons/payment_test/__manifest__.py create mode 100644 addons/payment_test/controllers/__init__.py create mode 100644 addons/payment_test/controllers/main.py create mode 100644 addons/payment_test/data/payment_acquirer_data.xml create mode 100644 addons/payment_test/models/__init__.py create mode 100644 addons/payment_test/models/payment_acquirer.py create mode 100644 addons/payment_test/static/description/icon.png create mode 100644 addons/payment_test/static/src/img/test_logo.jpg create mode 100644 addons/payment_test/views/payment_test_templates.xml (limited to 'addons/payment_test') diff --git a/addons/payment_test/__init__.py b/addons/payment_test/__init__.py new file mode 100644 index 00000000..ea1ce001 --- /dev/null +++ b/addons/payment_test/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.addons.payment.models.payment_acquirer import create_missing_journal_for_acquirers + +from . import models +from . import controllers diff --git a/addons/payment_test/__manifest__.py b/addons/payment_test/__manifest__.py new file mode 100644 index 00000000..1904f0d8 --- /dev/null +++ b/addons/payment_test/__manifest__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. +{ + 'name': 'Test Payment Acquirer', + 'version': '1.0', + 'category': 'Hidden', + 'description': """ +This module implements a simple test payment acquirer flow to allow +the testing of successful payments behaviors on e-commerce. It includes +a protection to avoid using it in production environment. However, do +not use it in production environment. +""", + 'depends': ['payment'], + 'data': [ + 'views/payment_test_templates.xml', + 'data/payment_acquirer_data.xml', + ], + 'installable': True, + 'post_init_hook': 'create_missing_journal_for_acquirers', + 'license': 'LGPL-3', +} diff --git a/addons/payment_test/controllers/__init__.py b/addons/payment_test/controllers/__init__.py new file mode 100644 index 00000000..65a8c120 --- /dev/null +++ b/addons/payment_test/controllers/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import main diff --git a/addons/payment_test/controllers/main.py b/addons/payment_test/controllers/main.py new file mode 100644 index 00000000..72ec4a04 --- /dev/null +++ b/addons/payment_test/controllers/main.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import http, _ +from odoo.http import request +from odoo.exceptions import UserError + + +class PaymentTestController(http.Controller): + + @http.route(['/payment/test/s2s/create_json_3ds'], type='json', auth='public', csrf=False) + def payment_test_s2s_create_json_3ds(self, verify_validity=False, **kwargs): + if not kwargs.get('partner_id'): + kwargs = dict(kwargs, partner_id=request.env.user.partner_id.id) + acquirer = request.env['payment.acquirer'].browse(int(kwargs.get('acquirer_id'))) + if acquirer.state != 'test': + raise UserError(_("Please do not use this acquirer for a production environment!")) + token = acquirer.s2s_process(kwargs) + + return { + 'result': True, + 'id': token.id, + 'short_name': 'short_name', + '3d_secure': False, + 'verified': True, + } diff --git a/addons/payment_test/data/payment_acquirer_data.xml b/addons/payment_test/data/payment_acquirer_data.xml new file mode 100644 index 00000000..3c82823d --- /dev/null +++ b/addons/payment_test/data/payment_acquirer_data.xml @@ -0,0 +1,29 @@ + + + + Test + Test (do not use in production) + 99 + test + + +

Test Payment Acquirer

+
    +
  • S2S Online Payment
  • +
  • Payment status tracking
  • +
  • Never loose money while testing
  • +
+
+ + + + + + test + s2s +
+
diff --git a/addons/payment_test/models/__init__.py b/addons/payment_test/models/__init__.py new file mode 100644 index 00000000..cae99a2c --- /dev/null +++ b/addons/payment_test/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import payment_acquirer diff --git a/addons/payment_test/models/payment_acquirer.py b/addons/payment_test/models/payment_acquirer.py new file mode 100644 index 00000000..965d5201 --- /dev/null +++ b/addons/payment_test/models/payment_acquirer.py @@ -0,0 +1,48 @@ +# coding: utf-8 +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from datetime import datetime +from uuid import uuid4 + +from odoo import api, exceptions, fields, models, _ + + +class PaymentAcquirerTest(models.Model): + _inherit = 'payment.acquirer' + + provider = fields.Selection(selection_add=[ + ('test', 'Test') + ], ondelete={'test': 'set default'}) + + @api.model + def create(self, values): + if values.get('provider') == 'test' and 'state' in values and values.get('state') not in ('test', 'disabled'): + raise exceptions.UserError(_('This acquirer should not be used for other purposes than testing.')) + return super(PaymentAcquirerTest, self).create(values) + + def write(self, values): + if any(rec.provider == 'test' for rec in self) and 'state' in values and values.get('state') not in ('test', 'disabled'): + raise exceptions.UserError(_('This acquirer should not be used for other purposes than testing.')) + return super(PaymentAcquirerTest, self).write(values) + + @api.model + def test_s2s_form_process(self, data): + """ Return a minimal token to allow proceeding to transaction creation. """ + payment_token = self.env['payment.token'].sudo().create({ + 'acquirer_ref': uuid4(), + 'acquirer_id': int(data['acquirer_id']), + 'partner_id': int(data['partner_id']), + 'name': 'Test - XXXXXXXXXXXX%s - %s' % (data['cc_number'][-4:], data['cc_holder_name']) + }) + return payment_token + + +class PaymentTransactionTest(models.Model): + _inherit = 'payment.transaction' + + def test_create(self, values): + """Automatically set the transaction as successful upon creation. """ + return {'date': datetime.now(), 'state': 'done'} + + def test_s2s_do_transaction(self, **kwargs): + self.execute_callback() diff --git a/addons/payment_test/static/description/icon.png b/addons/payment_test/static/description/icon.png new file mode 100644 index 00000000..81bb12e9 Binary files /dev/null and b/addons/payment_test/static/description/icon.png differ diff --git a/addons/payment_test/static/src/img/test_logo.jpg b/addons/payment_test/static/src/img/test_logo.jpg new file mode 100644 index 00000000..16adc064 Binary files /dev/null and b/addons/payment_test/static/src/img/test_logo.jpg differ diff --git a/addons/payment_test/views/payment_test_templates.xml b/addons/payment_test/views/payment_test_templates.xml new file mode 100644 index 00000000..808ae4a6 --- /dev/null +++ b/addons/payment_test/views/payment_test_templates.xml @@ -0,0 +1,26 @@ + + + + -- cgit v1.2.3