From e5d7434bc192700b39b7cc8a8ce8621d55bd0ab8 Mon Sep 17 00:00:00 2001 From: Kaushal Prajappati Date: Wed, 17 Jan 2018 16:10:51 +0530 Subject: [PATCH] [IMP] Payment and Payment Gateway compatible for Multi Website --- addons/payment_adyen/models/payment.py | 2 ++ addons/payment_authorize/controllers/main.py | 2 ++ addons/payment_authorize/models/payment.py | 2 ++ addons/payment_buckaroo/models/payment.py | 2 ++ addons/payment_ogone/models/payment.py | 2 ++ addons/payment_paypal/models/payment.py | 2 ++ addons/payment_payumoney/models/payment.py | 2 ++ addons/payment_sips/models/payment.py | 2 ++ addons/website_payment/models/__init__.py | 1 + addons/website_payment/models/payment.py | 10 ++++++++ .../views/website_payment_view.xml | 23 +++++++++++++++++++ addons/website_sale/controllers/main.py | 4 ++-- 12 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 addons/website_payment/models/payment.py diff --git a/addons/payment_adyen/models/payment.py b/addons/payment_adyen/models/payment.py index 0cfe5a84..eeabd87e 100644 --- a/addons/payment_adyen/models/payment.py +++ b/addons/payment_adyen/models/payment.py @@ -115,6 +115,8 @@ class AcquirerAdyen(models.Model): @api.multi def adyen_form_generate_values(self, values): base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url') + if self.env.ref('base.module_website').state == 'installed': + base_url = "http://" + self.env['website'].get_current_website().domain # tmp import datetime from dateutil import relativedelta diff --git a/addons/payment_authorize/controllers/main.py b/addons/payment_authorize/controllers/main.py index 843b95d4..8761c406 100644 --- a/addons/payment_authorize/controllers/main.py +++ b/addons/payment_authorize/controllers/main.py @@ -24,6 +24,8 @@ class AuthorizeController(http.Controller): request.env['payment.transaction'].sudo().form_feedback(post, 'authorize') return_url = post.pop('return_url', '/') base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url') + if self.env.ref('base.module_website').state == 'installed': + base_url = "http://" + self.env['website'].get_current_website().domain # Authorize.Net is expecting a response to the POST sent by their server. # This response is in the form of a URL that Authorize.Net will pass on to the # client's browser to redirect them to the desired location need javascript. diff --git a/addons/payment_authorize/models/payment.py b/addons/payment_authorize/models/payment.py index 4315690e..24c53e9d 100644 --- a/addons/payment_authorize/models/payment.py +++ b/addons/payment_authorize/models/payment.py @@ -60,6 +60,8 @@ class PaymentAcquirerAuthorize(models.Model): def authorize_form_generate_values(self, values): self.ensure_one() base_url = self.env['ir.config_parameter'].get_param('web.base.url') + if self.env.ref('base.module_website').state == 'installed': + base_url = "http://" + self.env['website'].get_current_website().domain authorize_tx_values = dict(values) temp_authorize_tx_values = { 'x_login': self.authorize_login, diff --git a/addons/payment_buckaroo/models/payment.py b/addons/payment_buckaroo/models/payment.py index 3c658590..b5ec2a8e 100644 --- a/addons/payment_buckaroo/models/payment.py +++ b/addons/payment_buckaroo/models/payment.py @@ -84,6 +84,8 @@ class AcquirerBuckaroo(models.Model): @api.multi def buckaroo_form_generate_values(self, values): base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url') + if self.env.ref('base.module_website').state == 'installed': + base_url = "http://" + self.env['website'].get_current_website().domain buckaroo_tx_values = dict(values) buckaroo_tx_values.update({ 'Brq_websitekey': self.brq_websitekey, diff --git a/addons/payment_ogone/models/payment.py b/addons/payment_ogone/models/payment.py index c052e614..5699b5de 100644 --- a/addons/payment_ogone/models/payment.py +++ b/addons/payment_ogone/models/payment.py @@ -150,6 +150,8 @@ class PaymentAcquirerOgone(models.Model): def ogone_form_generate_values(self, values): base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url') + if self.env.ref('base.module_website').state == 'installed': + base_url = "http://" + self.env['website'].get_current_website().domain ogone_tx_values = dict(values) temp_ogone_tx_values = { 'PSPID': self.ogone_pspid, diff --git a/addons/payment_paypal/models/payment.py b/addons/payment_paypal/models/payment.py index 3977907d..2b9cab09 100644 --- a/addons/payment_paypal/models/payment.py +++ b/addons/payment_paypal/models/payment.py @@ -92,6 +92,8 @@ class AcquirerPaypal(models.Model): @api.multi def paypal_form_generate_values(self, values): base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url') + if self.env.ref('base.module_website').state == 'installed': + base_url = "http://" + self.env['website'].get_current_website().domain paypal_tx_values = dict(values) paypal_tx_values.update({ diff --git a/addons/payment_payumoney/models/payment.py b/addons/payment_payumoney/models/payment.py index 79c40068..fe91f02b 100644 --- a/addons/payment_payumoney/models/payment.py +++ b/addons/payment_payumoney/models/payment.py @@ -56,6 +56,8 @@ class PaymentAcquirerPayumoney(models.Model): def payumoney_form_generate_values(self, values): self.ensure_one() base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url') + if self.env.ref('base.module_website').state == 'installed': + base_url = "http://" + self.env['website'].get_current_website().domain payumoney_values = dict(values, key=self.payumoney_merchant_key, txnid=values['reference'], diff --git a/addons/payment_sips/models/payment.py b/addons/payment_sips/models/payment.py index eef26b19..8ef0dd6e 100644 --- a/addons/payment_sips/models/payment.py +++ b/addons/payment_sips/models/payment.py @@ -68,6 +68,8 @@ class AcquirerSips(models.Model): def sips_form_generate_values(self, values): self.ensure_one() base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url') + if self.env.ref('base.module_website').state == 'installed': + base_url = "http://" + self.env['website'].get_current_website().domain currency = self.env['res.currency'].sudo().browse(values['currency_id']) currency_code = CURRENCY_CODES.get(currency.name, False) if not currency_code: diff --git a/addons/website_payment/models/__init__.py b/addons/website_payment/models/__init__.py index bd190fa8..300cd3e8 100644 --- a/addons/website_payment/models/__init__.py +++ b/addons/website_payment/models/__init__.py @@ -1 +1,2 @@ +from . import payment from . import website diff --git a/addons/website_payment/models/payment.py b/addons/website_payment/models/payment.py new file mode 100644 index 00000000..78f4e962 --- /dev/null +++ b/addons/website_payment/models/payment.py @@ -0,0 +1,10 @@ +# Part of Flectra. See LICENSE file for full copyright and licensing details. +from flectra import fields, models + + +class PaymentAcquirer(models.Model): + _inherit = "payment.acquirer" + + website_id = fields.Many2many('website', 'website_payment_rel', + 'website_id', 'payment_id', + string='Website') diff --git a/addons/website_payment/views/website_payment_view.xml b/addons/website_payment/views/website_payment_view.xml index b151c35f..915b0c64 100644 --- a/addons/website_payment/views/website_payment_view.xml +++ b/addons/website_payment/views/website_payment_view.xml @@ -18,5 +18,28 @@ + + + payment.acquirer.form + payment.acquirer + + + + + + + +
+
+ + Website is required in order to use payment gateway in e-commerce store. + +
+
+
+
+
+
+ diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 7f0ddcf8..9d8c828f 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -254,7 +254,7 @@ class WebsiteSale(http.Controller): if attrib_list: post['attrib'] = attrib_list - categs = request.env['product.public.category'].search([('parent_id', '=', False), '|', ('website_ids', '=', False), ('website_ids', 'in', request.website.id)]) + categs = request.env['product.public.category'].search([('parent_id', '=', False), ('website_ids', 'in', request.website.id)]) Product = request.env['product.template'] parent_category_ids = [] @@ -790,7 +790,7 @@ class WebsiteSale(http.Controller): ) acquirers = request.env['payment.acquirer'].search( - [('website_published', '=', True), ('company_id', '=', order.company_id.id)] + [('website_published', '=', True), ('company_id', '=', order.company_id.id), '|', ('website_id', '=', False), ('website_id', '=', request.website.id)] ) values['access_token'] = order.access_token