[REV] Reverted commit 10171, because I would like to keep some HTML in a template...
authorThibault Delavallée <tde@openerp.com>
Wed, 4 Dec 2013 17:14:29 +0000 (18:14 +0100)
committerThibault Delavallée <tde@openerp.com>
Wed, 4 Dec 2013 17:14:29 +0000 (18:14 +0100)
bzr revid: tde@openerp.com-20131204171429-080i7cqhza7ig6bw

addons/website_payment/__init__.py
addons/website_payment/__openerp__.py
addons/website_payment/controllers/__init__.py [new file with mode: 0644]
addons/website_payment/controllers/main.py [new file with mode: 0644]
addons/website_payment/static/src/js/payment_acquirer.js [new file with mode: 0644]
addons/website_payment/static/src/js/website_payment.js [deleted file]
addons/website_payment/views/website_payment_templates.xml [new file with mode: 0644]

index ee70d6d..edccdf7 100644 (file)
@@ -18,3 +18,5 @@
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
+
+import controllers
index a0814e6..01b69d3 100644 (file)
@@ -1,24 +1,42 @@
 # -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
 
 {
-    'name': 'Payment: Website Bridge Integration',
+    'name': 'Payment: Website Integration (Test Module)',
     'category': 'Website',
-    'summary': 'Payment: Website Bridge Module',
+    'summary': 'Payment: Website Integration (Test Module)',
     'version': '1.0',
-    'description': """Bridge module between the payment acquirer module and the
-    website module.""",
+    'description': """Module installing all sub-payment modules and adding some
+    controllers and menu entries in order to test them.""",
     'author': 'OpenERP SA',
     'depends': [
         'website',
         'payment_acquirer',
+        'payment_acquirer_ogone',
+        'payment_acquirer_paypal',
+        'payment_acquirer_transfer',
     ],
     'data': [
+        'views/website_payment_templates.xml',
     ],
-    'js': [
-        'static/lib/jquery.payment/jquery.payment.js',
-        'static/src/js/website_payment.js'
-    ],
-    'css': [
-        'static/src/css/website_payment.css'
-    ],
+    'installable': False,
+    'active': False,
 }
diff --git a/addons/website_payment/controllers/__init__.py b/addons/website_payment/controllers/__init__.py
new file mode 100644 (file)
index 0000000..8ee9bae
--- /dev/null
@@ -0,0 +1 @@
+import main
diff --git a/addons/website_payment/controllers/main.py b/addons/website_payment/controllers/main.py
new file mode 100644 (file)
index 0000000..4a97197
--- /dev/null
@@ -0,0 +1,95 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from openerp.addons.web import http
+from openerp.addons.web.http import request
+from openerp.addons.website.models import website
+
+
+class WebsitePayment(http.Controller):
+
+    @website.route([
+        '/payment/paypal/test',
+    ], type='http', auth="public")
+    def paypal_test(self, **post):
+        """ TODO
+        """
+        cr, uid, context = request.cr, request.uid, request.context
+        acquirer_obj = request.registry['payment.acquirer']
+        payment_obj = request.registry['payment.transaction']
+        currency_obj = request.registry['res.currency']
+
+        paypal_id = acquirer_obj.search(cr, uid, [('name', '=', 'paypal')], limit=1, context=context)[0]
+        currency_id = currency_obj.search(cr, uid, [('name', '=', 'EUR')], limit=1, context=context)[0]
+
+        nbr_tx = payment_obj.search(cr, uid, [], count=True, context=context)
+        tx_id = payment_obj.create(cr, uid, {
+            'reference': 'test_ref_%s' % (nbr_tx),
+            'amount': 1.95,
+            'currency_id': currency_id,
+            'acquirer_id': paypal_id,
+            'partner_name': 'Norbert Buyer',
+            'partner_email': 'norbert.buyer@example.com',
+            'partner_lang': 'fr_FR',
+        }, context=context)
+
+        paypal_form = acquirer_obj.render(cr, uid, paypal_id, None, None, None, tx_id=tx_id, context=context)
+        paypal = acquirer_obj.browse(cr, uid, paypal_id, context=context)
+
+        values = {
+            'acquirer': paypal,
+            'acquirer_form': paypal_form,
+        }
+        return request.website.render("website_payment.index_paypal", values)
+
+    @website.route([
+        '/payment/ogone/test',
+    ], type='http', auth="public")
+    def ogone_test(self, **post):
+        """ TODO
+        """
+        cr, uid, context = request.cr, request.uid, request.context
+        acquirer_obj = request.registry['payment.acquirer']
+        payment_obj = request.registry['payment.transaction']
+        currency_obj = request.registry['res.currency']
+
+        ogone_id = acquirer_obj.search(cr, uid, [('name', '=', 'ogone')], limit=1, context=context)[0]
+        currency_id = currency_obj.search(cr, uid, [('name', '=', 'EUR')], limit=1, context=context)[0]
+
+        nbr_tx = payment_obj.search(cr, uid, [], count=True, context=context)
+        tx_id = payment_obj.create(cr, uid, {
+            'reference': 'test_ref_%s' % (nbr_tx),
+            'amount': 1.95,
+            'currency_id': currency_id,
+            'acquirer_id': ogone_id,
+            'partner_name': 'Norbert Buyer',
+            'partner_email': 'norbert.buyer@example.com',
+            'partner_lang': 'fr_FR',
+        }, context=context)
+
+        ogone_form = acquirer_obj.render(cr, uid, ogone_id, None, None, None, tx_id=tx_id, context=context)
+        ogone = acquirer_obj.browse(cr, uid, ogone_id, context=context)
+
+        values = {
+            'acquirer': ogone,
+            'acquirer_form': ogone_form,
+        }
+        return request.website.render("website_payment.index_ogone", values)
diff --git a/addons/website_payment/static/src/js/payment_acquirer.js b/addons/website_payment/static/src/js/payment_acquirer.js
new file mode 100644 (file)
index 0000000..8955af0
--- /dev/null
@@ -0,0 +1,58 @@
+$(document).ready(function () {
+
+    $('input#cc_number').payment('formatCardNumber');
+    $('input#cc_cvc').payment('formatCardCVC');
+    $('input#cc_expiry').payment('formatCardExpiry')
+
+    $('input#cc_number').on('focusout', function (e) {
+        var valid_value = $.payment.validateCardNumber(this.value);
+        var card_type = $.payment.cardType(this.value);
+        console.log('Validating card', this.value, 'is a', card_type, 'and valid:', valid_value);
+        if (card_type) {
+            $(this).parent('.form-group').children('.card_placeholder').removeClass().addClass('card_placeholder ' + card_type);
+        }
+        else {
+            $(this).parent('.form-group').children('.card_placeholder').removeClass().addClass('card_placeholder');   
+        }
+        if (valid_value) {
+            $(this).parent('.form-group').addClass('has-success');
+            $(this).parent('.form-group').removeClass('has-error');
+        }
+        else {
+            $(this).parent('.form-group').addClass('has-error');
+            $(this).parent('.form-group').removeClass('has-success');
+        }
+    });
+
+    $('input#cc_cvc').on('focusout', function (e) {
+        var cc_nbr = $(this).parents('.oe_cc').find('#cc_number').val();
+        var card_type = $.payment.cardType(cc_nbr);
+        var valid_value = $.payment.validateCardCVC(this.value, card_type);
+        console.log('Validating CVC', this.value, 'for card', cc_nbr, 'of type', card_type, 'and is valid:', valid_value);
+        if (valid_value) {
+            $(this).parent('.form-group').addClass('has-success');
+            $(this).parent('.form-group').removeClass('has-error');
+        }
+        else {
+            $(this).parent('.form-group').addClass('has-error');
+            $(this).parent('.form-group').removeClass('has-success');
+        }
+    });
+
+    $('input#cc_expiry').on('focusout', function (e) {
+        var expiry_value = $.payment.cardExpiryVal(this.value);
+        var month = expiry_value.month || '';
+        var year = expiry_value.year || '';
+        var valid_value = $.payment.validateCardExpiry(month, year);
+        console.log('Validating expiry', this.value, 'month', month, 'year', year, 'and is valid:', valid_value);
+        if (valid_value) {
+            $(this).parent('.form-group').addClass('has-success');
+            $(this).parent('.form-group').removeClass('has-error');
+        }
+        else {
+            $(this).parent('.form-group').addClass('has-error');
+            $(this).parent('.form-group').removeClass('has-success');
+        }
+    });
+
+});
diff --git a/addons/website_payment/static/src/js/website_payment.js b/addons/website_payment/static/src/js/website_payment.js
deleted file mode 100644 (file)
index 8955af0..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-$(document).ready(function () {
-
-    $('input#cc_number').payment('formatCardNumber');
-    $('input#cc_cvc').payment('formatCardCVC');
-    $('input#cc_expiry').payment('formatCardExpiry')
-
-    $('input#cc_number').on('focusout', function (e) {
-        var valid_value = $.payment.validateCardNumber(this.value);
-        var card_type = $.payment.cardType(this.value);
-        console.log('Validating card', this.value, 'is a', card_type, 'and valid:', valid_value);
-        if (card_type) {
-            $(this).parent('.form-group').children('.card_placeholder').removeClass().addClass('card_placeholder ' + card_type);
-        }
-        else {
-            $(this).parent('.form-group').children('.card_placeholder').removeClass().addClass('card_placeholder');   
-        }
-        if (valid_value) {
-            $(this).parent('.form-group').addClass('has-success');
-            $(this).parent('.form-group').removeClass('has-error');
-        }
-        else {
-            $(this).parent('.form-group').addClass('has-error');
-            $(this).parent('.form-group').removeClass('has-success');
-        }
-    });
-
-    $('input#cc_cvc').on('focusout', function (e) {
-        var cc_nbr = $(this).parents('.oe_cc').find('#cc_number').val();
-        var card_type = $.payment.cardType(cc_nbr);
-        var valid_value = $.payment.validateCardCVC(this.value, card_type);
-        console.log('Validating CVC', this.value, 'for card', cc_nbr, 'of type', card_type, 'and is valid:', valid_value);
-        if (valid_value) {
-            $(this).parent('.form-group').addClass('has-success');
-            $(this).parent('.form-group').removeClass('has-error');
-        }
-        else {
-            $(this).parent('.form-group').addClass('has-error');
-            $(this).parent('.form-group').removeClass('has-success');
-        }
-    });
-
-    $('input#cc_expiry').on('focusout', function (e) {
-        var expiry_value = $.payment.cardExpiryVal(this.value);
-        var month = expiry_value.month || '';
-        var year = expiry_value.year || '';
-        var valid_value = $.payment.validateCardExpiry(month, year);
-        console.log('Validating expiry', this.value, 'month', month, 'year', year, 'and is valid:', valid_value);
-        if (valid_value) {
-            $(this).parent('.form-group').addClass('has-success');
-            $(this).parent('.form-group').removeClass('has-error');
-        }
-        else {
-            $(this).parent('.form-group').addClass('has-error');
-            $(this).parent('.form-group').removeClass('has-success');
-        }
-    });
-
-});
diff --git a/addons/website_payment/views/website_payment_templates.xml b/addons/website_payment/views/website_payment_templates.xml
new file mode 100644 (file)
index 0000000..bf6b151
--- /dev/null
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+
+    <!-- Add menus for testing -->
+    <data noupdate="0">
+        <record id="menu_paypal_test" model="website.menu">
+            <field name="name">Paypal (Test)</field>
+            <field name="url">/payment/paypal/test</field>
+            <field name="parent_id" ref="website.main_menu"/>
+            <field name="sequence" type="int">90</field>
+        </record>
+
+        <record id="menu_paypal_ogone" model="website.menu">
+            <field name="name">Ogone (Test)</field>
+            <field name="url">/payment/ogone/test</field>
+            <field name="parent_id" ref="website.main_menu"/>
+            <field name="sequence" type="int">91</field>
+        </record>
+
+        <record id="menu_transfer_test" model="website.menu">
+            <field name="name">Transfer (Test)</field>
+            <field name="url">/payment/transfer/test</field>
+            <field name="parent_id" ref="website.main_menu"/>
+            <field name="sequence" type="int">92</field>
+        </record>
+    </data>
+
+    <!-- Page -->
+    <data>
+        <template id="index_paypal" name="Paypal (Test)" page="True">
+            <t t-call="website.layout">
+                <t t-set="head">
+                    <script type="text/javascript" src="/website_payment/static/src/js/payment_acquirer.js"></script>
+                    <script type="text/javascript" src="/website_payment/static/lib/jquery.payment/jquery.payment.js"></script>
+                    <link rel='stylesheet' href='/website_payment/static/src/css/website_payment.css'/>
+                </t>
+                <div id="wrap">
+                    <div class="container mt16 js_website_blog">
+<!--                         <div class="row">
+                            <h3>Paypal payment: server 2 server</h3>
+                            <form class="form-horizontal col-sm-4 oe_cc" role="form">
+                                <div class="form-group col-sm-8">
+                                    <label class="control-label" for="cc_number">Card number</label>
+                                    <input type="tel" id="cc_number" class="form-control"/>
+                                    <div class="card_placeholder"></div>
+                                    <div class="visa"></div>
+                                </div>
+                                <div class="form-group col-sm-4">
+                                    <label class="control-label" for="cc_cvc">Card code</label>
+                                    <input type="text" id="cc_cvc" class="form-control" maxlength="4" palceholder="CVC"/>
+                                </div>
+                                <div class="form-group col-sm-7">
+                                    <label class="control-label" for="cc_holder_name">Holder Name</label>
+                                    <input type="text" id="cc_hoder_name" class="form-control"/>
+                                </div>
+                                <div class="form-group col-sm-5">
+                                    <label class="control-label" for="cc_expires_mm">Expires</label>
+                                    <input type="text" id="cc_expiry" class="form-control" maxlength="7" placeholder="MM / YY"/>
+                                </div>
+
+                            </form>
+                            
+                        </div> -->
+                        <div>
+                            <h3>Paypal payment: form based</h3>
+                            <t t-raw="acquirer_form"/>
+                        </div>
+                    </div>
+                </div>
+            </t>
+        </template>
+
+        <template id="index_ogone" name="Ogone (Test)" page="True">
+            <t t-call="website.layout">
+                <div id="wrap">
+                    <div class="container mt16 js_website_blog">
+                        <div class="row">
+                            Ogone payment
+                            <t t-raw="acquirer_form"/>
+                        </div>
+                    </div>
+                </div>
+            </t>
+        </template>
+
+        <template id="index_transfer" name="Ogone (Test)" page="True">
+            <t t-call="website.layout">
+                <div id="wrap">
+                    <div class="container mt16 js_website_blog">
+                        <div class="row">
+                            Transfer payment
+                            <t t-raw="acquirer_form"/>
+                        </div>
+                    </div>
+                </div>
+            </t>
+        </template>
+
+    </data>
+</openerp>