diff --git a/media/js/src/application.js b/media/js/src/application.js index 08a9ae7..88ada6d 100644 --- a/media/js/src/application.js +++ b/media/js/src/application.js @@ -23,6 +23,14 @@ jQuery(function($) { var pre = $pres.eq(i); pre.width(pre.parents('section.code').width() - 30); }); + + $('form#cancel-team-subscription').submit(function() { + if (confirm('Are you sure you want to cancel your subscription?\n\nYou will no longer be able to create new Snipts under this team. This action is effective immediately and we unfortunately cannot issue any refunds.')) { + return true; + } else { + return false; + } + }); }); // Angular app init. diff --git a/media/js/src/team.js b/media/js/src/team.js index 3348575..988b7f1 100644 --- a/media/js/src/team.js +++ b/media/js/src/team.js @@ -23,6 +23,7 @@ if (typeof angular !== 'undefined') { // Controllers. controllers.TeamController = function($scope, $timeout, TeamStorage) { $scope.users = []; + $scope.search = ''; $scope.$watch('search', function(val) { $timeout.cancel($scope.timeout); diff --git a/snipts/templates/snipts/list.html b/snipts/templates/snipts/list.html index 8687133..259a240 100644 --- a/snipts/templates/snipts/list.html +++ b/snipts/templates/snipts/list.html @@ -12,6 +12,11 @@ {% endblock %} {% block content %} + {% if 'team-cancelled' in request.GET %} +
+ Your team plan has been succesfully cancelled. +
+ {% endif %}
- 25 users + {{ name }}
- $49.00 USD / month + ${{ amount|currency_convert }}.00 USD / {{ interval }}
- xxxx-xxxx-xxxx-4242 + xxxx-xxxx-xxxx-{{ last4 }}
- Active + {{ status }}
- August 29, 2015 + {{ team.created|date:'M d, Y' }}
- November 29, 2015 + {{ nextBill|to_date|date:'M d, Y' }}
-

- Cancel subscription -

+
+ {% csrf_token %} + +
{% endblock %} diff --git a/teams/templatetags/team_tags.py b/teams/templatetags/team_tags.py index 2d1f81e..98d16a8 100644 --- a/teams/templatetags/team_tags.py +++ b/teams/templatetags/team_tags.py @@ -1,3 +1,5 @@ +import datetime + from django import template register = template.Library() @@ -6,3 +8,13 @@ register = template.Library() @register.filter def user_is_member(team, user): return team.user_is_member(user) + + +@register.filter +def currency_convert(amount): + return amount / 100 + + +@register.filter +def to_date(timestamp): + return datetime.datetime.fromtimestamp(float(timestamp)) diff --git a/teams/urls.py b/teams/urls.py index 6f0296f..aa157e6 100644 --- a/teams/urls.py +++ b/teams/urls.py @@ -17,4 +17,7 @@ urlpatterns = \ name='team-members'), url(r'^(?P[^/]+)/billing/$', views.team_billing, - name='team-billing')) + name='team-billing'), + url(r'^(?P[^/]+)/billing/cancel/$', + views.cancel_team_subscription, + name='team-cancel-subscription')) diff --git a/teams/views.py b/teams/views.py index 7e4389b..be3763f 100644 --- a/teams/views.py +++ b/teams/views.py @@ -20,12 +20,76 @@ def for_teams(request): return {} +@login_required +@render_to('teams/for-teams-complete.html') +def for_teams_complete(request): + if request.method == 'POST' and request.user.is_authenticated(): + + token = request.POST['token'] + stripe.api_key = os.environ.get('STRIPE_SECRET_KEY', + settings.STRIPE_SECRET_KEY) + + plan = request.POST['plan'] + + try: + customer = stripe.Customer.create(card=token, + plan=plan, + email=request.user.email) + except stripe.CardError, e: + error_message = e.json_body['error']['message'] + return HttpResponseRedirect('/for-teams/?declined=%s' % + error_message or + 'Your card was declined.') + + team = Team(name=request.POST['team-name'], + email=request.POST['email'], + plan=plan, + owner=request.user) + team.stripe_id = customer.id + team.save() + + user = User.objects.create_user(team.slug, + team.email, + str(uuid.uuid4())) + + team.user = user + team.save() + + return { + 'team': team + } + else: + return HttpResponseBadRequest() + + @login_required @render_to('teams/team-billing.html') def team_billing(request, username): team = get_object_or_404(Team, slug=username, disabled=False) if team.owner != request.user: raise Http404 + + stripe.api_key = os.environ.get('STRIPE_SECRET_KEY', + settings.STRIPE_SECRET_KEY) + customer = stripe.Customer.retrieve(team.stripe_id) + + data = { + 'last4': customer.active_card.last4, + 'created': customer.created, + 'email': customer.email, + 'team': team + } + + if customer.subscription: + data['amount'] = customer.subscription.plan.amount + data['interval'] = customer.subscription.plan.interval + data['name'] = customer.subscription.plan.name + data['status'] = customer.subscription.status + data['nextBill'] = customer.subscription.current_period_end + else: + data['status'] = 'inactive' + + return data return { 'team': team } @@ -72,42 +136,22 @@ def remove_team_member(request, username, member): @login_required -@render_to('teams/for-teams-complete.html') -def for_teams_complete(request): - if request.method == 'POST' and request.user.is_authenticated(): +def cancel_team_subscription(request, username): - token = request.POST['token'] - stripe.api_key = os.environ.get('STRIPE_SECRET_KEY', - settings.STRIPE_SECRET_KEY) + if request.method != 'POST': + raise Http404 - plan = request.POST['plan'] + team = get_object_or_404(Team, slug=username, disabled=False) + if team.owner != request.user: + raise Http404 - try: - customer = stripe.Customer.create(card=token, - plan=plan, - email=request.user.email) - except stripe.CardError, e: - error_message = e.json_body['error']['message'] - return HttpResponseRedirect('/for-teams/?declined=%s' % - error_message or - 'Your card was declined.') + stripe.api_key = os.environ.get('STRIPE_SECRET_KEY', + settings.STRIPE_SECRET_KEY) + customer = stripe.Customer.retrieve(team.stripe_id) + customer.delete() - team = Team(name=request.POST['team-name'], - email=request.POST['email'], - plan=plan, - owner=request.user) - team.stripe_id = customer.id - team.save() + team.disabled = True + team.stripe_id = None + team.save() - user = User.objects.create_user(team.slug, - team.email, - str(uuid.uuid4())) - - team.user = user - team.save() - - return { - 'team': team - } - else: - return HttpResponseBadRequest() + return HttpResponseRedirect('/' + team.slug + '/?team-cancelled=true') diff --git a/templates/ad-leaderboard-pro.html b/templates/ad-leaderboard-pro.html index abf2936..56f50bd 100644 --- a/templates/ad-leaderboard-pro.html +++ b/templates/ad-leaderboard-pro.html @@ -1,4 +1,4 @@ - Sign up for Snipt!
Post public snipts for free. Private snipts just $5/mo. + Sign up for Snipt!
Post public snipts for free.