Merge branch 'release/v20.2.3'
This commit is contained in:
@@ -19,6 +19,7 @@ from rowers.utils import myqueue
|
||||
import rowers.fakturoid as fakturoid
|
||||
from braintree.exceptions.invalid_signature_error import InvalidSignatureError
|
||||
import time
|
||||
import sys, traceback
|
||||
|
||||
import braintree
|
||||
from django.utils import timezone
|
||||
@@ -53,13 +54,7 @@ else:
|
||||
|
||||
def process_webhook(notification):
|
||||
if not settings.TESTING: # pragma: no cover
|
||||
with open('braintreewebhooks.log', 'a') as f:
|
||||
t = time.localtime()
|
||||
timestamp = time.strftime('%b-%d-%Y_%H%M', t)
|
||||
try:
|
||||
f.write(timestamp+' '+notification.kind+'\n')
|
||||
except TypeError:
|
||||
f.write(timestamp+'\n')
|
||||
dologging('braintreewebhooks.log','{kind}'.format(kind=notification.kind))
|
||||
if notification.kind == 'subscription_charged_successfully':
|
||||
subscription = notification.subscription
|
||||
rs = Rower.objects.filter(subscription_id=subscription.id)
|
||||
@@ -85,13 +80,27 @@ def process_webhook(notification):
|
||||
r = rs[0]
|
||||
result, mesg, errormsg = cancel_subscription(r, subscription.id)
|
||||
if result:
|
||||
with open('braintreewebhooks.log', 'a') as f:
|
||||
f.write('Subscription canceled: '+str(subscription.id)+'\n')
|
||||
dologging('braintreewebhooks.log','Subscription canceled {id}'.format(id=subscription.id))
|
||||
return subscription.id
|
||||
with open('braintreewebhooks.log', 'a') as f: # pragma: no cover
|
||||
f.write('Could not cancel Subscription: ' +
|
||||
str(subscription.id)+'\n')
|
||||
return 0 # pragma: no cover
|
||||
if notification.kind == 'subscription_charged_unsuccessfully':
|
||||
dologging('braintreewebhooks.log','Subscription charged unsuccessfully')
|
||||
subscription = notification.subscription
|
||||
rs = Rower.objects.filter(subscription_id=subscription.id)
|
||||
if rs.count() == 0: # pragma: no cover
|
||||
dologging('braintreewebhooks.log', 'Could not find rowers with subscription ID {id}'.format(
|
||||
id=subscription.id
|
||||
))
|
||||
else:
|
||||
r = rs[0]
|
||||
result, mesg, errormsg = cancel_subscription(r, subscription.id)
|
||||
dologging('braintreewebhooks.log','Subscription canceled for rower {r} with subscription ID {id}'.format(
|
||||
r = r.user.email,
|
||||
id = subscription.id
|
||||
))
|
||||
return 0
|
||||
|
||||
|
||||
@@ -178,6 +187,7 @@ def make_payment(rower, data):
|
||||
info = nonce.three_d_secure_info
|
||||
if nonce.type.lower() == 'creditcard': # pragma: no cover
|
||||
if info is None or not info.liability_shifted:
|
||||
dologging('braintree.log','Nonce info {info}'.format(info=info))
|
||||
return False, 0
|
||||
|
||||
amount = data['amount']
|
||||
@@ -215,6 +225,7 @@ def make_payment(rower, data):
|
||||
name, rower.user.email, amount)
|
||||
return amount, True
|
||||
else: # pragma: no cover
|
||||
dologging('braintree.log','Payment failed {result}'.format(result=result))
|
||||
return 0, False
|
||||
|
||||
|
||||
@@ -226,6 +237,7 @@ def update_subscription(rower, data, method='up'):
|
||||
info = nonce.three_d_secure_info
|
||||
if nonce.type.lower() == 'creditcard': # pragma: no cover
|
||||
if info is None or not info.liability_shifted:
|
||||
dologging('braintree.log','Nonce info {info}'.format(info=info))
|
||||
return False, 0
|
||||
amount = data['amount']
|
||||
amount = '{amount:.2f}'.format(amount=amount)
|
||||
@@ -249,7 +261,14 @@ def update_subscription(rower, data, method='up'):
|
||||
rower.subscription_id,
|
||||
gatewaydata
|
||||
)
|
||||
except: # pragma: no cover
|
||||
except BaseException as e: # pragma: no cover
|
||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||
dologging('braintree.log','Payment failed with error')
|
||||
dologging('braintree.log','{t}, {v}'.format(t=exc_type,v=exc_value))
|
||||
trace_back = traceback.extract_tb(exc_traceback)
|
||||
for trace in trace_back:
|
||||
dologging('braintree.log','{t}'.format(t=trace))
|
||||
|
||||
return False, 0
|
||||
|
||||
if result.is_success:
|
||||
@@ -319,6 +338,8 @@ def update_subscription(rower, data, method='up'):
|
||||
if create_new:
|
||||
return create_subscription(rower, data)
|
||||
|
||||
dologging('braintree.log','Unrecognized proceed code {c}'.format(c=codes))
|
||||
|
||||
return False, 0
|
||||
|
||||
return False, 0 # pragma: no cover
|
||||
@@ -332,6 +353,7 @@ def create_subscription(rower, data):
|
||||
|
||||
if nonce.type != 'PayPalAccount': # pragma: no cover
|
||||
if info is None or not info.liability_shifted:
|
||||
dologging('braintree.log','Create Subscription. Nonce info {info}'.format(info=info))
|
||||
return False, 0
|
||||
# amount = data['amount']
|
||||
|
||||
@@ -347,6 +369,7 @@ def create_subscription(rower, data):
|
||||
if result.is_success:
|
||||
payment_method_token = result.payment_method.token
|
||||
else: # pragma: no cover
|
||||
dologging('braintree.log','Payment failed {result}'.format(result=result))
|
||||
return False, 0
|
||||
|
||||
result = gateway.subscription.create({
|
||||
|
||||
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
Binary file not shown.
Reference in New Issue
Block a user