From 0a1a950c256c162bb3070d72d2dcdb9e8ab7cf1c Mon Sep 17 00:00:00 2001 From: jev-odoo Date: Thu, 16 May 2019 06:49:56 +0000 Subject: [PATCH] [FIX] payment_authorize: no customer profile don't crash transaction When transaction is approved, if for any reason the `customerProfileId` is missing from the response, the transaction is aborted. It should succeed even if we cannot create a customer profile. opw-1998505 closes odoo/odoo#33501 Signed-off-by: Nicolas Martinelli (nim) --- .../models/authorize_request.py | 8 ++++++++ addons/payment_authorize/models/payment.py | 17 +++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/addons/payment_authorize/models/authorize_request.py b/addons/payment_authorize/models/authorize_request.py index fef82365b71..04291b5d133 100644 --- a/addons/payment_authorize/models/authorize_request.py +++ b/addons/payment_authorize/models/authorize_request.py @@ -4,12 +4,14 @@ from urllib2 import urlopen, Request from StringIO import StringIO import xml.etree.ElementTree as ET from uuid import uuid4 +import logging from odoo import _ from odoo.exceptions import ValidationError, UserError from odoo import _ XMLNS = 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' +_logger = logging.getLogger(__name__) def strip_ns(xml, ns): @@ -183,6 +185,12 @@ class AuthorizeAPI(): etree.SubElement(customer, "email").text = partner.email or '' response = self._authorize_request(root) res = dict() + if not response.find('customerProfileId'): + _logger.warning( + 'Unable to create customer payment profile, data missing from transaction. Transaction_id: %s - Partner_id: %s' + % (transaction_id, partner) + ) + return res res['profile_id'] = response.find('customerProfileId').text res['payment_profile_id'] = response.find('customerPaymentProfileIdList/numericString').text root_profile = self._base_tree('getCustomerPaymentProfileRequest') diff --git a/addons/payment_authorize/models/payment.py b/addons/payment_authorize/models/payment.py index 6c31e7a499e..f77504d738e 100644 --- a/addons/payment_authorize/models/payment.py +++ b/addons/payment_authorize/models/payment.py @@ -230,14 +230,15 @@ class TxAuthorize(models.Model): (self.type == 'form_save' or self.acquirer_id.save_token == 'always'): transaction = AuthorizeAPI(self.acquirer_id) res = transaction.create_customer_profile_from_tx(self.partner_id, self.acquirer_reference) - token_id = self.env['payment.token'].create({ - 'authorize_profile': res.get('profile_id'), - 'name': res.get('name'), - 'acquirer_ref': res.get('payment_profile_id'), - 'acquirer_id': self.acquirer_id.id, - 'partner_id': self.partner_id.id, - }) - self.payment_token_id = token_id + if res: + token_id = self.env['payment.token'].create({ + 'authorize_profile': res.get('profile_id'), + 'name': res.get('name'), + 'acquirer_ref': res.get('payment_profile_id'), + 'acquirer_id': self.acquirer_id.id, + 'partner_id': self.partner_id.id, + }) + self.payment_token_id = token_id return True elif status_code == self._authorize_pending_tx_status: self.write({