diff --git a/addons/payment/static/src/js/payment_form.js b/addons/payment/static/src/js/payment_form.js index d2dd252f442..1cd09b04689 100644 --- a/addons/payment/static/src/js/payment_form.js +++ b/addons/payment/static/src/js/payment_form.js @@ -17,10 +17,15 @@ odoo.define('payment.payment_form', function (require) { 'click input[type="radio"]': 'radioClickEvent' }, + init: function(parent, options) { + this._super.apply(this, arguments); + this.options = _.extend(options || {}, { + }); + }, + start: function () { this.updateNewPaymentDisplayStatus(); $('[data-toggle="tooltip"]').tooltip(); - }, payEvent: function (ev) { @@ -47,6 +52,9 @@ odoo.define('payment.payment_form', function (require) { // if the user is adding a new payment if (this.isNewPaymentRadio(checked_radio)) { + if (this.options.partnerId === undefined) { + console.warn('payment_form: unset partner_id when adding new token; things could go wrong'); + } var form_data = this.getFormData(inputs_form); var empty_inputs = false; @@ -115,12 +123,6 @@ 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)) { - // if neither the dataset or the action url is defined, then we just stop the execution of the function - if (!ds || !ds.dataset.actionUrl) { - console.warn('payment_form: invalid dataset / actionurl'); - return; - } - var $tx_url = this.$el.find('input[name="prepare_tx_url"]'); // if there's a prepare tx url set if ($tx_url.length === 1) { @@ -130,14 +132,19 @@ odoo.define('payment.payment_form', function (require) { ajax.jsonRpc($tx_url[0].value, 'call', { 'acquirer_id': parseInt(acquirer_id), 'save_token': form_save_token, + 'access_token': self.options.accessToken, + 'success_url': self.options.successUrl, + 'error_url': self.options.errorUrl, + 'callback_method': self.options.callbackMethod, }).then(function (result) { if (result) { // if the server sent us the html form, we create a form element var newForm = document.createElement('form'); newForm.setAttribute("method", "post"); // set it to post - newForm.setAttribute("action", ds.dataset.actionUrl); // set the action url newForm.hidden = true; // hide it newForm.innerHTML = result; // put the html sent by the server inside the form + var action_url = $(newForm).find('input[name="data_set"]').data('actionUrl'); + newForm.setAttribute("action", action_url); // set the action url document.getElementsByTagName('body')[0].appendChild(newForm); // append the form to the body $(newForm).find('input[data-remove-me]').remove(); // remove all the input that should be removed newForm.submit(); // and finally submit the form @@ -379,13 +386,15 @@ odoo.define('payment.payment_form', function (require) { }, }); - - require('web.dom_ready'); // only start this when dom is ready if (!$('.o_payment_form').length) { return $.Deferred().reject("DOM doesn't contain '.o_payment_form'"); } - var form = new PaymentForm(); - form.attachTo($('.o_payment_form')); + $('.o_payment_form').each(function () { + var $elem = $(this); + var form = new PaymentForm(null, $elem.data()); + form.attachTo($elem); + }); + }); diff --git a/addons/payment/views/payment_templates.xml b/addons/payment/views/payment_templates.xml index 81e73aa464b..446d248680f 100644 --- a/addons/payment/views/payment_templates.xml +++ b/addons/payment/views/payment_templates.xml @@ -12,7 +12,7 @@ - 'submit_txt' the text displayed inside the submit button - 'submit_class' the css classes to style the submit button - 'icon_class' font awesome class (e.g. 'fa-trash', 'fa-lock') - - 'form_action' the URI to the page that will handle the form values + - 'form_action' the URI to the page that will handle the form values given for server2server - 'pms' the tokens - 'checked_pm_id' the payment token that should be checked (for radio buttons) - 'mode' can take two values, either 'payment' or 'manage'. 'manage' displays the add a new card and delete buttons. 'payment' @@ -22,10 +22,22 @@ - 'verify_validity' if we need to verify if the payment method is valid when adding a new one - 'prepare_tx_url' the url of the route which will handle the creation of a transaction for a form base payment (handles if the transaction is form or form_save) --> -
+ + + + + + +
@@ -69,7 +81,9 @@
- + + +
@@ -103,7 +117,6 @@
-