diff --git a/rowers/braintreestuff.py b/rowers/braintreestuff.py index 2b36a91f..a7372f93 100644 --- a/rowers/braintreestuff.py +++ b/rowers/braintreestuff.py @@ -115,6 +115,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, @@ -124,16 +125,19 @@ def update_subscription(rower,data,method='up'): }, } + if plan.paymenttype == 'single': gatewaydata['number_of_billing_cycles'] = 1 else: gatewaydata['never_expires'] = True - - result = gateway.subscription.update( - rower.subscription_id, - gatewaydata - ) + try: + result = gateway.subscription.update( + rower.subscription_id, + gatewaydata + ) + except: + return False if result.is_success: rower.paidplan = plan @@ -164,7 +168,7 @@ def update_subscription(rower,data,method='up'): handle_send_email_subscription_update, name, rower.user.email, plan.name, - plan.paymenttype == 'recurring', + plan.paymenttype, plan.price, amount, result.subscription.billing_period_end_date.strftime('%Y-%m-%d'), @@ -225,7 +229,7 @@ def create_subscription(rower,data): ) - recurring = plan.paymenttype == 'recurring', + recurring = plan.paymenttype job = myqueue( queuehigh, @@ -268,6 +272,7 @@ def cancel_subscription(rower,id): rower.planexpires = timezone.now() rower.clubsize = 0 rower.rowerplan = 'basic' + rower.subscription_id = None rower.save() themessages.append("Your plan was reset to basic") @@ -309,7 +314,8 @@ def find_subscriptions(rower): 'plan_id': subscription.plan_id, 'price': subscription.price, 'id': subscription.id, - 'plan': plan.name + 'plan': plan.name, + 'never_expires': subscription.never_expires } result.append(thedict) diff --git a/rowers/tasks.py b/rowers/tasks.py index 784ad55a..ece7a6a6 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -852,6 +852,7 @@ def handle_send_email_subscription_create( from_email = 'Rowsandall ' + d = { 'name': username, 'siteurl': siteurl, diff --git a/rowers/templates/subscription_create_email.html b/rowers/templates/subscription_create_email.html index c312a6b1..63c70e90 100644 --- a/rowers/templates/subscription_create_email.html +++ b/rowers/templates/subscription_create_email.html @@ -8,7 +8,7 @@ subscription to the Rowsandall paid plan "{{ planname }}".

-{% if recurring %} +{% if recurring=='recurring' %}

Your next charge is due on {{ end_of_billing_period }}. We will charge your {{ paymentmethod }} on that date. diff --git a/rowers/templates/subscription_create_notification.html b/rowers/templates/subscription_create_notification.html index 89c0ebf1..bcf19cc7 100644 --- a/rowers/templates/subscription_create_notification.html +++ b/rowers/templates/subscription_create_notification.html @@ -7,7 +7,7 @@ New plan: "{{ planname }}".

-{% if recurring %} +{% if recurring=='recurring'%}

The subscription cost is €{{ price }} per year. The next charge is due on {{ end_of_billing_period }}. diff --git a/rowers/templates/subscription_downgrade_email.html b/rowers/templates/subscription_downgrade_email.html index 789b48ae..579ab8ce 100644 --- a/rowers/templates/subscription_downgrade_email.html +++ b/rowers/templates/subscription_downgrade_email.html @@ -7,7 +7,7 @@ Thank you. You have successfully changed your plan to "{{ planname }}".

-{% if recurring %} +{% if recurring=='recurring' %}

The subscription cost is €{{ price }} per year. Your next charge is due on {{ end_of_billing_period }}. We will charge you automatically diff --git a/rowers/templates/subscription_downgrade_notification.html b/rowers/templates/subscription_downgrade_notification.html index 6fb0589d..a0a95257 100644 --- a/rowers/templates/subscription_downgrade_notification.html +++ b/rowers/templates/subscription_downgrade_notification.html @@ -7,7 +7,7 @@ New plan: "{{ planname }}".

-{% if recurring %} +{% if recurring=='recurring' %}

The subscription cost is €{{ price }} per year. The next charge is due on {{ end_of_billing_period }}. diff --git a/rowers/templates/subscription_update_email.html b/rowers/templates/subscription_update_email.html index c50e1b08..d805d0d5 100644 --- a/rowers/templates/subscription_update_email.html +++ b/rowers/templates/subscription_update_email.html @@ -9,7 +9,7 @@ You are now on the Rowsandall paid plan "{{ planname }}".

-{% if recurring %} +{% if recurring=='recurring' %}

The subscription cost is €{{ price }} per year. Your next charge is due on {{ end_of_billing_period }}. We will charge you automatically diff --git a/rowers/templates/subscription_update_notification.html b/rowers/templates/subscription_update_notification.html index ce72fe97..26f1f392 100644 --- a/rowers/templates/subscription_update_notification.html +++ b/rowers/templates/subscription_update_notification.html @@ -7,7 +7,7 @@ New plan: "{{ planname }}".

-{% if recurring %} +{% if recurring=='recurring' %}

The subscription cost is €{{ price }} per year. The next charge is due on {{ end_of_billing_period }}. diff --git a/rowers/templates/subscriptions_cancel.html b/rowers/templates/subscriptions_cancel.html index aa360f37..2419c07b 100644 --- a/rowers/templates/subscriptions_cancel.html +++ b/rowers/templates/subscriptions_cancel.html @@ -12,7 +12,8 @@ - + + @@ -27,6 +28,13 @@ +
SubscriptionNext Billing DatePrice SubscriptionPaid UntilPriceSubscription type 
{{ subscription|lookup:"price" }} € + {% if subscription|lookup:"never_expires" %} + Recurring + {% else %} + Not recurring + {% endif %} + Stop this plan