diff --git a/addons/payment/controllers/portal.py b/addons/payment/controllers/portal.py index dc402446ea3..9d06665d021 100644 --- a/addons/payment/controllers/portal.py +++ b/addons/payment/controllers/portal.py @@ -8,7 +8,7 @@ from odoo.http import request class WebsitePayment(http.Controller): @http.route(['/my/payment_method'], type='http', auth="user", website=True) def payment_method(self, **kwargs): - acquirers = list(request.env['payment.acquirer'].search([('website_published', '=', True), ('registration_view_template_id', '!=', False)])) + acquirers = list(request.env['payment.acquirer'].search([('website_published', '=', True), ('registration_view_template_id', '!=', False), ('prefered_payment_type', 'in', ['s2s', 'both'])])) partner = request.env.user.partner_id payment_tokens = partner.payment_token_ids payment_tokens |= partner.commercial_partner_id.sudo().payment_token_ids diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index 325f58c3aff..365e8d14b37 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -151,6 +151,15 @@ class PaymentAcquirer(models.Model): "Use this field anywhere a small image is required.") payment_option_ids = fields.Many2many('payment.option', string='Supported Payment Option') + prefered_payment_type = fields.Selection(selection=[('s2s','Server to server'), + ('form', 'Form'), + ('both', 'Both') + ], default='form', required=True, string='Prefered payment type', help="""Which payment type you wish to use. + - Form: Redirect the user to the payment acquirer website to pay. + - Server to server: The user enter his credit card information on your website and is processed by Odoo. + - Both: Both are displayed to the user. + + Note: Subscriptions does not take this field in account, it uses server to server by default.""") def _search_is_tokenized(self, operator, value): tokenized = self._get_feature_support()['tokenize'] diff --git a/addons/payment/static/src/js/payment_form.js b/addons/payment/static/src/js/payment_form.js index bf8f490a493..5da7cfbe2ea 100644 --- a/addons/payment/static/src/js/payment_form.js +++ b/addons/payment/static/src/js/payment_form.js @@ -77,23 +77,55 @@ odoo.define('payment.payment_form', function (require){ // if the user is going to pay with a form payment, then else if(this.isFormPaymentRadio(checked_radio)) { + var self = this; // we retrieve the acquirer id and its form var acquirer_id = this.getAcquirerIdFromRadio(checked_radio); var acquirer_form = this.$('#o_payment_form_acq_' + acquirer_id); var inputs_form = $('input', acquirer_form); var ds = $('input[name="data_set"]', acquirer_form)[0]; + var form_save_token = false; + var $tx_url = this.$el.find('input[name="prepare_tx_url"]'); // Here we take the values we need to send to the acquirer and generate a form with them var html_form = '
'; - // we append the form to the body and send it. - $(html_form).appendTo("body").submit(); + + // if there's a prepare tx url set + if($tx_url.length == 1) + { + // then we call the route to prepare the transaction + ajax.jsonRpc($tx_url[0].value, 'call', { + 'acquirer_id': parseInt(acquirer_id), + 'save_token': form_save_token + }).then(function(result){ + if(result) { + // we append the form to the body and send it. + $(html_form).appendTo("body").submit(); + } + else { + self.error(_t('Server Error'), + _t("We are not able to redirect you to the payment form.
")); + } + }).fail(function(message, data){ + self.error(_t('Server Error'), + _t("We are not able to redirect you to the payment form.
") + (core.debug ? data.data.message : '')); + }); + } + else + { + // we append the form to the body and send it. + $(html_form).appendTo("body").submit(); + } } // if the user is using an old payment else { diff --git a/addons/payment/static/src/js/payment_transaction.js b/addons/payment/static/src/js/payment_transaction.js deleted file mode 100644 index eb945f7a220..00000000000 --- a/addons/payment/static/src/js/payment_transaction.js +++ /dev/null @@ -1,81 +0,0 @@ -odoo.define('payment.transaction', function (require) { -"use strict"; - -var ajax = require('web.ajax'); - -$(document).ready(function () { - // When choosing an acquirer, display its Pay Now button - var $payment = $("#payment_method"); - $payment.on("click", "input[name='acquirer'], a.btn_payment_token", function (ev) { - var ico_off = 'fa-circle-o'; - var ico_on = 'fa-dot-circle-o'; - - var payment_id = $(ev.currentTarget).val() || $(this).data('acquirer'); - var token = $(ev.currentTarget).data('token') || ''; - - $("div.o_payment_acquirer_button[data-id='"+payment_id+"']", $payment).attr('data-token', token); - $("div.js_payment a.list-group-item").removeClass("list-group-item-info"); - $('span.js_radio').switchClass(ico_on, ico_off, 0); - if (token) { - $("div.o_payment_acquirer_button div.token_hide").hide(); - $(ev.currentTarget).find('span.js_radio').switchClass(ico_off, ico_on, 0); - $(ev.currentTarget).parents('li').find('input').prop("checked", true); - $(ev.currentTarget).addClass("list-group-item-info"); - } - else{ - $("div.o_payment_acquirer_button div.token_hide").show(); - } - $("div.o_payment_acquirer_button[data-id]", $payment).addClass("hidden"); - $("div.o_payment_acquirer_button[data-id='"+payment_id+"']", $payment).removeClass("hidden"); - - }) - .find("input[name='acquirer']:checked").click(); - - // When clicking on payment button: create the tx using json then continue to the acquirer - $payment.on("click", 'button[type="submit"], button[name="submit"]', function (ev) { - ev.preventDefault(); - ev.stopPropagation(); - var $form = $(ev.currentTarget).parents('form'); - var acquirer = $(ev.currentTarget).parents('div.o_payment_acquirer_button').first(); - var tx_data = acquirer.data(); - if (! tx_data.id || ! tx_data.callUrl) { - return false; - } - - var params = {"tx_type": tx_data.txType || acquirer.find('input[name="odoo_save_token"]').is(':checked') ? 'form_save': 'form'}; - var acquirer_token = acquirer.attr('data-token'); // !=data - if (acquirer_token) { - params.token = acquirer_token; - } - if (tx_data.access_token) { - params.access_token = tx_data.access_token; - } - $form.off('submit'); - ajax.jsonRpc(tx_data.callUrl, 'call', params).then(function (data) { - $(data).appendTo('body').submit(); - }); - return false; - }); - - $('div.oe_pay_token').on('click', 'a.js_btn_valid_tx', function() { - $('div.js_token_load').toggle(); - - var $form = $(this).parents('form'); - ajax.jsonRpc($form.attr('action'), 'call', $.deparam($form.serialize())).then(function (data) { - if (data.url) { - window.location = data.url; - } - else { - $('div.js_token_load').toggle(); - if (!data.success && data.error) { - $('div.oe_pay_token div.panel-body p').html(data.error + "