[ADD] payment_acquirer
bzr revid: chm@openerp.com-20131010142415-3dy4chf6kithshtt
This commit is contained in:
parent
672a76a002
commit
4605508567
|
@ -0,0 +1,23 @@
|
|||
# -*- 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import controllers
|
||||
import payment_acquirer
|
|
@ -0,0 +1,34 @@
|
|||
# -*- 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 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,
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
import main
|
|
@ -0,0 +1,32 @@
|
|||
# -*- 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 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
|
|
@ -0,0 +1,82 @@
|
|||
# -*- 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
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)
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data noupdate="1">
|
||||
<record id="paypal" model="payment.acquirer.type">
|
||||
<field name="name">paypal</field>
|
||||
</record>
|
||||
|
||||
<record id="paypal_acquirer" model="payment.acquirer">
|
||||
<field name="name">Paypal</field>
|
||||
<field name="form_template">
|
||||
<form t-if="object.company_id.paypal_account" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
|
||||
<input type="hidden" name="cmd" value="_xclick"/>
|
||||
<input type="hidden" name="business" t-att-value="object.company_id.paypal_account}"/>
|
||||
<input type="hidden" name="item_name" t-attf-value="#{object.company_id.name} #{kind.title()} #{reference}"/>
|
||||
<input type="hidden" name="amount" t-att-value="amount"/>
|
||||
<input type="hidden" name="currency_code" t-att-value="currency.name"/>
|
||||
<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif"/>
|
||||
</form>
|
||||
</field>
|
||||
<field name="type_id" ref="payment_acquirer.paypal"/>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
|
@ -0,0 +1,63 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="acquirer_form" model="ir.ui.view">
|
||||
<field name="model">payment.acquirer</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Payment Acquirer" version="7.0">
|
||||
<group col="1">
|
||||
<div class="oe_title">
|
||||
<label for="name" class="oe_edit_only"/><h1><field name="name"/></h1>
|
||||
<div class="oe_edit_only"><field name="visible"/><label for="visible"/></div>
|
||||
</div>
|
||||
<group string="Form Template">
|
||||
<div>
|
||||
<p>
|
||||
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:
|
||||
<ul>
|
||||
<li>reference: the reference number of the document to pay</li>
|
||||
<li>currency: the currency record in which the document is issued (e.g. currency.name could be EUR)</li>
|
||||
<li>amount: the total amount to pay, as a float</li>
|
||||
<li>amount_str: the total amount to pay, as a string with the account precision</li>
|
||||
<li>object: the browse record on which the payment form is rendered (usually an invoice or sales order record)</li>
|
||||
<li>user_id: the current user browse record</li>
|
||||
<li>context: the current context dictionary</li>
|
||||
</ul>
|
||||
If the template renders to an empty result in a certain context it will be ignored, as if it was inactive.
|
||||
</p>
|
||||
</div>
|
||||
<field name="form_template" nolabel="1" colspan="2"/>
|
||||
</group>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<record id="acquirer_list" model="ir.ui.view">
|
||||
<field name="model">payment.acquirer</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Payment Acquirers">
|
||||
<field name="name"/>
|
||||
<field name="visible"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
<record id="acquirer_search" model="ir.ui.view">
|
||||
<field name="model">portal.payment.acquirer</field>
|
||||
<field name="arch" type="xml">
|
||||
<search>
|
||||
<field name="name"/>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Acquirers list action is visible in Invoicing Settings -->
|
||||
<record model="ir.actions.act_window" id="action_acquirer_list">
|
||||
<field name="name">Payment Acquirers</field>
|
||||
<field name="res_model">payment.acquirer</field>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
Loading…
Reference in New Issue