diff options
| author | tbe-odoo <tbe@odoo.com> | 2017-08-21 17:17:26 +0200 |
|---|---|---|
| committer | tbe-odoo <tbe@odoo.com> | 2017-08-24 11:20:14 +0200 |
| commit | ffcd95aaa99e9d76bb234da9845f00b7cb2fcbc4 (patch) | |
| tree | cbcd69b23c958e1a87cef5d62e891abf973d49ae /addons/payment | |
| parent | fc17776f31f8e16e78d9383248e371f65b947d56 (diff) | |
[IMP] website_sale: Added S2S payment with new payment form
- Added the support of form payment.
- Fixed payment form's errors not being displayed.
- Fixed a crash when paying on e-commerce with a saved token.
(dev commit, need to clean the code)
Diffstat (limited to 'addons/payment')
| -rw-r--r-- | addons/payment/security/ir.model.access.csv | 3 | ||||
| -rw-r--r-- | addons/payment/static/src/js/payment_form.js | 72 | ||||
| -rw-r--r-- | addons/payment/views/payment_portal_templates.xml | 1 | ||||
| -rw-r--r-- | addons/payment/views/payment_templates.xml | 34 |
4 files changed, 86 insertions, 24 deletions
diff --git a/addons/payment/security/ir.model.access.csv b/addons/payment/security/ir.model.access.csv index 2bfa46839a0..f1d86956349 100644 --- a/addons/payment/security/ir.model.access.csv +++ b/addons/payment/security/ir.model.access.csv @@ -9,3 +9,6 @@ payment_method_all,payment.token.all,model_payment_token,,1,0,0,0 payment_method_user,payment.token.user,model_payment_token,base.group_user,1,1,1,1 payment_method_portal,payment.token.portal,model_payment_token,base.group_portal,1,1,1,1 payment_method_system,payment.token.system,model_payment_token,base.group_system,1,1,1,1 +payment_option_all,payment.option.all,model_payment_option,,1,0,0,0 +payment_option_user,payment.option.user,model_payment_option,base.group_user,1,1,1,0 +payment_option_system,payment.option.system,model_payment_option,base.group_system,1,1,1,1
\ No newline at end of file diff --git a/addons/payment/static/src/js/payment_form.js b/addons/payment/static/src/js/payment_form.js index ae2d44c1cb7..bf8f490a493 100644 --- a/addons/payment/static/src/js/payment_form.js +++ b/addons/payment/static/src/js/payment_form.js @@ -59,7 +59,7 @@ odoo.define('payment.payment_form', function (require){ } // if the server has returned false, we display an error else { - self.error(_t('Error'), + self.error(_t('Server Error'), _t("<p>We are not able to add your payment method at the moment.</p>")); } // here we remove the 'processing' icon from the 'add a new payment' button @@ -70,10 +70,31 @@ odoo.define('payment.payment_form', function (require){ $(button).attr('disabled', false); $(button).find('span.o_loader').remove(); - self.error(_t('Error'), + self.error(_t('Server Error'), _t("<p>We are not able to add your payment method at the moment.</p>") + (core.debug ? data.data.message : '')); }); } + // if the user is going to pay with a form payment, then + else if(this.isFormPaymentRadio(checked_radio)) + { + // 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]; + + // 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">'; + + for(var i = 0; i < inputs_form.length; i ++) { + if(inputs_form[i].name != "data_set") { + html_form +='<input name="' + inputs_form[i].name + '" value="' + inputs_form[i].value + '"/>'; + } + } + html_form += '</form>'; + // we append the form to the body and send it. + $(html_form).appendTo("body").submit(); + } // if the user is using an old payment else { // then we just submit the form @@ -81,8 +102,8 @@ odoo.define('payment.payment_form', function (require){ } } else { - this.error(_t('Error'), - _t('<p>Please select a payment method</p>')); + this.error(_t('No payment method selected'), + _t('<p>Please select a payment method.</p>')); } }, // event handler when clicking on the button to add a new payment method @@ -132,7 +153,7 @@ odoo.define('payment.payment_form', function (require){ } // if the server has returned false, we display an error else { - self.error(_t('Error'), + self.error(_t('Server Error'), _t("<p>We are not able to add your payment method at the moment.</p>")); } // here we remove the 'processing' icon from the 'add a new payment' button @@ -143,13 +164,13 @@ odoo.define('payment.payment_form', function (require){ $(button).attr('disabled', false); $(button).find('span.o_loader').remove(); - self.error(_t('Error'), + self.error(_t('Server error'), _t("<p>We are not able to add your payment method at the moment.</p>") + (core.debug ? data.data.message : '')); }); } else { - this.error(_t('Error'), - _t('<p>Please select the option to add a new payment method</p>')); + this.error(_t('No payment method selected'), + _t('<p>Please select the option to add a new payment method.</p>')); } }, // event handler when clicking on a button to delete a payment method @@ -170,7 +191,7 @@ odoo.define('payment.payment_form', function (require){ ev.target.closest('div').remove(); } },function(type,err){ - self.error(_t('Error'), + self.error(_t('Server Error'), _t("<p>We are not able to delete your payment method at the moment.</p>")); }); }; @@ -202,7 +223,7 @@ odoo.define('payment.payment_form', function (require){ Delete(); } }, function(type, err){ - self.error(_t('Error'), + self.error(_t('Server Error'), _t("<p>We are not able to delete your payment method at the moment.</p>") + (core.debug ? err.data.message : '')); }); }, @@ -215,28 +236,43 @@ odoo.define('payment.payment_form', function (require){ var checked_radio = this.$('input[type="radio"]:checked'); // we hide all the acquirers form this.$('[id*="o_payment_add_token_acq_"]').addClass('hidden'); + this.$('[id*="o_payment_form_acq_"]').addClass('hidden'); + if(checked_radio.length != 1) { + return; + } + checked_radio = checked_radio[0]; // if we clicked on an add new payment radio - if(checked_radio.length == 1 && this.isNewPaymentRadio(checked_radio[0])) + if(this.isNewPaymentRadio(checked_radio)) { // then we retrieve the acquirer name - var acquirer_id = this.getAcquirerIdFromRadio(checked_radio[0]); + var acquirer_id = this.getAcquirerIdFromRadio(checked_radio); // and display its form this.$('#o_payment_add_token_acq_' + acquirer_id).removeClass('hidden'); } + else if(this.isFormPaymentRadio(checked_radio)) + { + // then we retrieve the acquirer name + var acquirer_id = this.getAcquirerIdFromRadio(checked_radio); + // and display its form + this.$('#o_payment_form_acq_' + acquirer_id).removeClass('hidden'); + } }, isNewPaymentRadio: function(element) { - return $(element).data('acquirer-id') !== undefined; + return $(element).data('s2s-payment') === 'True'; + }, + isFormPaymentRadio: function(element) { + return $(element).data('form-payment') === 'True'; }, getAcquirerIdFromRadio: function(element) { return $(element).data('acquirer-id'); }, error: function(title, message, url) { return new Dialog(null, { - title: title || "", - $content: $(core.qweb.render('website.error_dialog', { - message: message || "", - })), - }).open(); + title: _t('Error: ') + title, + size: 'medium', + $content: message || "", + buttons: [ + {text: _t('Ok'), close: true}]}).open(); }, getFormData: function($form){ var unindexed_array = $form.serializeArray(); diff --git a/addons/payment/views/payment_portal_templates.xml b/addons/payment/views/payment_portal_templates.xml index 3c8a5e3f5d3..f599329e5e1 100644 --- a/addons/payment/views/payment_portal_templates.xml +++ b/addons/payment/views/payment_portal_templates.xml @@ -19,6 +19,7 @@ <div class="col-sm-8"> <h3>Manage your Payment Methods</h3> <t t-call="payment.payment_tokens_list"> + <t t-set="s2s_acquirers" t-value="acquirers"/> <t t-set="mode" t-value="'manage'"/> <t t-set="verify_validity" t-value="True"/> </t> diff --git a/addons/payment/views/payment_templates.xml b/addons/payment/views/payment_templates.xml index ae9a1501632..57bdae3b1c0 100644 --- a/addons/payment/views/payment_templates.xml +++ b/addons/payment/views/payment_templates.xml @@ -17,31 +17,53 @@ - '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' display a form that is used to pay and send the information to the form action url. - - 'acquirers' the list of the acquirers + - 's2s_acquirers' the list of the server2server acquirers + - 'form_acquirers' the list of the payment acquirers to pay with forms - 'verify_validity' if we need to verify if the payment method is valid when adding a new one --> - <form method="post" t-att-action="form_action if form_action else '#'" class="o_payment_form"> + <form t-if="s2s_acquirers or pms or form_acquirers" method="post" t-att-action="form_action if form_action else '#'" class="o_payment_form"> <input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/> <input type="hidden" t-if="verify_validity==True" name="verify_validity" value="1"/> <div class="panel panel-default"> - <t t-foreach="acquirers" t-as="acq"> + <t t-foreach="s2s_acquirers" t-as="acq"> <div class="panel-body"> <label> <t t-if="mode == 'manage'"> - <input type="radio" t-att-data-acquirer-id="acq.id" name="pm_id" t-attf-value="new_{{acq.id}}" t-att-class="'hidden' if (len(acquirers)==1) else ''" t-att-checked="len(acquirers) == 1"/> + <input type="radio" t-att-data-acquirer-id="acq.id" t-att-data-s2s-payment="true" name="pm_id" t-attf-value="new_{{acq.id}}" t-att-class="'hidden' if (len(s2s_acquirers)==1) else ''" t-att-checked="len(s2s_acquirers) == 1"/> </t> <t t-else=""> - <input type="radio" t-att-data-acquirer-id="acq.id" name="pm_id" t-attf-value="new_{{acq.id}}" t-att-class="'hidden' if (len(acquirers)==1 and len(pms)==0) else ''" t-att-checked="len(acquirers)==1 and len(pms)==0"/> + <input type="radio" t-att-data-acquirer-id="acq.id" t-att-data-s2s-payment="true" name="pm_id" t-attf-value="new_{{acq.id}}" t-att-class="'hidden' if (len(s2s_acquirers)==1 and len(pms)==0) else ''" t-att-checked="len(s2s_acquirers)==1 and len(pms)==0"/> </t> <t t-esc="acq.name"/> </label> + <ul class="pull-right list-inline"> + <t t-foreach="acq.payment_option_ids" t-as="pm_option"> + <li> + <span t-field="pm_option.image_small" + t-options='{"widget": "image", "alt-field": "name"}' /> + </li> + </t> + </ul> </div> - <div t-attf-id="o_payment_add_token_acq_{{acq.id}}" t-attf-class="panel-footer {{'hidden' if (len(acquirers)>1 and len(pms)==0 and acquirers[0]!=acq) else 'hidden' if len(pms)>0 else ''}}"> + <div t-attf-id="o_payment_add_token_acq_{{acq.id}}" t-attf-class="panel-footer {{'hidden' if (len(s2s_acquirers)>1 and len(pms)==0 and s2s_acquirers[0]!=acq) else 'hidden' if len(pms)>0 else ''}}"> <div class="clearfix"> <t t-raw="acq.form" t-att-data-acquirer-id="acquirer.id"/> </div> </div> </t> + <t tif="mode == 'payment'" t-foreach="form_acquirers" t-as="acq"> + <div class="panel-body"> + <label> + <!-- TBE TODO: Tout le schmilblick du hidden et checked (pareil pour le s2s juste au dessus) --> + <input type="radio" t-att-data-acquirer-id="acq.id" t-att-data-form-payment="true" name="pm_id" t-attf-value="form_{{acq.id}}"/> + <t t-esc="acq.name"/> + </label> + </div> + <div t-attf-id="o_payment_form_acq_{{acq.id}}" class="panel-footer hidden"> + You'll be redirected to the <t t-esc="acq.provider"/> website after clicking on the payment button. + <t t-raw="acq.form"/> + </div> + </t> <t t-foreach="pms" t-as="pm"> <div class="panel-body"> <label> |
