Private
Public Access
1
0

Merge branch 'release/v15.37'

This commit is contained in:
Sander Roosendaal
2021-02-03 08:34:28 +01:00
2 changed files with 28 additions and 24 deletions

View File

@@ -14,6 +14,7 @@ queuelow = django_rq.get_queue('low')
queuehigh = django_rq.get_queue('low') queuehigh = django_rq.get_queue('low')
from braintree.exceptions.invalid_signature_error import InvalidSignatureError from braintree.exceptions.invalid_signature_error import InvalidSignatureError
import rowers.fakturoid as fakturoid
from rowers.utils import myqueue from rowers.utils import myqueue
from rowers.tasks import ( from rowers.tasks import (
@@ -55,27 +56,29 @@ 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):
print(notification.kind)
if notification.kind == 'subscription_charged_successfully': if notification.kind == 'subscription_charged_successfully':
subscription_id = notification.subscription.id return send_invoice(notification.subscription)
print(subscription_id) return 0
rs = Rower.objects.filter(subscription_id=subscription_id)
if rs.count() == 0: def send_invoice(subscription):
return 0 subscription_id = subscription.id
else: rs = Rower.objects.filter(subscription_id=subscription_id)
r = rs[0] if rs.count() == 0:
print(r) return 0
fakturoid_contact_id = fakturoid.get_contacts(r) else:
if not fakturoid_contact_id: r = rs[0]
fakturoid_contact_id = fakturoid.create_contact(rower) fakturoid_contact_id = fakturoid.get_contacts(r)
transactions = result.subscription.transactions if not fakturoid_contact_id:
if transactions: fakturoid_contact_id = fakturoid.create_contact(r)
amount = transactions[0].amount transactions = subscription.transactions
fakturoid.create_invoice(r,amount) if transactions:
return 1 amount = transactions[0].amount
id = fakturoid.create_invoice(r,amount,subscription_id,dosend=True)
return id
return 0 return 0
def webhook(request): def webhook(request):
try: try:
webhook_notification = gateway.webhook_notification.parse( webhook_notification = gateway.webhook_notification.parse(
@@ -84,8 +87,6 @@ def webhook(request):
except InvalidSignatureError: except InvalidSignatureError:
return 4 return 4
print(webhook_notification.kind)
result = process_webhook(webhook_notification) result = process_webhook(webhook_notification)

View File

@@ -28,10 +28,11 @@ def get_contacts(rower):
if res.status_code != 200: if res.status_code != 200:
return None return None
if len(res.json())==1: if len(res.json())>=1:
r = res.json()[0] r = res.json()[0]
return r['id'] return r['id']
return None return None
# this should be triggered on braintree payment # this should be triggered on braintree payment
@@ -54,6 +55,7 @@ def create_contact(rower):
"web": "" "web": ""
} }
res = requests.post(contacts_url, data=json.dumps(post_data), auth=auth,headers=headers) res = requests.post(contacts_url, data=json.dumps(post_data), auth=auth,headers=headers)
if res.status_code not in [200,201]: if res.status_code not in [200,201]:
@@ -62,7 +64,7 @@ def create_contact(rower):
return res.json()['id'] return res.json()['id']
# this should be triggered by a Braintree webhook # this should be triggered by a Braintree webhook
def create_invoice(rower,amount,braintreeid,send=False): def create_invoice(rower,amount,braintreeid,dosend=True):
r_id = get_contacts(rower) r_id = get_contacts(rower)
@@ -75,17 +77,18 @@ def create_invoice(rower,amount,braintreeid,send=False):
'language':'en', 'language':'en',
'payment_method': 'card', 'payment_method': 'card',
'currency': 'EUR', 'currency': 'EUR',
'paid_amount': amount, 'paid_amount': str(amount),
'status': 'paid', 'status': 'paid',
'lines': [{ 'lines': [{
'name': 'Rowsandall Subscription', 'name': 'Rowsandall Subscription',
'quantity': '1', 'quantity': '1',
'unit_price': amount, 'unit_price': str(amount),
'vat_rate': 0, 'vat_rate': 0,
} }
] ]
} }
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)
if res.status_code not in [200,201]: if res.status_code not in [200,201]:
@@ -107,7 +110,7 @@ def create_invoice(rower,amount,braintreeid,send=False):
if res.status_code not in [200,201]: if res.status_code not in [200,201]:
return 0 return 0
if send: if dosend:
res = requests.post(urlsend,auth=auth,headers=headers) res = requests.post(urlsend,auth=auth,headers=headers)
return id return id