Private
Public Access
1
0

fixes for upgrades

This commit is contained in:
2023-11-07 21:29:58 +01:00
parent 173a3528ee
commit 76a1fb13bb
3 changed files with 22 additions and 32 deletions

View File

@@ -2,6 +2,7 @@ import requests
import json
from requests.auth import HTTPBasicAuth
import urllib.parse
from rowers.utils import dologging
from rowsandall_app.settings import (
FAKTUROID_EMAIL, FAKTUROID_API_KEY,
@@ -27,19 +28,16 @@ headers = {
def get_contacts(rower):
res = requests.get(contacts_url, auth=auth, headers=headers)
url = contacts_search_url+'?query='+urllib.parse.quote(rower.user.email)
with open('braintreewebhooks.log', 'a') as f:
f.write('Searching Contact url :'+str(url)+'\n')
dologging('braintreewebhooks.log','Searching Contact url :'+str(url))
res = requests.get(url, auth=auth, headers=headers)
with open('braintreewebhooks.log', 'a') as f:
f.write('Searching Contact Status code '+str(res.status_code)+'\n')
dologging('braintreewebhooks.log','Searching Contact Status code '+str(res.status_code)+'\n')
if res.status_code != 200: # pragma: no cover
return None
with open('braintreewebhooks.log', 'a') as f:
f.write('Status Code '+json.dumps(res.json())+'\n')
dologging('braintreewebhooks.log','Status Code '+json.dumps(res.json())+'\n')
if len(res.json()) >= 1:
r = res.json()[0]
@@ -69,20 +67,17 @@ def create_contact(rower):
"web": ""
}
with open('braintreewebhooks.log', 'a') as f:
f.write('Creating fakturoid contact for '+str(rower.user.email)+'\n')
dologging('braintreewebhooks.log','Creating fakturoid contact for '+str(rower.user.email)+'\n')
res = requests.post(contacts_url, data=json.dumps(
post_data), auth=auth, headers=headers)
with open('braintreewebhooks.log', 'a') as f:
f.write('Status Code '+str(res.status_code)+'\n')
dologging('braintreewebhooks.log','Status Code '+str(res.status_code)+'\n')
if res.status_code not in [200, 201]: # pragma: no cover
return 0
with open('braintreewebhooks.log', 'a') as f:
f.write('Contact ID'+str(res.json()['id'])+'\n')
dologging('braintreewebhooks.log','Contact ID'+str(res.json()['id'])+'\n')
return res.json()['id']
@@ -98,8 +93,7 @@ def create_invoice(rower, amount, braintreeid, dosend=True,
if not name:
name = 'Rowsandall Subscription'
with open('braintreewebhooks.log', 'a') as f:
f.write('Creating invoice for contact iD '+str(contact_id)+'\n')
dologging('braintreewebhooks.log','Creating invoice for contact iD '+str(contact_id)+'\n')
if not contact_id: # pragma: no cover
return 0
@@ -123,8 +117,7 @@ def create_invoice(rower, amount, braintreeid, dosend=True,
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')
dologging('braintreewebhooks.log','Invoice Created - status code '+str(res.status_code)+'\n')
if res.status_code not in [200, 201]: # pragma: no cover
return 0
@@ -141,8 +134,7 @@ def create_invoice(rower, amount, braintreeid, dosend=True,
res = requests.post(urlpay, auth=auth, headers=headers)
with open('braintreewebhooks.log', 'a') as f:
f.write('Invoice Set to paid - status code ' +
dologging('braintreewebhooks.log','Invoice Set to paid - status code ' +
str(res.status_code)+'\n')
if res.status_code not in [200, 201]: # pragma: no cover
@@ -151,8 +143,7 @@ def create_invoice(rower, amount, braintreeid, dosend=True,
if dosend:
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')
dologging('braintreewebhooks.log','Invoice Sent - status code '+str(res.status_code)+'\n')
return id