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