Private
Public Access
1
0

Clearer message on user-passes-test

This commit is contained in:
Sander Roosendaal
2019-11-15 12:19:23 +01:00
parent 39c489b935
commit 4004b9a66d
3 changed files with 59 additions and 55 deletions

View File

@@ -20,7 +20,7 @@ from rowers.tasks import (
handle_send_email_subscription_create,
handle_send_email_failed_cancel,
)
import pandas as pd
from rowsandall_app.settings import (
@@ -70,7 +70,7 @@ def create_customer(rower,force=False):
else:
return rower.customer_id
def get_client_token(rower):
try:
@@ -79,10 +79,10 @@ def get_client_token(rower):
})
except ValueError:
customer_id = create_customer(rower,force=True)
client_token = gateway.client_token.generate({
"customer_id": customer_id,
})
})
return client_token
@@ -90,7 +90,7 @@ def get_plans_costs():
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:
@@ -108,7 +108,7 @@ def make_payment(rower,data):
amount = data['amount']
amount = '{amount:.f2}'.format(amount=amount)
result = gateway.transaction.sale({
"amount": amount,
"payment_method_nonce": nonce_from_the_client,
@@ -123,7 +123,7 @@ def make_payment(rower,data):
f = rower.user.first_name,
l = rower.user.last_name,
)
job = myqueue(queuehigh,handle_send_email_transaction,
name, rower.user.email, amount)
@@ -143,7 +143,7 @@ def update_subscription(rower,data,method='up'):
amount = data['amount']
amount = '{amount:.2f}'.format(amount=amount)
gatewaydata = {
"price": amount,
"plan_id": plan.external_id,
@@ -192,7 +192,7 @@ def update_subscription(rower,data,method='up'):
coachgroup.save()
rower.mycoachgroup = coachgroup
rower.save()
athletes = Rower.objects.filter(coachinggroups__in=[rower.mycoachgroup]).distinct()
for athlete in athletes:
athlete.coachinggroups.remove(rower.mycoachgroup)
@@ -217,7 +217,7 @@ def update_subscription(rower,data,method='up'):
amount,
result.subscription.billing_period_end_date.strftime('%Y-%m-%d'),
method)
return True,amount
else:
errors = result.errors.for_object("subscription")
@@ -230,12 +230,12 @@ def update_subscription(rower,data,method='up'):
if create_new:
return create_subscription(rower,data)
return False,0
return False,0
def create_subscription(rower,data):
nonce_from_the_client = data['payment_method_nonce']
nonce = gateway.payment_method_nonce.find(nonce_from_the_client)
@@ -249,8 +249,8 @@ def create_subscription(rower,data):
planid = data['plan']
plan = PaidPlan.objects.get(id=planid)
# create or find payment method
result = gateway.payment_method.create({
"customer_id": rower.customer_id,
@@ -270,6 +270,7 @@ def create_subscription(rower,data):
if result.is_success:
yesterday = (timezone.now()-datetime.timedelta(days=1)).date()
rower.paidplan = plan
rower.planexpires = result.subscription.billing_period_end_date
rower.teamplanexpires = result.subscription.billing_period_end_date
@@ -277,6 +278,8 @@ def create_subscription(rower,data):
rower.paymenttype = plan.paymenttype
rower.rowerplan = plan.shortname
rower.subscription_id = result.subscription.id
rower.protrialexpires = yesterday
rower.plantrialexpires = yesterday
rower.save()
name = '{f} {l}'.format(
@@ -286,7 +289,7 @@ def create_subscription(rower,data):
recurring = plan.paymenttype
job = myqueue(
queuehigh,
handle_send_email_subscription_create,
@@ -312,15 +315,15 @@ def cancel_subscription(rower,id):
themessages.append("Subscription canceled")
except:
errormessages.append("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)
return False, themessages, errormessages
basicplans = PaidPlan.objects.filter(price=0,paymentprocessor='braintree')
@@ -343,7 +346,7 @@ def find_subscriptions(rower):
raise ProcessorCustomerError("We could not find the customer in the database")
active_subscriptions = []
cards = result.credit_cards
for card in cards:
for subscription in card.subscriptions:
@@ -360,12 +363,12 @@ def find_subscriptions(rower):
pass
result = []
for subscription in active_subscriptions:
plan = PaidPlan.objects.filter(paymentprocessor="braintree",
external_id=subscription.plan_id)[0]
thedict = {
'end_date': subscription.billing_period_end_date,
'plan_id': subscription.plan_id,
@@ -444,7 +447,7 @@ def get_transactions(start_date,end_date):
transaction.credit_card_details.country_of_issuance)
statuses.append(transaction.status)
df = pd.DataFrame({
'name':names,
'email':emails,