summaryrefslogtreecommitdiff
path: root/addons/payment_test
diff options
context:
space:
mode:
authorAurélien Warnon <awa@odoo.com>2019-04-29 09:47:22 +0000
committerThibault Delavallée <tde@odoo.com>2019-08-28 13:27:59 +0000
commite7c47614645d789a294d85bd647d68ff3b088857 (patch)
treeef7fcdbf7f9e4079f34f34a2736a11adb9c86671 /addons/payment_test
parentff768a0642572798489400a41d6fafdaac5320cf (diff)
[ADD] payment_test: add a payment acquirer to be used for testing only
PURPOSE Test frontend and UI tools of eLearning. SPECIFICATIONS This new module implements a simple test payment acquirer in order to allow testing successful payments behaviors, notably on eCommerce. Its usage is prevented in other state then test to avoid any potential misuse. LINKS Task ID 1937768
Diffstat (limited to 'addons/payment_test')
-rw-r--r--addons/payment_test/__init__.py7
-rw-r--r--addons/payment_test/__manifest__.py20
-rw-r--r--addons/payment_test/controllers/__init__.py3
-rw-r--r--addons/payment_test/controllers/main.py26
-rw-r--r--addons/payment_test/data/payment_acquirer_data.xml29
-rw-r--r--addons/payment_test/models/__init__.py4
-rw-r--r--addons/payment_test/models/payment_acquirer.py42
-rw-r--r--addons/payment_test/static/description/icon.pngbin0 -> 6019 bytes
-rw-r--r--addons/payment_test/static/src/img/test_logo.jpgbin0 -> 4406 bytes
-rw-r--r--addons/payment_test/views/payment_test_templates.xml26
10 files changed, 157 insertions, 0 deletions
diff --git a/addons/payment_test/__init__.py b/addons/payment_test/__init__.py
new file mode 100644
index 00000000000..ea1ce001fba
--- /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 00000000000..8274258cd4e
--- /dev/null
+++ b/addons/payment_test/__manifest__.py
@@ -0,0 +1,20 @@
+# -*- 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',
+}
diff --git a/addons/payment_test/controllers/__init__.py b/addons/payment_test/controllers/__init__.py
new file mode 100644
index 00000000000..65a8c12013d
--- /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 00000000000..72ec4a04389
--- /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 00000000000..3c82823dbf5
--- /dev/null
+++ b/addons/payment_test/data/payment_acquirer_data.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo><data noupdate="1">
+ <record id="payment_acquirer_test" model="payment.acquirer">
+ <field name="name">Test</field>
+ <field name="display_as">Test (do not use in production)</field>
+ <field name="sequence">99</field>
+ <field name="provider">test</field>
+ <field name="image_128" type="base64" file="payment_test/static/src/img/test_logo.jpg"/>
+ <field name="description" type="html">
+<p>Test Payment Acquirer</p>
+<ul class="list-inline">
+ <li class="list-inline-item"><i class="fa fa-check"/>S2S Online Payment</li>
+ <li class="list-inline-item"><i class="fa fa-check"/>Payment status tracking</li>
+ <li class="list-inline-item"><i class="fa fa-check"/>Never loose money while testing</li>
+</ul>
+ </field>
+ <field name="payment_icon_ids" eval='[(6, 0, [ref("payment.payment_icon_cc_ideal"),
+ ref("payment.payment_icon_cc_bancontact"),
+ ref("payment.payment_icon_cc_maestro"),
+ ref("payment.payment_icon_cc_mastercard"),
+ ref("payment.payment_icon_cc_visa")])]'/>
+
+ <field name="module_id" ref="base.module_payment_test"/>
+ <field name="company_id" ref="base.main_company"/>
+ <field name="registration_view_template_id" ref="test_s2s_form"/>
+ <field name="state">test</field>
+ <field name="payment_flow">s2s</field>
+ </record>
+</data></odoo>
diff --git a/addons/payment_test/models/__init__.py b/addons/payment_test/models/__init__.py
new file mode 100644
index 00000000000..cae99a2c472
--- /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 00000000000..9867b499b4b
--- /dev/null
+++ b/addons/payment_test/models/payment_acquirer.py
@@ -0,0 +1,42 @@
+# 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')])
+
+ @api.model
+ def create(self, values):
+ if values.get('provider') == 'test' and 'state' in values and values.get('state') != 'test':
+ raise exceptions.UserError(_('This acquirer should not be used for other purpose 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') != 'test':
+ raise exceptions.UserError(_('This acquirer should not be used for other purpose 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'])
+ })
+ 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'}
diff --git a/addons/payment_test/static/description/icon.png b/addons/payment_test/static/description/icon.png
new file mode 100644
index 00000000000..81bb12e9ed8
--- /dev/null
+++ b/addons/payment_test/static/description/icon.png
Binary files 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 00000000000..16adc0642ca
--- /dev/null
+++ b/addons/payment_test/static/src/img/test_logo.jpg
Binary files 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 00000000000..808ae4a6631
--- /dev/null
+++ b/addons/payment_test/views/payment_test_templates.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+ <template id="test_s2s_form">
+ <input type="hidden" name="data_set" data-create-route="/payment/test/s2s/create_json_3ds"/>
+ <input type="hidden" name="acquirer_id" t-att-value="id"/>
+ <input t-if="return_url" type="hidden" name="return_url" t-att-value="return_url"/>
+ <input t-if="partner_id" type="hidden" name="partner_id" t-att-value="partner_id"/>
+ <div t-attf-class="row mt8 #{'' if bootstrap_formatting else 'o_card_brand_detail'}">
+ <div t-att-class="'form-group col-lg-12' if bootstrap_formatting else 'form-group'">
+ <input type="tel" name="cc_number" id="cc_number" class="form-control" placeholder="Card number" data-is-required="true"/>
+ <div class="card_placeholder"></div>
+ <div class="visa"></div>
+ <input type="hidden" name="cc_brand" value=""/>
+ </div>
+ <div t-att-class="'form-group col-lg-5' if bootstrap_formatting else 'form-group'">
+ <input type="text" name="cc_holder_name" id="cc_holder_name" class="form-control" placeholder="Cardholder name" data-is-required="true"/>
+ </div>
+ <div t-att-class="'form-group col-lg-3' if bootstrap_formatting else 'form-group'">
+ <input type="text" name="cc_expiry" id="cc_expiry" class="form-control" maxlength="7" placeholder="Expires (MM / YY)" data-is-required="true"/>
+ </div>
+ <div t-att-class="'form-group col-lg-4' if bootstrap_formatting else 'form-group'">
+ <input type="text" name="cvc" id="cvc" class="form-control" maxlength="4" placeholder="CVC" data-is-required="true"/>
+ </div>
+ </div>
+ </template>
+</odoo>