logging braintree
This commit is contained in:
@@ -53,13 +53,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 +79,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 +186,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 +224,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
|
||||
|
||||
|
||||
|
||||
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