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
|
import rowers.fakturoid as fakturoid
|
||||||
from braintree.exceptions.invalid_signature_error import InvalidSignatureError
|
from braintree.exceptions.invalid_signature_error import InvalidSignatureError
|
||||||
import time
|
import time
|
||||||
|
import sys, traceback
|
||||||
|
|
||||||
import braintree
|
import braintree
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
@@ -53,13 +54,7 @@ else:
|
|||||||
|
|
||||||
def process_webhook(notification):
|
def process_webhook(notification):
|
||||||
if not settings.TESTING: # pragma: no cover
|
if not settings.TESTING: # pragma: no cover
|
||||||
with open('braintreewebhooks.log', 'a') as f:
|
dologging('braintreewebhooks.log','{kind}'.format(kind=notification.kind))
|
||||||
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')
|
|
||||||
if notification.kind == 'subscription_charged_successfully':
|
if notification.kind == 'subscription_charged_successfully':
|
||||||
subscription = notification.subscription
|
subscription = notification.subscription
|
||||||
rs = Rower.objects.filter(subscription_id=subscription.id)
|
rs = Rower.objects.filter(subscription_id=subscription.id)
|
||||||
@@ -85,13 +80,27 @@ def process_webhook(notification):
|
|||||||
r = rs[0]
|
r = rs[0]
|
||||||
result, mesg, errormsg = cancel_subscription(r, subscription.id)
|
result, mesg, errormsg = cancel_subscription(r, subscription.id)
|
||||||
if result:
|
if result:
|
||||||
with open('braintreewebhooks.log', 'a') as f:
|
dologging('braintreewebhooks.log','Subscription canceled {id}'.format(id=subscription.id))
|
||||||
f.write('Subscription canceled: '+str(subscription.id)+'\n')
|
|
||||||
return subscription.id
|
return subscription.id
|
||||||
with open('braintreewebhooks.log', 'a') as f: # pragma: no cover
|
with open('braintreewebhooks.log', 'a') as f: # pragma: no cover
|
||||||
f.write('Could not cancel Subscription: ' +
|
f.write('Could not cancel Subscription: ' +
|
||||||
str(subscription.id)+'\n')
|
str(subscription.id)+'\n')
|
||||||
return 0 # pragma: no cover
|
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
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@@ -178,6 +187,7 @@ def make_payment(rower, data):
|
|||||||
info = nonce.three_d_secure_info
|
info = nonce.three_d_secure_info
|
||||||
if nonce.type.lower() == 'creditcard': # pragma: no cover
|
if nonce.type.lower() == 'creditcard': # pragma: no cover
|
||||||
if info is None or not info.liability_shifted:
|
if info is None or not info.liability_shifted:
|
||||||
|
dologging('braintree.log','Nonce info {info}'.format(info=info))
|
||||||
return False, 0
|
return False, 0
|
||||||
|
|
||||||
amount = data['amount']
|
amount = data['amount']
|
||||||
@@ -215,6 +225,7 @@ def make_payment(rower, data):
|
|||||||
name, rower.user.email, amount)
|
name, rower.user.email, amount)
|
||||||
return amount, True
|
return amount, True
|
||||||
else: # pragma: no cover
|
else: # pragma: no cover
|
||||||
|
dologging('braintree.log','Payment failed {result}'.format(result=result))
|
||||||
return 0, False
|
return 0, False
|
||||||
|
|
||||||
|
|
||||||
@@ -226,6 +237,7 @@ def update_subscription(rower, data, method='up'):
|
|||||||
info = nonce.three_d_secure_info
|
info = nonce.three_d_secure_info
|
||||||
if nonce.type.lower() == 'creditcard': # pragma: no cover
|
if nonce.type.lower() == 'creditcard': # pragma: no cover
|
||||||
if info is None or not info.liability_shifted:
|
if info is None or not info.liability_shifted:
|
||||||
|
dologging('braintree.log','Nonce info {info}'.format(info=info))
|
||||||
return False, 0
|
return False, 0
|
||||||
amount = data['amount']
|
amount = data['amount']
|
||||||
amount = '{amount:.2f}'.format(amount=amount)
|
amount = '{amount:.2f}'.format(amount=amount)
|
||||||
@@ -249,7 +261,14 @@ def update_subscription(rower, data, method='up'):
|
|||||||
rower.subscription_id,
|
rower.subscription_id,
|
||||||
gatewaydata
|
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
|
return False, 0
|
||||||
|
|
||||||
if result.is_success:
|
if result.is_success:
|
||||||
@@ -319,6 +338,8 @@ def update_subscription(rower, data, method='up'):
|
|||||||
if create_new:
|
if create_new:
|
||||||
return create_subscription(rower, data)
|
return create_subscription(rower, data)
|
||||||
|
|
||||||
|
dologging('braintree.log','Unrecognized proceed code {c}'.format(c=codes))
|
||||||
|
|
||||||
return False, 0
|
return False, 0
|
||||||
|
|
||||||
return False, 0 # pragma: no cover
|
return False, 0 # pragma: no cover
|
||||||
@@ -332,6 +353,7 @@ def create_subscription(rower, data):
|
|||||||
|
|
||||||
if nonce.type != 'PayPalAccount': # pragma: no cover
|
if nonce.type != 'PayPalAccount': # pragma: no cover
|
||||||
if info is None or not info.liability_shifted:
|
if info is None or not info.liability_shifted:
|
||||||
|
dologging('braintree.log','Create Subscription. Nonce info {info}'.format(info=info))
|
||||||
return False, 0
|
return False, 0
|
||||||
# amount = data['amount']
|
# amount = data['amount']
|
||||||
|
|
||||||
@@ -347,6 +369,7 @@ def create_subscription(rower, data):
|
|||||||
if result.is_success:
|
if result.is_success:
|
||||||
payment_method_token = result.payment_method.token
|
payment_method_token = result.payment_method.token
|
||||||
else: # pragma: no cover
|
else: # pragma: no cover
|
||||||
|
dologging('braintree.log','Payment failed {result}'.format(result=result))
|
||||||
return False, 0
|
return False, 0
|
||||||
|
|
||||||
result = gateway.subscription.create({
|
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