fixes for upgrades
This commit is contained in:
@@ -18,6 +18,7 @@ from rowers.tasks import (
|
||||
from rowers.utils import myqueue
|
||||
import rowers.fakturoid as fakturoid
|
||||
from braintree.exceptions.invalid_signature_error import InvalidSignatureError
|
||||
from braintree.exceptions.not_found_error import NotFoundError
|
||||
import time
|
||||
import sys, traceback
|
||||
|
||||
@@ -73,8 +74,7 @@ def process_webhook(notification):
|
||||
subscription = notification.subscription
|
||||
rs = Rower.objects.filter(subscription_id=subscription.id)
|
||||
if rs.count() == 0: # pragma: no cover
|
||||
with open('braintreewebhooks.log', 'a') as f:
|
||||
f.write('Could not find rowers with subscription ID ' +
|
||||
dologging('braintreewebhooks.log','Could not find rowers with subscription ID ' +
|
||||
subscription.id+'\n')
|
||||
return 0
|
||||
r = rs[0]
|
||||
@@ -82,8 +82,7 @@ def process_webhook(notification):
|
||||
if result:
|
||||
dologging('braintreewebhooks.log','Subscription canceled {id}'.format(id=subscription.id))
|
||||
return subscription.id
|
||||
with open('braintreewebhooks.log', 'a') as f: # pragma: no cover
|
||||
f.write('Could not cancel Subscription: ' +
|
||||
dologging('braintreewebhooks.log','Could not cancel Subscription: ' +
|
||||
str(subscription.id)+'\n')
|
||||
return 0 # pragma: no cover
|
||||
if notification.kind == 'subscription_charged_unsuccessfully':
|
||||
@@ -112,21 +111,17 @@ def send_invoice(subscription):
|
||||
return 0
|
||||
else:
|
||||
r = rs[0]
|
||||
with open('braintreewebhooks.log', 'a') as f:
|
||||
f.write('Rower '+str(r)+'\n')
|
||||
dologging('braintreewebhooks.log','Rower '+str(r)+'\n')
|
||||
fakturoid_contact_id = fakturoid.get_contacts(r)
|
||||
with open('braintreewebhooks.log', 'a') as f:
|
||||
f.write('Fakturoid Contact ID '+str(fakturoid_contact_id)+'\n')
|
||||
dologging('braintreewebhooks.log','Fakturoid Contact ID '+str(fakturoid_contact_id)+'\n')
|
||||
if not fakturoid_contact_id: # pragma: no cover
|
||||
fakturoid_contact_id = fakturoid.create_contact(r)
|
||||
with open('braintreewebhooks.log', 'a') as f:
|
||||
f.write('Created Fakturoid Contact ID ' +
|
||||
dologging('braintreewebhooks.log','Created Fakturoid Contact ID ' +
|
||||
str(fakturoid_contact_id)+'\n')
|
||||
transactions = subscription.transactions
|
||||
if transactions:
|
||||
amount = transactions[0].amount
|
||||
with open('braintreewebhooks.log', 'a') as f:
|
||||
f.write('Transaction amount '+str(amount)+'\n')
|
||||
dologging('braintreewebhooks.log','Transaction amount '+str(amount)+'\n')
|
||||
id = fakturoid.create_invoice(r, amount, subscription_id, dosend=True,
|
||||
contact_id=fakturoid_contact_id)
|
||||
return id
|
||||
@@ -261,6 +256,10 @@ def update_subscription(rower, data, method='up'):
|
||||
rower.subscription_id,
|
||||
gatewaydata
|
||||
)
|
||||
except NotFoundError:
|
||||
rower.subscription_id = None
|
||||
rower.save()
|
||||
return create_subscription(rower, data)
|
||||
except BaseException as e: # pragma: no cover
|
||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||
dologging('braintree.log','Payment failed with error')
|
||||
|
||||
Reference in New Issue
Block a user