|
|
@ -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,6 +102,8 @@ 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(lsub.data) > 0 :
|
|
|
|
lplans = [str(item['plan']['id']) for item in lsub.data if item.ended_at in [None,""]]
|
|
|
|
lplans = [str(item['plan']['id']) for item in lsub.data if item.ended_at in [None,""]]
|
|
|
|
x_plans = [item['id'] for item in plans]
|
|
|
|
x_plans = [item['id'] for item in plans]
|
|
|
|
|
|
|
|
|
|
|
@ -109,6 +117,7 @@ class User:
|
|
|
|
#
|
|
|
|
#
|
|
|
|
has_plan = False
|
|
|
|
has_plan = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if has_plan == False :
|
|
|
|
if has_plan == False :
|
|
|
|
r = self.subscribe(id,plans)
|
|
|
|
r = self.subscribe(id,plans)
|
|
|
|
lsub.data.append(r[0])
|
|
|
|
lsub.data.append(r[0])
|
|
|
@ -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,
|
|
|
|