From 378f4cdfec1c60e8af2730493fc9d9e6a5470751 Mon Sep 17 00:00:00 2001 From: tbe-odoo Date: Mon, 7 Aug 2017 14:35:14 +0200 Subject: [PATCH 01/20] [IMP] payment: Supported payment options - Added the ability to specify which payment option each payment acquirer supports and, displays those payment option on e-commerce footer. --- addons/payment/models/payment_acquirer.py | 31 ++++++++++++++ addons/payment/views/payment_views.xml | 40 +++++++++++++++++++ addons/website_payment/models/website.py | 7 +++- .../views/website_payment_templates.xml | 8 ++-- 4 files changed, 80 insertions(+), 6 deletions(-) diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index 623676c7a9c..c6b220ceffb 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -150,6 +150,8 @@ class PaymentAcquirer(models.Model): "resized as a 64x64px image, with aspect ratio preserved. " "Use this field anywhere a small image is required.") + payment_option_ids = fields.Many2many('payment.option', string='Supported Payment Option') + def _search_is_tokenized(self, operator, value): tokenized = self._get_feature_support()['tokenize'] if (operator, value) in [('=', True), ('!=', False)]: @@ -394,6 +396,35 @@ class PaymentAcquirer(models.Model): 'context': context, } +class PaymentOption(models.Model): + _name = 'payment.option' + _description = 'Payment Option' + + name = fields.Char(string='Name') + acquirer_ids = fields.Many2many('payment.acquirer', string="Acquirers", help="List of Acquirers supporting this payment option.") + image = fields.Binary( + "Image", attachment=True, + help="This field holds the image used for this payment option, limited to 1024x1024px") + image_medium = fields.Binary( + "Medium-sized image", attachment=True, + help="Medium-sized image of this payment option. It is automatically " + "resized as a 128x128px image, with aspect ratio preserved. " + "Use this field in form views or some kanban views.") + image_small = fields.Binary( + "Small-sized image", attachment=True, + help="Small-sized image of this payment option. It is automatically " + "resized as a 64x64px image, with aspect ratio preserved. " + "Use this field anywhere a small image is required.") + + @api.model + def create(self, vals): + image_resize_images(vals) + return super(PaymentOption, self).create(vals) + + @api.multi + def write(self, vals): + image_resize_images(vals) + return super(PaymentOption, self).write(vals) class PaymentTransaction(models.Model): """ Transaction Model. Each specific acquirer can extend the model by adding diff --git a/addons/payment/views/payment_views.xml b/addons/payment/views/payment_views.xml index c626657bc42..6b67db74ec6 100644 --- a/addons/payment/views/payment_views.xml +++ b/addons/payment/views/payment_views.xml @@ -112,6 +112,7 @@ + @@ -376,5 +377,44 @@ parent='root_payment_menu' groups='base.group_no_one'/> + + + payment.option.form + payment.option + +
+ + +
+

+
+ + + + + + + +
+
+
+
+ + + Payment Options + payment.option + form + tree,form + +

+ Click to create a payment acquirer. +

+
+
+ + diff --git a/addons/website_payment/models/website.py b/addons/website_payment/models/website.py index 540277d79c2..0bb533cd1c9 100644 --- a/addons/website_payment/models/website.py +++ b/addons/website_payment/models/website.py @@ -8,5 +8,8 @@ class Website(models.Model): _inherit = "website" @api.model - def payment_acquirers(self): - return list(self.env['payment.acquirer'].sudo().search([('website_published', '=', True)])) + def payment_options(self): + """ This function returns the list of payment options which are supported by payment acquirers that are published + """ + options = self.env['payment.option'].sudo().search([('acquirer_ids', '!=', False)]) + return [opt for opt in options if any(acq.website_published for acq in opt.acquirer_ids)] diff --git a/addons/website_payment/views/website_payment_templates.xml b/addons/website_payment/views/website_payment_templates.xml index c49937bb83f..95d5d44cbf2 100644 --- a/addons/website_payment/views/website_payment_templates.xml +++ b/addons/website_payment/views/website_payment_templates.xml @@ -1,12 +1,12 @@ - + + + - - diff --git a/addons/payment_transfer/views/payment_transfer_templates.xml b/addons/payment_transfer/views/payment_transfer_templates.xml index 0716d99c349..52d311d9eb4 100644 --- a/addons/payment_transfer/views/payment_transfer_templates.xml +++ b/addons/payment_transfer/views/payment_transfer_templates.xml @@ -19,5 +19,13 @@ + From ffcd95aaa99e9d76bb234da9845f00b7cb2fcbc4 Mon Sep 17 00:00:00 2001 From: tbe-odoo Date: Mon, 21 Aug 2017 17:17:26 +0200 Subject: [PATCH 03/20] [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) --- addons/payment/security/ir.model.access.csv | 3 + addons/payment/static/src/js/payment_form.js | 72 ++++++++++++++----- .../views/payment_portal_templates.xml | 1 + addons/payment/views/payment_templates.xml | 34 +++++++-- .../data/payment_acquirer_data.xml | 3 +- .../views/payment_adyen_templates.xml | 3 +- .../data/payment_acquirer_data.xml | 3 +- .../views/payment_authorize_templates.xml | 1 + .../data/payment_acquirer_data.xml | 3 +- .../views/payment_buckaroo_templates.xml | 1 + .../data/payment_acquirer_data.xml | 3 +- .../views/payment_ogone_templates.xml | 1 + .../data/payment_acquirer_data.xml | 3 +- .../views/payment_paypal_templates.xml | 1 + .../data/payment_acquirer_data.xml | 3 +- .../views/payment_payumoney_templates.xml | 1 + .../data/payment_acquirer_data.xml | 3 +- .../views/payment_sips_templates.xml | 1 + .../data/payment_acquirer_data.xml | 3 +- .../views/payment_stripe_templates.xml | 1 + .../data/payment_acquirer_data.xml | 3 +- .../views/payment_transfer_templates.xml | 1 + addons/sale_payment/models/payment.py | 2 +- addons/website_sale/controllers/main.py | 65 ++++++++++++++++- addons/website_sale/views/templates.xml | 12 ++++ 25 files changed, 190 insertions(+), 37 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("

We are not able to add your payment method at the moment.

")); } // 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("

We are not able to add your payment method at the moment.

") + (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 = ''; + // 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('

Please select a payment method

')); + this.error(_t('No payment method selected'), + _t('

Please select a payment method.

')); } }, // 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("

We are not able to add your payment method at the moment.

")); } // 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("

We are not able to add your payment method at the moment.

") + (core.debug ? data.data.message : '')); }); } else { - this.error(_t('Error'), - _t('

Please select the option to add a new payment method

')); + this.error(_t('No payment method selected'), + _t('

Please select the option to add a new payment method.

')); } }, // 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("

We are not able to delete your payment method at the moment.

")); }); }; @@ -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("

We are not able to delete your payment method at the moment.

") + (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 @@

Manage your Payment Methods

+ 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 --> -
+
- +
+
    + +
  • + +
  • +
    +
-
+
+ +
+ +
+ +