Merge branch 'release/v15.38'
This commit is contained in:
@@ -13,6 +13,8 @@ queue = django_rq.get_queue('default')
|
|||||||
queuelow = django_rq.get_queue('low')
|
queuelow = django_rq.get_queue('low')
|
||||||
queuehigh = django_rq.get_queue('low')
|
queuehigh = django_rq.get_queue('low')
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
from braintree.exceptions.invalid_signature_error import InvalidSignatureError
|
from braintree.exceptions.invalid_signature_error import InvalidSignatureError
|
||||||
import rowers.fakturoid as fakturoid
|
import rowers.fakturoid as fakturoid
|
||||||
|
|
||||||
@@ -56,23 +58,37 @@ from rowers.models import Rower,PaidPlan, CoachingGroup
|
|||||||
from rowers.utils import ProcessorCustomerError
|
from rowers.utils import ProcessorCustomerError
|
||||||
|
|
||||||
def process_webhook(notification):
|
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':
|
if notification.kind == 'subscription_charged_successfully':
|
||||||
return send_invoice(notification.subscription)
|
return send_invoice(notification.subscription)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def send_invoice(subscription):
|
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
|
subscription_id = subscription.id
|
||||||
rs = Rower.objects.filter(subscription_id=subscription_id)
|
rs = Rower.objects.filter(subscription_id=subscription_id)
|
||||||
if rs.count() == 0:
|
if rs.count() == 0:
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
r = rs[0]
|
r = rs[0]
|
||||||
|
with open('braintreewebhooks.log','a') as f:
|
||||||
|
f.write('Rower '+str(r)+'\n')
|
||||||
fakturoid_contact_id = fakturoid.get_contacts(r)
|
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:
|
if not fakturoid_contact_id:
|
||||||
fakturoid_contact_id = fakturoid.create_contact(r)
|
fakturoid_contact_id = fakturoid.create_contact(r)
|
||||||
transactions = subscription.transactions
|
transactions = subscription.transactions
|
||||||
if transactions:
|
if transactions:
|
||||||
amount = transactions[0].amount
|
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)
|
id = fakturoid.create_invoice(r,amount,subscription_id,dosend=True)
|
||||||
return id
|
return id
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ def create_contact(rower):
|
|||||||
def create_invoice(rower,amount,braintreeid,dosend=True):
|
def create_invoice(rower,amount,braintreeid,dosend=True):
|
||||||
|
|
||||||
r_id = get_contacts(rower)
|
r_id = get_contacts(rower)
|
||||||
|
with open('braintreewebhooks.log','a') as f:
|
||||||
|
f.write('Creating invoice for contact iD '+str(r_id)+'\n')
|
||||||
|
|
||||||
if not r_id:
|
if not r_id:
|
||||||
return 0
|
return 0
|
||||||
@@ -90,6 +92,8 @@ def create_invoice(rower,amount,braintreeid,dosend=True):
|
|||||||
|
|
||||||
|
|
||||||
res = requests.post(invoices_url, data=json.dumps(post_data), auth=auth,headers=headers)
|
res = requests.post(invoices_url, data=json.dumps(post_data), auth=auth,headers=headers)
|
||||||
|
with open('braintreewebhooks.log','a') as f:
|
||||||
|
f.write('Invoice Created - status code '+str(res.status_code)+'\n')
|
||||||
|
|
||||||
if res.status_code not in [200,201]:
|
if res.status_code not in [200,201]:
|
||||||
return 0
|
return 0
|
||||||
@@ -107,12 +111,18 @@ def create_invoice(rower,amount,braintreeid,dosend=True):
|
|||||||
|
|
||||||
res = requests.post(urlpay,auth=auth,headers=headers)
|
res = requests.post(urlpay,auth=auth,headers=headers)
|
||||||
|
|
||||||
|
with open('braintreewebhooks.log','a') as f:
|
||||||
|
f.write('Invoice Set to paid - status code '+str(res.status_code)+'\n')
|
||||||
|
|
||||||
if res.status_code not in [200,201]:
|
if res.status_code not in [200,201]:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if dosend:
|
if dosend:
|
||||||
res = requests.post(urlsend,auth=auth,headers=headers)
|
res = requests.post(urlsend,auth=auth,headers=headers)
|
||||||
|
|
||||||
|
with open('braintreewebhooks.log','a') as f:
|
||||||
|
f.write('Invoice Sent - status code '+str(res.status_code)+'\n')
|
||||||
|
|
||||||
return id
|
return id
|
||||||
|
|
||||||
#curl -u vas@email.cz:API_TOKEN -H 'User-Agent: YourApp (yourname@example.com)' \
|
#curl -u vas@email.cz:API_TOKEN -H 'User-Agent: YourApp (yourname@example.com)' \
|
||||||
|
|||||||
@@ -7,6 +7,11 @@ from rowers.views.statements import *
|
|||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def braintree_webhook_view(request):
|
def braintree_webhook_view(request):
|
||||||
|
with open('braintreewebhooks.log','a') as f:
|
||||||
|
t = time.localtime()
|
||||||
|
timestamp = time.strftime('%b-%d-%Y_%H%M', t)
|
||||||
|
f.write('\n')
|
||||||
|
f.write(timestamp+' /rowers/braintree/\n')
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
result = braintreestuff.webhook(request)
|
result = braintreestuff.webhook(request)
|
||||||
if result == 4:
|
if result == 4:
|
||||||
|
|||||||
Reference in New Issue
Block a user