[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
This commit is contained in:
tbe-odoo
2017-08-24 13:48:08 +02:00
parent ba739fcd8f
commit a0fcbd6fbe
3 changed files with 24 additions and 25 deletions
+16 -17
View File
@@ -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 = '<form method="post" action="' + ds.dataset.actionUrl + '" class="hidden">';
var ignored_inputs = ['data_set', 'o_payment_form_save_token'];
for(var i = 0; i < inputs_form.length; i ++) {
if(ignored_inputs.indexOf(inputs_form[i].name) == -1) {
html_form +='<input name="' + inputs_form[i].name + '" value="' + inputs_form[i].value + '"/>';
}
else if(inputs_form[i].name == 'o_payment_form_save_token') {
form_save_token = inputs_form[i].checked;
}
}
html_form += '</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 = '<form method="post" action="'
+ ds.dataset.actionUrl + '" class="hidden">'
+ result + '</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("<p>We're unable to process your payment.</p>"));
}
}
// if the user is using an old payment
+6 -6
View File
@@ -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/<int:order_id>/transaction/token', type='http', auth='public', website=True)
def payment_token(self, order_id, pm_id=None, **kwargs):
+2 -2
View File
@@ -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):