Private
Public Access
1
0
This commit is contained in:
Sander Roosendaal
2022-02-18 08:01:22 +01:00
parent ac9b541a28
commit f80dbdb4de

View File

@@ -72,8 +72,7 @@ def process_webhook(notification):
transactions = subscription.transactions
if transactions:
amount = int(transactions[0].amount)
eurocredits = credits.upgrade(amount, r)
eurocredits = credits.upgrade(amount, r)
_ = credits.upgrade(amount, r)
return send_invoice(notification.subscription)
if notification.kind == 'subscription_canceled':
subscription = notification.subscription
@@ -97,10 +96,7 @@ def process_webhook(notification):
def send_invoice(subscription):
with open('braintreewebhooks.log', 'a') as f:
t = time.localtime()
timestamp = time.strftime('%b-%d-%Y_%H%M', t)
f.write('Subscription ID '+str(subscription.id)+'\n')
dologging('braintreewebhooks.log', 'Subscription ID '+str(subscription.id))
subscription_id = subscription.id
rs = Rower.objects.filter(subscription_id=subscription_id)
if rs.count() == 0: # pragma: no cover
@@ -176,20 +172,6 @@ def get_client_token(rower):
return client_token
def get_plans_costs(): # pragma: no cover
plans = gateway.plan.all()
localplans = PaidPlan.object.filter(paymentprocessor='braintree')
for plan in localplans:
for btplan in btplans:
if int(btplan.id) == plan.external_id:
plan.price = float(x)
plan.save()
return plans
def make_payment(rower, data):
nonce_from_the_client = data['payment_method_nonce']
nonce = gateway.payment_method_nonce.find(nonce_from_the_client)
@@ -226,17 +208,11 @@ def make_payment(rower, data):
fakturoid_contact_id = fakturoid.get_contacts(rower)
if not fakturoid_contact_id:
fakturoid_contact_id = fakturoid.create_contact(rower)
id = fakturoid.create_invoice(rower, amount, transaction.id, dosend=True, contact_id=fakturoid_contact_id,
name=additional_text)
try:
job = myqueue(queuehigh, handle_send_email_transaction,
name, rower.user.email, amount)
job = myqueue(queuehigh, handle_send_email_transation_notification,
name.rower.user.email, amount, additional_text)
except: # pragma: no cover
pass
_ = fakturoid.create_invoice(rower, amount, transaction.id, dosend=True, contact_id=fakturoid_contact_id,
name=additional_text)
_ = myqueue(queuehigh, handle_send_email_transaction,
name, rower.user.email, amount)
return amount, True
else: # pragma: no cover
return 0, False
@@ -280,7 +256,7 @@ def update_subscription(rower, data, method='up'):
yesterday = (timezone.now()-datetime.timedelta(days=1)).date()
rower.paidplan = plan
amount_int = int(float(amount))
eurocredits = credits.upgrade(amount_int, rower)
_ = credits.upgrade(amount_int, rower)
rower.planexpires = result.subscription.billing_period_end_date
rower.teamplanexpires = result.subscription.billing_period_end_date
rower.clubsize = plan.clubsize
@@ -319,16 +295,16 @@ def update_subscription(rower, data, method='up'):
else: # pragma: no cover
amount = 0
job = myqueue(queuehigh,
handle_send_email_subscription_update,
name, rower.user.email,
plan.name,
plan.paymenttype,
plan.price,
amount,
result.subscription.billing_period_end_date.strftime(
'%Y-%m-%d'),
method)
_ = myqueue(queuehigh,
handle_send_email_subscription_update,
name, rower.user.email,
plan.name,
plan.paymenttype,
plan.price,
amount,
result.subscription.billing_period_end_date.strftime(
'%Y-%m-%d'),
method)
return True, amount
else: # pragma: no cover
@@ -352,12 +328,12 @@ def create_subscription(rower, data):
nonce_from_the_client = data['payment_method_nonce']
nonce = gateway.payment_method_nonce.find(nonce_from_the_client)
info = nonce.three_d_secure_info
paymenttype = nonce.type
# paymenttype = nonce.type
if nonce.type != 'PayPalAccount': # pragma: no cover
if info is None or not info.liability_shifted:
return False, 0
amount = data['amount']
# amount = data['amount']
planid = data['plan']
plan = PaidPlan.objects.get(id=planid)
@@ -399,7 +375,7 @@ def create_subscription(rower, data):
recurring = plan.paymenttype
job = myqueue(
_ = myqueue(
queuehigh,
handle_send_email_subscription_create,
name, rower.user.email,
@@ -420,18 +396,19 @@ def cancel_subscription(rower, id):
themessages = []
errormessages = []
try:
result = gateway.subscription.cancel(id)
_ = gateway.subscription.cancel(id)
themessages.append("Subscription canceled")
except: # pragma: no cover
errormessages.append(
"We could not find the subscription record in our customer database. We have notified the site owner, who will contact you.")
"We could not find the subscription record in our customer database."
" We have notified the site owner, who will contact you.")
name = '{f} {l}'.format(f=rower.user.first_name,
l=rower.user.last_name)
job = myqueue(queuehigh,
handle_send_email_failed_cancel,
name, rower.user.email, rower.user.username, id)
_ = myqueue(queuehigh,
handle_send_email_failed_cancel,
name, rower.user.email, rower.user.username, id)
return False, themessages, errormessages
@@ -510,15 +487,13 @@ def get_transactions(start_date, end_date): # pragma: no cover
dates = []
currencies = []
statuses = []
ids = []
# ids = []
usernames = []
customerids = []
transactionids = []
subscriptionids = []
ownids = []
countlines = [1 for transaction in results]
for transaction in results:
r = None
rs = Rower.objects.filter(