diff --git a/rowers/fakturoid.py b/rowers/fakturoid.py index 4d443426..551d582e 100644 --- a/rowers/fakturoid.py +++ b/rowers/fakturoid.py @@ -1,6 +1,7 @@ import requests import json from requests.auth import HTTPBasicAuth +import urllib.parse from rowsandall_app.settings import ( FAKTUROID_EMAIL, FAKTUROID_API_KEY, @@ -21,7 +22,7 @@ headers = { def get_contacts(rower): res = requests.get(contacts_url, auth=auth, headers=headers) - url = contacts_search_url+'?query='+str(rower.user.email) + 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') @@ -81,17 +82,21 @@ def create_contact(rower): return res.json()['id'] # this should be triggered by a Braintree webhook -def create_invoice(rower,amount,braintreeid,dosend=True): +def create_invoice(rower,amount,braintreeid,dosend=True, + contact_id=None): + + if not contact_id: + contact_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') + f.write('Creating invoice for contact iD '+str(contact_id)+'\n') - if not r_id: + if not contact_id: return 0 post_data = { - 'subject_id': r_id, + 'subject_id': contact_id, 'custom_id': braintreeid, 'language':'en', 'payment_method': 'card',