summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfda-odoo <fda@odoo.com>2017-12-13 16:07:59 +0100
committerfda-odoo <fda@odoo.com>2018-01-24 15:28:53 +0100
commitdaf6ab1c872ed9a04517dccd2b32db8dd4855163 (patch)
treea511831833b0fc273afb71f542188e4da418b0ff
parent50beec7fa0029f6ece11df02a26e333a8430ee95 (diff)
[FIX] Payment, payment_authorize: show an error if customer doesn't have a complete profil on authorize.net payment.
If the user has no Zip code, country or city, authorize refuse the payment, but Odoo doens't show any error. The commit invite the user to log in in this case or to fill his missing information
-rw-r--r--addons/payment/static/src/js/payment_form.js25
-rw-r--r--addons/payment_authorize/controllers/main.py25
-rw-r--r--addons/payment_authorize/models/authorize_request.py5
3 files changed, 46 insertions, 9 deletions
diff --git a/addons/payment/static/src/js/payment_form.js b/addons/payment/static/src/js/payment_form.js
index 21a105da3fa..bf555254d5e 100644
--- a/addons/payment/static/src/js/payment_form.js
+++ b/addons/payment/static/src/js/payment_form.js
@@ -108,9 +108,15 @@ odoo.define('payment.payment_form', function (require) {
}
// if the server has returned false, we display an error
else {
- self.displayError(
- _t('Server Error'),
- _t('e.g. Your credit card details are wrong. Please verify.'));
+ if (data.error) {
+ self.displayError(
+ '',
+ data.error);
+ } else { // if the server doesn't provide an error message
+ self.displayError(
+ _t('Server Error'),
+ _t('e.g. Your credit card details are wrong. Please verify.'));
+ }
}
// here we remove the 'processing' icon from the 'add a new payment' button
$(button).attr('disabled', false);
@@ -265,10 +271,15 @@ odoo.define('payment.payment_form', function (require) {
}
// if the server has returned false, we display an error
else {
- self.displayError(
- _t('Server Error'),
- _t("<p>We are not able to add your payment method at the moment.</p>")
- );
+ if (data.error) {
+ self.displayError(
+ '',
+ data.error);
+ } else { // if the server doesn't provide an error message
+ self.displayError(
+ _t('Server Error'),
+ _t('e.g. Your credit card details are wrong. Please verify.'));
+ }
}
// here we remove the 'processing' icon from the 'add a new payment' button
$(button).attr('disabled', false);
diff --git a/addons/payment_authorize/controllers/main.py b/addons/payment_authorize/controllers/main.py
index 6b0aae9bf6a..451a5875b6d 100644
--- a/addons/payment_authorize/controllers/main.py
+++ b/addons/payment_authorize/controllers/main.py
@@ -3,8 +3,9 @@ import pprint
import logging
from werkzeug import urls, utils
-from odoo import http
+from odoo import http, _
from odoo.http import request
+from odoo.exceptions import ValidationError
_logger = logging.getLogger(__name__)
@@ -39,7 +40,27 @@ class AuthorizeController(http.Controller):
@http.route(['/payment/authorize/s2s/create_json_3ds'], type='json', auth='public', csrf=False)
def authorize_s2s_create_json_3ds(self, verify_validity=False, **kwargs):
- token = request.env['payment.acquirer'].browse(int(kwargs.get('acquirer_id'))).s2s_process(kwargs)
+ token = False
+ acquirer = request.env['payment.acquirer'].browse(int(kwargs.get('acquirer_id')))
+
+ try:
+ token = acquirer.s2s_process(kwargs)
+ except ValidationError as e:
+ message = e.args[0]
+ if isinstance(message, dict) and 'missing_fields' in message:
+ msg = _("The transaction cannot be processed because some contact details are missing or invalid: ")
+ message = msg + ', '.join(message['missing_fields']) + '. '
+ if request.env.user._is_public():
+ message += _("Please sign in to complete your profile.")
+ # update message if portal mode = b2b
+ if request.env['ir.config_parameter'].sudo().get_param('auth_signup.allow_uninvited', 'False').lower() == 'false':
+ message += _("If you don't have any account, please ask your salesperson to update your profile. ")
+ else:
+ message += _("Please complete your profile. ")
+
+ return {
+ 'error': message
+ }
if not token:
res = {
diff --git a/addons/payment_authorize/models/authorize_request.py b/addons/payment_authorize/models/authorize_request.py
index 939abcaf049..5a5f30072f1 100644
--- a/addons/payment_authorize/models/authorize_request.py
+++ b/addons/payment_authorize/models/authorize_request.py
@@ -139,6 +139,11 @@ class AuthorizeAPI():
etree.SubElement(payment_profile, "customerType").text = 'business' if partner.is_company else 'individual'
billTo = etree.SubElement(payment_profile, "billTo")
etree.SubElement(billTo, "address").text = (partner.street or '' + (partner.street2 if partner.street2 else '')) or None
+
+ missing_fields = [partner._fields[field].string for field in ['city', 'country_id', 'zip'] if not partner[field]]
+ if missing_fields:
+ raise ValidationError({'missing_fields': missing_fields})
+
etree.SubElement(billTo, "city").text = partner.city
etree.SubElement(billTo, "state").text = partner.state_id.name or None
etree.SubElement(billTo, "zip").text = partner.zip