diff --git a/HISTORY.rst b/HISTORY.rst index 2995fdf36c..5ab037ebed 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -6,9 +6,12 @@ History 0.1.3 (2013-08-7) ++++++++++++++++++ +* Added account view * Added Customer.get_or_create method -* sync file for all code that keeps things in sync with stripe * Added djstripe_sync_customers management command +* sync file for all code that keeps things in sync with stripe +* Use client-side JavaScript to get history data asynchronously +* More user friendly action views 0.1.2 (2013-08-6) ++++++++++++++++++ diff --git a/djstripe/settings.py b/djstripe/settings.py index 4bd5a62b35..ad33e1c62a 100644 --- a/djstripe/settings.py +++ b/djstripe/settings.py @@ -65,6 +65,12 @@ def load_path_attr(path): "PAYMENTS_TRIAL_PERIOD_FOR_USER_CALLBACK", None ) +PLAN_LIST = [] +for p in settings.PAYMENTS_PLANS: + if settings.PAYMENTS_PLANS[p].get("stripe_plan_id"): + plan = settings.PAYMENTS_PLANS[p] + PLAN_LIST.append(plan) + if PY3: if isinstance(TRIAL_PERIOD_FOR_USER_CALLBACK, str): TRIAL_PERIOD_FOR_USER_CALLBACK = load_path_attr( diff --git a/djstripe/static/img/in-progress.gif b/djstripe/static/img/in-progress.gif new file mode 100644 index 0000000000..3288d1035d Binary files /dev/null and b/djstripe/static/img/in-progress.gif differ diff --git a/djstripe/templates/djstripe/account.html b/djstripe/templates/djstripe/account.html new file mode 100644 index 0000000000..b125173ef3 --- /dev/null +++ b/djstripe/templates/djstripe/account.html @@ -0,0 +1,67 @@ +{% extends "payments/base.html" %} + +{% block title %}Account{% endblock title %} + +{% block content %} + {{ block.super }} +
+
+
+

Account Information

+ {% include "djstripe/includes/_subscription_status.html" %} +
+
+
+
+

+ Credit Card on file. + Show card +

+
+
+

+ Next billed on {{ subscription.current_period_end }} + Update credit card +

+
+
+
+
+ + + + + + + + + + + + {% for plan in plans %} + + + + + + + {% endfor %} + +
PlanIntervalDescription
{{ plan.name }}{{ plan.interval.title }}ly{{ plan.description }}Your plan
+
+
+
+ + +{% endblock content %} + +{% block javascript %} +{{ block.super }} + +{% endblock javascript %} \ No newline at end of file diff --git a/djstripe/templates/djstripe/base.html b/djstripe/templates/djstripe/base.html index 5b74fa4e31..3488f4e470 100644 --- a/djstripe/templates/djstripe/base.html +++ b/djstripe/templates/djstripe/base.html @@ -1,41 +1,21 @@ {% extends "base.html" %} +{% load static %} {% block content %} -{% with customer.current_subscription as subscription %} - {% if subscription %} - {% if subscription.status == "active" %} -
- Your subscription will automatically renew in {{ subscription.current_period_end|timeuntil }}. + + {% endblock %} \ No newline at end of file diff --git a/djstripe/templates/djstripe/includes/_subscription_status.html b/djstripe/templates/djstripe/includes/_subscription_status.html new file mode 100644 index 0000000000..6a19808cda --- /dev/null +++ b/djstripe/templates/djstripe/includes/_subscription_status.html @@ -0,0 +1,31 @@ +{% if subscription %} + {% if subscription.status != "active" %} + {% if subscription.status == "trialing" %} + {% if request.user.customer.plan and request.user.customer.card_kind %} +
+ Your free trial will end in {{ subscription.current_period_end|timeuntil }} after which you commence a {{ subscription.plan_display }} plan. +
+ {% else %} +
+ Your free trial will end in {{ subscription.current_period_end|timeuntil }} after which you will need to get a subscription to continue using the site. +
+ {% endif %} + {% else %} + {% if subscription.status == "canceled" %} + {% if subscription.is_period_current %} +
+ Your subscription has been canceled but you can continue to use the site for another {{ subscription.current_period_end|timeuntil }}. +
+ {% else %} +
+ Your subscription has been canceled. +
+ {% endif %} + {% else %} +
+ Your subscription is {{ subscription.status }}. +
+ {% endif %} + {% endif %} + {% endif %} +{% endif %} diff --git a/djstripe/templates/djstripe/subscribe_form.html b/djstripe/templates/djstripe/subscribe_form.html index ff1fe7f733..6cf706c6ff 100644 --- a/djstripe/templates/djstripe/subscribe_form.html +++ b/djstripe/templates/djstripe/subscribe_form.html @@ -1,8 +1,9 @@ -{% extends "payments/base.html" %} +{% extends "djstripe/base.html" %} {% block title %}Subscription Form{% endblock title %} {% block content %} +{{ block.super }}

Subscription Form

{% if error %} @@ -22,6 +23,7 @@

Subscription Form

+ {% endblock content %} {% block javascript %} @@ -36,10 +38,9 @@

Subscription Form

token = function(res) { $form.find("input[name=stripe_token]").val(res.id); - // work on this for pure HTML edition. Or maybe JS edition? - //$(".main-content").hide(); - //$("div.progress").removeClass("hidden"); - //$('.progress-bar').animate({width:'+=100%'}, 2000); + $("button[type=submit]").attr("disabled", "true"); + $('#in-progress').modal({"keyboard": false}) + $('.progress-bar').animate({width:'+=100%'}, 2000); $form.trigger("submit"); }; diff --git a/djstripe/urls.py b/djstripe/urls.py index 72b2b8cb81..8d4dc1a56f 100644 --- a/djstripe/urls.py +++ b/djstripe/urls.py @@ -23,6 +23,11 @@ urlpatterns = patterns("", + url( + r"^$", + views.AccountView.as_view(), + name="account" + ), url( r"^subscribe/$", views.SubscribeFormView.as_view(), diff --git a/djstripe/views.py b/djstripe/views.py index 85c8af57f9..5f970f6121 100644 --- a/djstripe/views.py +++ b/djstripe/views.py @@ -20,6 +20,7 @@ from .models import Event from .models import EventProcessingException from .settings import PLAN_CHOICES +from .settings import PLAN_LIST from .settings import PY3 from .sync import sync_customer from .viewmixins import PaymentsContextMixin @@ -37,6 +38,7 @@ class SubscribeFormView( def get_context_data(self, *args, **kwargs): context = super(SubscribeFormView, self).get_context_data(**kwargs) context['is_plans_plural'] = bool(len(PLAN_CHOICES) > 1) + context['customer'], created = Customer.get_or_create(self.request.user) return context def post(self, request, *args, **kwargs): @@ -48,10 +50,7 @@ def post(self, request, *args, **kwargs): form = self.get_form(form_class) if form.is_valid(): try: - try: - customer = self.request.user.customer - except ObjectDoesNotExist: - customer = Customer.create(self.request.user) + customer, created = Customer.get_or_create(self.request.user) customer.update_card(self.request.POST.get("stripe_token")) customer.subscribe(form.cleaned_data["plan"]) except stripe.StripeError as e: @@ -118,3 +117,15 @@ def post(self, request, *args, **kwargs): "djstripe/includes/_history_table.html", {"customer": sync_customer(request.user)} ) + + +class AccountView(LoginRequiredMixin, SelectRelatedMixin, TemplateView): + template_name = "djstripe/account.html" + + def get_context_data(self, *args, **kwargs): + context = super(AccountView, self).get_context_data(**kwargs) + customer, created = Customer.get_or_create(self.request.user) + context['customer'] = customer + context['subscription'] = customer.current_subscription + context['plans'] = PLAN_LIST + return context