logging for braintree
This commit is contained in:
@@ -13,6 +13,8 @@ queue = django_rq.get_queue('default')
|
||||
queuelow = django_rq.get_queue('low')
|
||||
queuehigh = django_rq.get_queue('low')
|
||||
|
||||
import time
|
||||
|
||||
from braintree.exceptions.invalid_signature_error import InvalidSignatureError
|
||||
import rowers.fakturoid as fakturoid
|
||||
|
||||
@@ -56,23 +58,37 @@ from rowers.models import Rower,PaidPlan, CoachingGroup
|
||||
from rowers.utils import ProcessorCustomerError
|
||||
|
||||
def process_webhook(notification):
|
||||
with open('braintreewebhooks.log','a') as f:
|
||||
t = time.localtime()
|
||||
timestamp = time.strftime('%b-%d-%Y_%H%M', t)
|
||||
f.write(timestamp+' '+notification.kind+'\n')
|
||||
if notification.kind == 'subscription_charged_successfully':
|
||||
return send_invoice(notification.subscription)
|
||||
return 0
|
||||
|
||||
def send_invoice(subscription):
|
||||
with open('braintreewebhooks.log','a') as f:
|
||||
t = time.localtime()
|
||||
timestamp = time.strftime('%b-%d-%Y_%H%M', t)
|
||||
f.write('Subscription ID '+subscription.id+'\n')
|
||||
subscription_id = subscription.id
|
||||
rs = Rower.objects.filter(subscription_id=subscription_id)
|
||||
if rs.count() == 0:
|
||||
return 0
|
||||
else:
|
||||
r = rs[0]
|
||||
with open('braintreewebhooks.log','a') as f:
|
||||
f.write('Rower '+str(r)+'\n')
|
||||
fakturoid_contact_id = fakturoid.get_contacts(r)
|
||||
with open('braintreewebhooks.log','a') as f:
|
||||
f.write('Fakturoid ID '+str(fakturoid_contact_id)+'\n')
|
||||
if not fakturoid_contact_id:
|
||||
fakturoid_contact_id = fakturoid.create_contact(r)
|
||||
transactions = subscription.transactions
|
||||
if transactions:
|
||||
amount = transactions[0].amount
|
||||
with open('braintreewebhooks.log','a') as f:
|
||||
f.write('Transaction amount '+str(amount)+'\n')
|
||||
id = fakturoid.create_invoice(r,amount,subscription_id,dosend=True)
|
||||
return id
|
||||
|
||||
|
||||
Reference in New Issue
Block a user