[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) <nim@odoo.com>
This commit is contained in:
jev-odoo
2019-05-20 11:29:08 +00:00
committed by Nicolas Martinelli
parent df4dcc8932
commit 0a1a950c25
2 changed files with 17 additions and 8 deletions
@@ -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')
+9 -8
View File
@@ -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({