diff options
| author | Thibault Delavallée <tde@odoo.com> | 2017-09-01 11:47:55 +0200 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2017-09-06 10:40:46 +0200 |
| commit | 06fe263a150f42ec36c91e6219fdc8f19fd50798 (patch) | |
| tree | c8225ac4e7bd52273ec4346b1f11539eb4839a61 /addons/payment/static | |
| parent | faea6583820bd78dac330915cef0016969af5bbb (diff) | |
[IMP] payment: add new explicit parameters to the payment widget
Purpose of this commit is to ease the use of the payment widget and
avoid having to perform too much custom code in the various routes used
when doing payments :
* when instantiating the widget give him its parent element data so
that parameters given when calling the payment form template are
automatically present in the widget options;
* support more parameters when calling the route for form-based acquirers
including access_token, URLs and callback method;
* when doing a form-based payment a call to a JSON route returning the
rendered form is done. Payment widget now uses all data from that
form including the URL of the acquirer website. This way form-based
acquirers are really dynamic and values update is easier;
* remove hidden display of form-based acquirers as all data come now
from the called JSON route that returns the form;
* add a warning about partner-id not being set as it is an issue some
people may encounter;
Diffstat (limited to 'addons/payment/static')
| -rw-r--r-- | addons/payment/static/src/js/payment_form.js | 33 |
1 files changed, 21 insertions, 12 deletions
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); + }); + }); |
