From 2a381402e2879bca37ef57df8d2b1436ec918834 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Fri, 3 Jul 2020 22:50:14 +0000 Subject: [PATCH] Try to verify PayPal IPNs twice --- apiserver/apiserver/api/utils_paypal.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/apiserver/apiserver/api/utils_paypal.py b/apiserver/apiserver/api/utils_paypal.py index e27ff2d..997906c 100644 --- a/apiserver/apiserver/api/utils_paypal.py +++ b/apiserver/apiserver/api/utils_paypal.py @@ -85,15 +85,24 @@ def verify_paypal_ipn(data): } try: - r = requests.post(VERIFY_URL, params=params, headers=headers, timeout=2) + r = requests.post(VERIFY_URL, params=params, headers=headers, timeout=4) r.raise_for_status() - if r.text != 'VERIFIED': - return False + if r.text == 'VERIFIED': + return True except BaseException as e: logger.error('IPN verify - {} - {}'.format(e.__class__.__name__, str(e))) - return False - return True + logger.info('IPN - verification failed, retrying...') + + try: + r = requests.post(VERIFY_URL, params=params, headers=headers, timeout=4) + r.raise_for_status() + if r.text == 'VERIFIED': + return True + except BaseException as e: + logger.error('IPN verify - {} - {}'.format(e.__class__.__name__, str(e))) + + return False def build_tx(data): amount = float(data.get('mc_gross', 0))