from django.contrib.auth.decorators import login_required
from annoying.decorators import ajax_request, render_to
from snipts.models import Snipt

import stripe

from settings_local import STRIPE_SECRET_KEY


@login_required
@render_to('account.html')
def account(request):
    return {}


@login_required
@ajax_request
def stripe_account_details(request):

    if request.user.profile.stripe_id is None:
        return {}
    else:
        stripe.api_key = STRIPE_SECRET_KEY
        customer = stripe.Customer.retrieve(request.user.profile.stripe_id)
        return {
            'last4': customer.active_card.last4,
            'created': customer.created,
            'email': customer.email,
            'amount': customer.subscription.plan.amount,
            'interval': customer.subscription.plan.interval,
            'name': customer.subscription.plan.name,
            'status': customer.subscription.status,
            'nextBill': customer.subscription.current_period_end,
        }


@login_required
@render_to('stats.html')
def stats(request):

    snipts = Snipt.objects.filter(user=request.user).order_by('-views')

    return {
        'snipts': snipts
    }

@@ -545,24 +545,25 @@
 ipe_id)%0A
+%0A
         
 return %7B
@@ -550,30 +550,30 @@
 d)%0A%0A        
-return
+data =
  %7B%0A         
@@ -702,20 +702,70 @@
     
-    
+%7D%0A%0A        if customer.subscription:%0A            data%5B
 'amount'
 : cu
@@ -760,17 +760,19 @@
 'amount'
-:
+%5D =
  custome
@@ -797,17 +797,16 @@
 n.amount
-,
 %0A       
@@ -810,16 +810,21 @@
         
+data%5B
 'interva
@@ -825,17 +825,19 @@
 nterval'
-:
+%5D =
  custome
@@ -864,17 +864,16 @@
 interval
-,
 %0A       
@@ -881,15 +881,22 @@
     
+data%5B
 'name'
-:
+%5D =
  cus
@@ -923,17 +923,16 @@
 lan.name
-,
 %0A       
@@ -940,16 +940,21 @@
     
+data%5B
 'status'
 : cu
@@ -949,17 +949,19 @@
 'status'
-:
+%5D =
  custome
@@ -981,17 +981,16 @@
 n.status
-,
 %0A       
@@ -994,16 +994,21 @@
         
+data%5B
 'nextBil
@@ -1009,17 +1009,19 @@
 extBill'
-:
+%5D =
  custome
@@ -1053,27 +1053,91 @@
 riod_end
-,%0A        %7D
+%0A        else:%0A            data%5B'status'%5D = 'inactive'%0A%0A        return data
 %0A%0A%0A@logi

Support non-subscriptions in billing.