|
|
|
@ -64,11 +64,11 @@ class User:
|
|
|
|
|
pass
|
|
|
|
|
# self.hasPlan(uid,plan)
|
|
|
|
|
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
|
|
|
|
|
#
|
|
|
|
|
customer['sources'] = str(self.stripeToken)
|
|
|
|
|
#customer['sources'] = str(self.stripeToken)
|
|
|
|
|
customer = self.stripe.Customer.create(
|
|
|
|
|
source=self.stripeToken,
|
|
|
|
|
email=uid
|
|
|
|
@ -81,6 +81,12 @@ class User:
|
|
|
|
|
has_plan = False
|
|
|
|
|
id = customer['id']
|
|
|
|
|
#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}
|
|
|
|
|
else:
|
|
|
|
|
#
|
|
|
|
@ -96,6 +102,8 @@ class User:
|
|
|
|
|
# We perform a set operation to determine if she is alread susbscribed
|
|
|
|
|
#
|
|
|
|
|
lsub = self.subscriptions()
|
|
|
|
|
|
|
|
|
|
if len(lsub.data) > 0 :
|
|
|
|
|
lplans = [str(item['plan']['id']) for item in lsub.data if item.ended_at in [None,""]]
|
|
|
|
|
x_plans = [item['id'] for item in plans]
|
|
|
|
|
|
|
|
|
@ -109,6 +117,7 @@ class User:
|
|
|
|
|
#
|
|
|
|
|
has_plan = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if has_plan == False :
|
|
|
|
|
r = self.subscribe(id,plans)
|
|
|
|
|
lsub.data.append(r[0])
|
|
|
|
@ -142,6 +151,7 @@ class User:
|
|
|
|
|
def subscribe(self,id,plans):
|
|
|
|
|
r = []
|
|
|
|
|
for plan in plans:
|
|
|
|
|
print ' --- >> ' plan
|
|
|
|
|
if self.stripeToken is None:
|
|
|
|
|
sub = self.stripe.Subscription.create(
|
|
|
|
|
customer=id,
|
|
|
|
|