From a0fcbd6fbe3c31d8d5cb7250608a0b6ddf4e4798 Mon Sep 17 00:00:00 2001 From: tbe-odoo Date: Thu, 24 Aug 2017 13:48:08 +0200 Subject: [PATCH] [FIX] payment: Some input were not set - e-commerce and website_quote create a transaction with its reference when the user click on Pay. So we need to render the inputs when the user click on pay and submit the form with the values --- addons/payment/static/src/js/payment_form.js | 33 ++++++++++---------- addons/website_quote/controllers/main.py | 12 +++---- addons/website_sale/controllers/main.py | 4 +-- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/addons/payment/static/src/js/payment_form.js b/addons/payment/static/src/js/payment_form.js index 5da7cfbe2ea..b1d503f340d 100644 --- a/addons/payment/static/src/js/payment_form.js +++ b/addons/payment/static/src/js/payment_form.js @@ -86,20 +86,6 @@ odoo.define('payment.payment_form', function (require){ 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 = ''; - // if there's a prepare tx url set if($tx_url.length == 1) { @@ -109,8 +95,20 @@ odoo.define('payment.payment_form', function (require){ '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(); + // TBE: I really don't like how it is designed, but I can't do better with how e-commerce works/ + var ignored_inputs = ['data_set', 'o_payment_form_save_token']; + var html_form = ''; + + // we append the form to the body + var form = $(html_form).appendTo("body"); + // we remove the "unused" inputs + for(var i = 0; i < ignored_inputs.length; i++) { + form.find('input[name="' + ignored_inputs[i] + '"]').remove(); + } + // we submit the form + form.submit(); } else { self.error(_t('Server Error'), @@ -124,7 +122,8 @@ odoo.define('payment.payment_form', function (require){ else { // we append the form to the body and send it. - $(html_form).appendTo("body").submit(); + // $(html_form).appendTo("body").submit(); + this.error(_t("Cannot set-up the payment"), _t("

We're unable to process your payment.

")); } } // if the user is using an old payment diff --git a/addons/website_quote/controllers/main.py b/addons/website_quote/controllers/main.py index 7849d14ccc7..cd87591f2fa 100644 --- a/addons/website_quote/controllers/main.py +++ b/addons/website_quote/controllers/main.py @@ -186,12 +186,12 @@ class sale_quote(http.Controller): }) request.session['quote_%s_transaction_id' % order.id] = tx.id - return True - # return tx.render_sale_button(order, '/quote/%s/%s' % (order_id, token) if token else '/quote/%s' % order_id, - # submit_txt=_('Pay & Confirm'), render_values={ - # 'type': order._get_payment_type(), - # 'alias_usage': _('If we store your payment information on our server, subscription payments will be made automatically.'), - # }) + # return True + return tx.render_sale_button(order, '/quote/%s/%s' % (order_id, token) if token else '/quote/%s' % order_id, + submit_txt=_('Pay & Confirm'), render_values={ + 'type': order._get_payment_type(), + 'alias_usage': _('If we store your payment information on our server, subscription payments will be made automatically.'), + }) @http.route('/quote//transaction/token', type='http', auth='public', website=True) def payment_token(self, order_id, pm_id=None, **kwargs): diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 8893bf5110a..1f9eff5c2c9 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -822,8 +822,8 @@ class WebsiteSale(http.Controller): # if token: # return request.env.ref('website_sale.payment_token_form').render(dict(tx=tx), engine='ir.qweb') - return True - # return tx.render_sale_button(order, '/shop/payment/validate') + # return True + return tx.render_sale_button(order, '/shop/payment/validate') @http.route('/shop/payment/token', type='http', auth='public', website=True) def payment_token(self, pm_id=None, **kwargs):