bug fix with multiple signup

legacy
Steve L. Nyemba 6 years ago
parent dd2cf3196e
commit cd6ccf1b34

@ -37,6 +37,7 @@ class User :
if customer :
customer = [item for item in customer if item.email == uid]
customer = customer[0]
#
# Insure the product is the one we are looking for ...
args = dict(self.store)
@ -90,11 +91,13 @@ class User :
def post(self,**args):
document = dict(self.me,**{})
args = dict(self.store)
args['create'] = True
writer = CouchdbWriter(**args)
writer.set(document)
# writer.close()
def get_key(self,uid):
reader = CouchdbReader(**self.store)
@ -142,6 +145,26 @@ class User :
if not customer :
customer = self.stripe.Customer.create(email=uid)
self.update(_id=customer.id,emails=[uid])
elif not self.me['subscriptions']:
#
# We have a customer and subscription information that goes with it
#
mysub = {"plans":[]}
for rows in customer.subscriptions.data :
lsub = rows.items()
myplans = [ item[1]for item in lsub if 'plan' in item and item[1]['product'] == self.me['info']['id'] and item[1]['active'] ]
if myplans :
for plan in myplans :
plan['metadata'] = str(plan['metadata'])
self.me['subscriptions'] = {plan['nickname']: dict(plan)}
# print customer.subscriptions.data[0].items()]
# self.post(uid=customer.id)
# else:
# customer = customer
@ -157,7 +180,7 @@ class User :
info = {sub.plan.nickname:sub.plan}
self.update(subscriptions=info)
self.post()
self.post(uid=customer.id)
#
# keep a copy of this on our servers ...
#

@ -53,7 +53,9 @@ def init(product):
"""
uid = request.headers['uid']
plan_id = request.headers['pid'] if 'pid' in request.headers else None
user = User(stripe=stripe,store=CONFIG['couchdb'],product=product)
store = dict(CONFIG['couchdb'])
store['dbname'] = product
user = User(stripe=stripe,store=store,product=product)
user.subscribe(uid,plan_id)
sub = None

Loading…
Cancel
Save