make ipn optional and do some cleaning (bug 688203)
This commit is contained in:
Родитель
505ef2bd4b
Коммит
ccb098333f
|
@ -484,7 +484,8 @@ def purchase(request, addon):
|
|||
amount=amount, memo=contrib_for, email=addon.paypal_id,
|
||||
ip=request.META.get('REMOTE_ADDR'),
|
||||
pattern='addons.purchase.finished',
|
||||
qs={'realurl': request.GET.get('realurl')}))
|
||||
qs={'realurl': request.GET.get('realurl')},
|
||||
ipn=False))
|
||||
except:
|
||||
log.error('Error getting paykey, purchase of addon: %s' % addon.pk,
|
||||
exc_info=True)
|
||||
|
|
|
@ -65,8 +65,10 @@ def get_paykey(data):
|
|||
'receiverList.receiver(0).invoiceID': 'mozilla-%s' % data['uuid'],
|
||||
'receiverList.receiver(0).primary': 'TRUE',
|
||||
'receiverList.receiver(0).paymentType': 'DIGITALGOODS',
|
||||
'trackingId': data['uuid'],
|
||||
'ipnNotificationUrl': absolutify(reverse('amo.paypal'))}
|
||||
'trackingId': data['uuid']}
|
||||
|
||||
if data.get('ipn', True):
|
||||
paypal_data['ipnNotificationUrl'] = absolutify(reverse('amo.paypal'))
|
||||
|
||||
if data.get('memo'):
|
||||
paypal_data['memo'] = data['memo']
|
||||
|
@ -96,6 +98,7 @@ def check_purchase(paykey):
|
|||
|
||||
return response['status']
|
||||
|
||||
|
||||
def refund(txnid):
|
||||
"""
|
||||
Refund a payment.
|
||||
|
@ -123,15 +126,11 @@ def refund(txnid):
|
|||
responses.append({})
|
||||
responses[i][subkey] = response[k]
|
||||
for d in responses:
|
||||
status = '%s: %s' % (d['receiver.email'], d['refundStatus'])
|
||||
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 transaction %s.'
|
||||
' Statuses: %r'
|
||||
% (txnid, [(d['receiver.email'], d['refundStatus'])
|
||||
for d in responses]))
|
||||
|
||||
raise PaypalError('Bad refund status for %s' % status)
|
||||
paypal_log.debug('Refund done for transaction %s, status: %s'
|
||||
% (txnid, status))
|
||||
|
||||
return responses
|
||||
|
||||
|
|
|
@ -61,6 +61,21 @@ class TestPayKey(amo.tests.TestCase):
|
|||
qs = _call.call_args[0][1]['returnUrl'].split('?')[1]
|
||||
eq_(dict(urlparse.parse_qsl(qs))['foo'], 'bar')
|
||||
|
||||
@mock.patch('paypal._call')
|
||||
def test_ipn_skipped(self, _call):
|
||||
data = self.data.copy()
|
||||
data['ipn'] = False
|
||||
_call.return_value = {'payKey': '123'}
|
||||
paypal.get_paykey(data)
|
||||
assert 'ipnNotificationUrl' not in _call.call_args[0][1]
|
||||
|
||||
@mock.patch('paypal._call')
|
||||
def test_ipn_asked(self, _call):
|
||||
data = self.data.copy()
|
||||
_call.return_value = {'payKey': '123'}
|
||||
paypal.get_paykey(data)
|
||||
assert 'ipnNotificationUrl' in _call.call_args[0][1]
|
||||
|
||||
def _test_no_mock(self):
|
||||
# Remove _ and run if you'd like to try unmocked.
|
||||
return paypal.get_paykey(self.data)
|
||||
|
|
Загрузка…
Ссылка в новой задаче