Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
Don't choke on NOT_PROCESSED paypal responses (bug 740652)
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Short committed Apr 4, 2012
1 parent 8571909 commit 1d74c26
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion apps/paypal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,20 +239,28 @@ def refund(paykey):
while i >= len(responses):
responses.append({})
responses[i][subkey] = response[k]
clean_responses = []
for d in responses:
if d['refundStatus'] == 'NOT_PROCESSED':
# Probably, some other response failed, so PayPal
# ignored this one. We'll leave it out of the list we
# return.
continue
if d['refundStatus'] == 'NO_API_ACCESS_TO_RECEIVER':
# The refund didn't succeed, but let's not raise it as
# an error, because the caller needs to report this to
# the user.
clean_responses.append(d)
continue
if d['refundStatus'] not in OK_STATUSES:
raise PaypalError('Bad refund status for %s: %s'
% (d['receiver.email'],
d['refundStatus']))
paypal_log.debug('Refund successful for: %s, %s, %s' %
(paykey, d['receiver.email'], d['refundStatus']))
clean_responses.append(d)

return responses
return clean_responses


def get_personal_data(token):
Expand Down
13 changes: 13 additions & 0 deletions apps/paypal/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,13 @@ def test_get_permissions_subset(self, _call):
'&refundInfoList.refundInfo(0).receiver.email=bob@example.com'
'&refundInfoList.refundInfo(0).refundStatus=NO_API_ACCESS_TO_RECEIVER')

processing_failed_refund_string = (
'refundInfoList.refundInfo(1).receiver.amount=0.30'
'&refundInfoList.refundInfo(1).refundStatus=NO_API_ACCESS_TO_RECEIVER'
'&refundInfoList.refundInfo(1).receiver.email=andy_1318364497_biz@gmail.com'
'&refundInfoList.refundInfo(0).receiver.email=seller_1322765404_biz@gmail.com'
'&refundInfoList.refundInfo(0).refundStatus=NOT_PROCESSED')

error_refund_string = (
'refundInfoList.refundInfo(0).receiver.amount=123.45'
'&refundInfoList.refundInfo(0).receiver.email=bob@example.com'
Expand Down Expand Up @@ -388,6 +395,12 @@ def test_refund_no_refund_token(self, opener):
d = paypal.refund('fake-paykey')
eq_(d[0]['refundStatus'], 'NO_API_ACCESS_TO_RECEIVER')

@mock.patch('urllib2.OpenerDirector.open')
def test_refund_processing_failed(self, opener):
opener.return_value = StringIO(processing_failed_refund_string)
d = paypal.refund('fake-paykey')
eq_(d[0]['refundStatus'], 'NO_API_ACCESS_TO_RECEIVER')

@mock.patch('urllib2.OpenerDirector.open')
def test_refund_wrong_status(self, opener):
opener.return_value = StringIO(error_refund_string)
Expand Down

0 comments on commit 1d74c26

Please sign in to comment.