bug fix with initial setup

legacy
Steve L. Nyemba 8 years ago
parent 620cb151f1
commit 70928ace4c

@ -64,11 +64,11 @@ class User:
pass pass
# self.hasPlan(uid,plan) # self.hasPlan(uid,plan)
has_plan = True has_plan = True
if self.user is None and plans and stripe : if id is None :
# #
# First time customer, register them and sign them up for the first plan # First time customer, register them and sign them up for the first plan
# #
customer['sources'] = str(self.stripeToken) #customer['sources'] = str(self.stripeToken)
customer = self.stripe.Customer.create( customer = self.stripe.Customer.create(
source=self.stripeToken, source=self.stripeToken,
email=uid email=uid
@ -81,6 +81,12 @@ class User:
has_plan = False has_plan = False
id = customer['id'] id = customer['id']
#self.user = {"_id":uid,"id":id,"source":self.stripeToken} #self.user = {"_id":uid,"id":id,"source":self.stripeToken}
#
# At this point we have a new user and a plan identifier
# We formt the plan as it is given to us as a string ... later will be subscribed.
#
plans = [{"id":plans}]
self.user = {"_id":id,"emails":[uid],"source":self.stripeToken} self.user = {"_id":id,"emails":[uid],"source":self.stripeToken}
else: else:
# #
@ -96,18 +102,21 @@ class User:
# We perform a set operation to determine if she is alread susbscribed # We perform a set operation to determine if she is alread susbscribed
# #
lsub = self.subscriptions() lsub = self.subscriptions()
lplans = [str(item['plan']['id']) for item in lsub.data if item.ended_at in [None,""]]
x_plans = [item['id'] for item in plans]
if lplans and not set(x_plans) - set(lplans) : if len(lsub.data) > 0 :
has_plans = False lplans = [str(item['plan']['id']) for item in lsub.data if item.ended_at in [None,""]]
x = list(set(x_plans) - set(lplans)) x_plans = [item['id'] for item in plans]
plans = [ item for item in plans if item.id in x]
else: if lplans and not set(x_plans) - set(lplans) :
# has_plans = False
# In case the user doesn't have any plans with us x = list(set(x_plans) - set(lplans))
# plans = [ item for item in plans if item.id in x]
has_plan = False else:
#
# In case the user doesn't have any plans with us
#
has_plan = False
if has_plan == False : if has_plan == False :
r = self.subscribe(id,plans) r = self.subscribe(id,plans)
@ -142,6 +151,7 @@ class User:
def subscribe(self,id,plans): def subscribe(self,id,plans):
r = [] r = []
for plan in plans: for plan in plans:
print ' --- >> ' plan
if self.stripeToken is None: if self.stripeToken is None:
sub = self.stripe.Subscription.create( sub = self.stripe.Subscription.create(
customer=id, customer=id,

@ -40,7 +40,7 @@ def init(app_name):
if 'uid' in request.headers: if 'uid' in request.headers:
uid = request.headers['uid'] uid = request.headers['uid']
plan= request.headers['pid'] plan= request.headers['pid']
couchdb = Couchdb(uri=CONFIG['couchdb']['uri'],dbname=app_name,uid=None) couchdb = Couchdb(uri=CONFIG['couchdb']['uri'],dbname=app_name,uid=uid)
DB = couchdb.dbase DB = couchdb.dbase
handler = Domain.User(DB,stripe) ; handler = Domain.User(DB,stripe) ;
if 'customer.id' not in session : if 'customer.id' not in session :

Loading…
Cancel
Save