From 46055085675e2ac4626b65780e50f19f9e44e346 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 10 Oct 2013 16:24:15 +0200 Subject: [PATCH] [ADD] payment_acquirer bzr revid: chm@openerp.com-20131010142415-3dy4chf6kithshtt --- addons/payment_acquirer/__init__.py | 23 ++++++ addons/payment_acquirer/__openerp__.py | 34 ++++++++ .../payment_acquirer/controllers/__init__.py | 1 + addons/payment_acquirer/controllers/main.py | 32 ++++++++ addons/payment_acquirer/payment_acquirer.py | 82 +++++++++++++++++++ .../payment_acquirer_data.xml | 23 ++++++ .../payment_acquirer/views/acquirer_view.xml | 63 ++++++++++++++ 7 files changed, 258 insertions(+) create mode 100644 addons/payment_acquirer/__init__.py create mode 100644 addons/payment_acquirer/__openerp__.py create mode 100644 addons/payment_acquirer/controllers/__init__.py create mode 100644 addons/payment_acquirer/controllers/main.py create mode 100644 addons/payment_acquirer/payment_acquirer.py create mode 100644 addons/payment_acquirer/payment_acquirer_data.xml create mode 100644 addons/payment_acquirer/views/acquirer_view.xml diff --git a/addons/payment_acquirer/__init__.py b/addons/payment_acquirer/__init__.py new file mode 100644 index 00000000000..e5619fd9c83 --- /dev/null +++ b/addons/payment_acquirer/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-Today OpenERP SA (). +# +# 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 . +# +############################################################################## + +import controllers +import payment_acquirer diff --git a/addons/payment_acquirer/__openerp__.py b/addons/payment_acquirer/__openerp__.py new file mode 100644 index 00000000000..0b3aa2e89f0 --- /dev/null +++ b/addons/payment_acquirer/__openerp__.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-Today OpenERP SA (). +# +# 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 . +# +############################################################################## + +{ + 'name': 'Payment acquirer', + 'category': 'Hidden', + 'summary': 'Payment acquirer, display and validate payments', + 'version': '0.1', + 'description': """Payment acquirer module, use to display payment method and validate the payments.""", + 'author': 'OpenERP SA', + 'data': [ + 'views/acquirer_view.xml', + 'payment_acquirer_data.xml', + ], + 'installable': True, +} diff --git a/addons/payment_acquirer/controllers/__init__.py b/addons/payment_acquirer/controllers/__init__.py new file mode 100644 index 00000000000..8ee9bae18d9 --- /dev/null +++ b/addons/payment_acquirer/controllers/__init__.py @@ -0,0 +1 @@ +import main diff --git a/addons/payment_acquirer/controllers/main.py b/addons/payment_acquirer/controllers/main.py new file mode 100644 index 00000000000..d8f7a7d8a98 --- /dev/null +++ b/addons/payment_acquirer/controllers/main.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-Today OpenERP SA (). +# +# 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 . +# +############################################################################## + +from openerp import SUPERUSER_ID +from openerp.addons.web import http +from openerp.addons.web.http import request +from openerp.addons.website.models import website + + +class PaymentAcquirer(http.Controller): + + @website.route(['/payment_acquirer/'], type='json', auth="public") + def payment_acquirer(self, **post): + return False diff --git a/addons/payment_acquirer/payment_acquirer.py b/addons/payment_acquirer/payment_acquirer.py new file mode 100644 index 00000000000..455b0270d7f --- /dev/null +++ b/addons/payment_acquirer/payment_acquirer.py @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013-Today OpenERP SA (). +# +# 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 . +# +############################################################################## + +import openerp +from openerp.osv import osv, fields +from openerp.tools import float_repr + + +class type(osv.Model): + _name = 'payment.acquirer.type' + _columns = { + 'name': fields.char('Name', required=True), + } + + +class acquirer(osv.Model): + _name = 'payment.acquirer' + _description = 'Online Payment Acquirer' + + _columns = { + 'name': fields.char('Name', required=True), + 'type_id': fields.many2one('payment.acquirer.type', required=True), + 'form_template_id': fields.many2one('ir.ui.view', translate=True, required=True), + 'visible': fields.boolean('Visible', help="Make this payment acquirer available (Customer invoices, etc.)"), + } + + _defaults = { + 'visible': True, + } + + def render(self, cr, uid, ids, object, reference, currency, amount, context=None): + """ Renders the form template of the given acquirer as a qWeb template """ + view = self.pool.get("ir.ui.view") + user = self.pool.get("res.users") + precision = self.pool.get("decimal.precision").precision_get(cr, uid, 'Account') + + qweb_context = {} + qweb_context.update( + object=object, + reference=reference, + currency=currency, + amount=amount, + amount_str=float_repr(amount, precision), + user_id=user.browse(cr, uid, uid), + context=context + ) + + res = [] + for pay in self.browse(cr, uid, ids, context=context): + res[pay.id] = view.render(cr, uid, pay.form_template_id.id, qweb_context.copy(), context=context) + return res + + def validate_payement(self, cr, uid, ids, object, reference, currency, amount, context=None): + res = [] + for pay in self.browse(cr, uid, ids, context=context): + method = getattr(self, '_validate_payement_%s' % pay.type_id.name) + res[pay.id] = method(cr, uid, ids, object, reference, currency, amount, context=context) + return res + + def _validate_payement_paypal(self, cr, uid, ids, object, reference, currency, amount, context=None): + payment = "pending" # "validated" or "refused" or "pending" + retry_time = False + + return (payment, retry_time) \ No newline at end of file diff --git a/addons/payment_acquirer/payment_acquirer_data.xml b/addons/payment_acquirer/payment_acquirer_data.xml new file mode 100644 index 00000000000..6e842cab45d --- /dev/null +++ b/addons/payment_acquirer/payment_acquirer_data.xml @@ -0,0 +1,23 @@ + + + + + paypal + + + + Paypal + +
+ + + + + + +
+
+ +
+
+
diff --git a/addons/payment_acquirer/views/acquirer_view.xml b/addons/payment_acquirer/views/acquirer_view.xml new file mode 100644 index 00000000000..b6f783f82ec --- /dev/null +++ b/addons/payment_acquirer/views/acquirer_view.xml @@ -0,0 +1,63 @@ + + + + + payment.acquirer + +
+ +
+
+ +
+

+ This is an HTML form template to submit a payment through this acquirer. + The template will be rendered with qWeb, so it may use qWeb expressions. + The qWeb evaluation context provides: +

    +
  • reference: the reference number of the document to pay
  • +
  • currency: the currency record in which the document is issued (e.g. currency.name could be EUR)
  • +
  • amount: the total amount to pay, as a float
  • +
  • amount_str: the total amount to pay, as a string with the account precision
  • +
  • object: the browse record on which the payment form is rendered (usually an invoice or sales order record)
  • +
  • user_id: the current user browse record
  • +
  • context: the current context dictionary
  • +
+ If the template renders to an empty result in a certain context it will be ignored, as if it was inactive. +

+
+ +
+
+
+
+
+ + payment.acquirer + + + + + + + + + portal.payment.acquirer + + + + + + + + + + Payment Acquirers + payment.acquirer + + + +
+