From e40f390bc075ae86fabcb99bcc8cb680d793c1aa Mon Sep 17 00:00:00 2001 From: shlurbee Date: Sat, 16 Jun 2012 15:32:57 -0700 Subject: [PATCH] Update regexp for authorize duplicate customer error Fixes the following bug: A user was unable to authorize campaign because clicking Pay raised an exception. Cause: The user's record was missing from the authorize_account_id table. Our code has some logic to parse the customer id from the authorize error response when this happens and rewrite the record, but the regexp was out of date. This change updates the regexp to match the current authorize.net error msg format and logs some info to make it easier to catch the problem if the format changes again in the future. Note: - Why would a user record be missing in the first place? Should be looked into. --- r2/r2/lib/authorize/api.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/r2/r2/lib/authorize/api.py b/r2/r2/lib/authorize/api.py index ba2fe2734..672b61822 100644 --- a/r2/r2/lib/authorize/api.py +++ b/r2/r2/lib/authorize/api.py @@ -285,12 +285,22 @@ class CreateCustomerProfileRequest(AuthorizeNetRequest): return (CustomerID.get_id(self._user) or AuthorizeNetRequest.make_request(self)) - re_lost_id = re.compile("A duplicate record with id (\d+) already exists") + re_lost_id = re.compile("A duplicate record with ID (\d+) already exists") def process_error(self, res): if self.is_error_code(res, Errors.DUPLICATE_RECORD): - # D'oh. We lost one - m = self.re_lost_id.match(res.find("text").contents[0]).groups() - CustomerID.set(self._user, m[0]) + # authorize.net has a record for this customer but we don't. get + # the correct id from the error message and update our db + matches = self.re_lost_id.match(res.find("text").contents[0]) + if matches: + match_groups = matches.groups() + CustomerID.set(self._user, match_groups[0]) + g.log.debug("Updated missing authorize.net id for user %s" % self._user._id) + else: + # could happen if the format of the error message changes. + msg = ("Failed to fix duplicate authorize.net profile id. " + "re_lost_id regexp may need to be updated. Response: %r" + % res) + raise AuthorizeNetException(msg) # otherwise, we might have sent a user that already had a customer ID cust_id = CustomerID.get_id(self._user) if cust_id: