fixes for upgrades
This commit is contained in:
@@ -18,6 +18,7 @@ from rowers.tasks import (
|
|||||||
from rowers.utils import myqueue
|
from rowers.utils import myqueue
|
||||||
import rowers.fakturoid as fakturoid
|
import rowers.fakturoid as fakturoid
|
||||||
from braintree.exceptions.invalid_signature_error import InvalidSignatureError
|
from braintree.exceptions.invalid_signature_error import InvalidSignatureError
|
||||||
|
from braintree.exceptions.not_found_error import NotFoundError
|
||||||
import time
|
import time
|
||||||
import sys, traceback
|
import sys, traceback
|
||||||
|
|
||||||
@@ -73,8 +74,7 @@ def process_webhook(notification):
|
|||||||
subscription = notification.subscription
|
subscription = notification.subscription
|
||||||
rs = Rower.objects.filter(subscription_id=subscription.id)
|
rs = Rower.objects.filter(subscription_id=subscription.id)
|
||||||
if rs.count() == 0: # pragma: no cover
|
if rs.count() == 0: # pragma: no cover
|
||||||
with open('braintreewebhooks.log', 'a') as f:
|
dologging('braintreewebhooks.log','Could not find rowers with subscription ID ' +
|
||||||
f.write('Could not find rowers with subscription ID ' +
|
|
||||||
subscription.id+'\n')
|
subscription.id+'\n')
|
||||||
return 0
|
return 0
|
||||||
r = rs[0]
|
r = rs[0]
|
||||||
@@ -82,8 +82,7 @@ def process_webhook(notification):
|
|||||||
if result:
|
if result:
|
||||||
dologging('braintreewebhooks.log','Subscription canceled {id}'.format(id=subscription.id))
|
dologging('braintreewebhooks.log','Subscription canceled {id}'.format(id=subscription.id))
|
||||||
return subscription.id
|
return subscription.id
|
||||||
with open('braintreewebhooks.log', 'a') as f: # pragma: no cover
|
dologging('braintreewebhooks.log','Could not cancel Subscription: ' +
|
||||||
f.write('Could not cancel Subscription: ' +
|
|
||||||
str(subscription.id)+'\n')
|
str(subscription.id)+'\n')
|
||||||
return 0 # pragma: no cover
|
return 0 # pragma: no cover
|
||||||
if notification.kind == 'subscription_charged_unsuccessfully':
|
if notification.kind == 'subscription_charged_unsuccessfully':
|
||||||
@@ -112,21 +111,17 @@ def send_invoice(subscription):
|
|||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
r = rs[0]
|
r = rs[0]
|
||||||
with open('braintreewebhooks.log', 'a') as f:
|
dologging('braintreewebhooks.log','Rower '+str(r)+'\n')
|
||||||
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:
|
dologging('braintreewebhooks.log','Fakturoid Contact ID '+str(fakturoid_contact_id)+'\n')
|
||||||
f.write('Fakturoid Contact ID '+str(fakturoid_contact_id)+'\n')
|
|
||||||
if not fakturoid_contact_id: # pragma: no cover
|
if not fakturoid_contact_id: # pragma: no cover
|
||||||
fakturoid_contact_id = fakturoid.create_contact(r)
|
fakturoid_contact_id = fakturoid.create_contact(r)
|
||||||
with open('braintreewebhooks.log', 'a') as f:
|
dologging('braintreewebhooks.log','Created Fakturoid Contact ID ' +
|
||||||
f.write('Created Fakturoid Contact ID ' +
|
|
||||||
str(fakturoid_contact_id)+'\n')
|
str(fakturoid_contact_id)+'\n')
|
||||||
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:
|
dologging('braintreewebhooks.log','Transaction amount '+str(amount)+'\n')
|
||||||
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,
|
||||||
contact_id=fakturoid_contact_id)
|
contact_id=fakturoid_contact_id)
|
||||||
return id
|
return id
|
||||||
@@ -261,6 +256,10 @@ def update_subscription(rower, data, method='up'):
|
|||||||
rower.subscription_id,
|
rower.subscription_id,
|
||||||
gatewaydata
|
gatewaydata
|
||||||
)
|
)
|
||||||
|
except NotFoundError:
|
||||||
|
rower.subscription_id = None
|
||||||
|
rower.save()
|
||||||
|
return create_subscription(rower, data)
|
||||||
except BaseException as e: # pragma: no cover
|
except BaseException as e: # pragma: no cover
|
||||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||||
dologging('braintree.log','Payment failed with error')
|
dologging('braintree.log','Payment failed with error')
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import requests
|
|||||||
import json
|
import json
|
||||||
from requests.auth import HTTPBasicAuth
|
from requests.auth import HTTPBasicAuth
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
from rowers.utils import dologging
|
||||||
|
|
||||||
from rowsandall_app.settings import (
|
from rowsandall_app.settings import (
|
||||||
FAKTUROID_EMAIL, FAKTUROID_API_KEY,
|
FAKTUROID_EMAIL, FAKTUROID_API_KEY,
|
||||||
@@ -27,19 +28,16 @@ headers = {
|
|||||||
def get_contacts(rower):
|
def get_contacts(rower):
|
||||||
res = requests.get(contacts_url, auth=auth, headers=headers)
|
res = requests.get(contacts_url, auth=auth, headers=headers)
|
||||||
url = contacts_search_url+'?query='+urllib.parse.quote(rower.user.email)
|
url = contacts_search_url+'?query='+urllib.parse.quote(rower.user.email)
|
||||||
with open('braintreewebhooks.log', 'a') as f:
|
dologging('braintreewebhooks.log','Searching Contact url :'+str(url))
|
||||||
f.write('Searching Contact url :'+str(url)+'\n')
|
|
||||||
|
|
||||||
res = requests.get(url, auth=auth, headers=headers)
|
res = requests.get(url, auth=auth, headers=headers)
|
||||||
|
|
||||||
with open('braintreewebhooks.log', 'a') as f:
|
dologging('braintreewebhooks.log','Searching Contact Status code '+str(res.status_code)+'\n')
|
||||||
f.write('Searching Contact Status code '+str(res.status_code)+'\n')
|
|
||||||
|
|
||||||
if res.status_code != 200: # pragma: no cover
|
if res.status_code != 200: # pragma: no cover
|
||||||
return None
|
return None
|
||||||
|
|
||||||
with open('braintreewebhooks.log', 'a') as f:
|
dologging('braintreewebhooks.log','Status Code '+json.dumps(res.json())+'\n')
|
||||||
f.write('Status Code '+json.dumps(res.json())+'\n')
|
|
||||||
|
|
||||||
if len(res.json()) >= 1:
|
if len(res.json()) >= 1:
|
||||||
r = res.json()[0]
|
r = res.json()[0]
|
||||||
@@ -69,20 +67,17 @@ def create_contact(rower):
|
|||||||
"web": ""
|
"web": ""
|
||||||
}
|
}
|
||||||
|
|
||||||
with open('braintreewebhooks.log', 'a') as f:
|
dologging('braintreewebhooks.log','Creating fakturoid contact for '+str(rower.user.email)+'\n')
|
||||||
f.write('Creating fakturoid contact for '+str(rower.user.email)+'\n')
|
|
||||||
|
|
||||||
res = requests.post(contacts_url, data=json.dumps(
|
res = requests.post(contacts_url, data=json.dumps(
|
||||||
post_data), auth=auth, headers=headers)
|
post_data), auth=auth, headers=headers)
|
||||||
|
|
||||||
with open('braintreewebhooks.log', 'a') as f:
|
dologging('braintreewebhooks.log','Status Code '+str(res.status_code)+'\n')
|
||||||
f.write('Status Code '+str(res.status_code)+'\n')
|
|
||||||
|
|
||||||
if res.status_code not in [200, 201]: # pragma: no cover
|
if res.status_code not in [200, 201]: # pragma: no cover
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
with open('braintreewebhooks.log', 'a') as f:
|
dologging('braintreewebhooks.log','Contact ID'+str(res.json()['id'])+'\n')
|
||||||
f.write('Contact ID'+str(res.json()['id'])+'\n')
|
|
||||||
|
|
||||||
return res.json()['id']
|
return res.json()['id']
|
||||||
|
|
||||||
@@ -98,8 +93,7 @@ def create_invoice(rower, amount, braintreeid, dosend=True,
|
|||||||
if not name:
|
if not name:
|
||||||
name = 'Rowsandall Subscription'
|
name = 'Rowsandall Subscription'
|
||||||
|
|
||||||
with open('braintreewebhooks.log', 'a') as f:
|
dologging('braintreewebhooks.log','Creating invoice for contact iD '+str(contact_id)+'\n')
|
||||||
f.write('Creating invoice for contact iD '+str(contact_id)+'\n')
|
|
||||||
|
|
||||||
if not contact_id: # pragma: no cover
|
if not contact_id: # pragma: no cover
|
||||||
return 0
|
return 0
|
||||||
@@ -123,8 +117,7 @@ def create_invoice(rower, amount, braintreeid, dosend=True,
|
|||||||
|
|
||||||
res = requests.post(invoices_url, data=json.dumps(
|
res = requests.post(invoices_url, data=json.dumps(
|
||||||
post_data), auth=auth, headers=headers)
|
post_data), auth=auth, headers=headers)
|
||||||
with open('braintreewebhooks.log', 'a') as f:
|
dologging('braintreewebhooks.log','Invoice Created - status code '+str(res.status_code)+'\n')
|
||||||
f.write('Invoice Created - status code '+str(res.status_code)+'\n')
|
|
||||||
|
|
||||||
if res.status_code not in [200, 201]: # pragma: no cover
|
if res.status_code not in [200, 201]: # pragma: no cover
|
||||||
return 0
|
return 0
|
||||||
@@ -141,8 +134,7 @@ 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:
|
dologging('braintreewebhooks.log','Invoice Set to paid - status code ' +
|
||||||
f.write('Invoice Set to paid - status code ' +
|
|
||||||
str(res.status_code)+'\n')
|
str(res.status_code)+'\n')
|
||||||
|
|
||||||
if res.status_code not in [200, 201]: # pragma: no cover
|
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:
|
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:
|
dologging('braintreewebhooks.log','Invoice Sent - status code '+str(res.status_code)+'\n')
|
||||||
f.write('Invoice Sent - status code '+str(res.status_code)+'\n')
|
|
||||||
|
|
||||||
return id
|
return id
|
||||||
|
|
||||||
|
|||||||
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
Binary file not shown.
Reference in New Issue
Block a user