From cd6ccf1b34925b744ba1cea4729f197992700765 Mon Sep 17 00:00:00 2001 From: Steve Nyemba Date: Wed, 23 Jan 2019 15:15:53 -0600 Subject: [PATCH] bug fix with multiple signup --- src/api/User.py | 25 ++++++++++++++++++++++++- src/api/index.py | 4 +++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/api/User.py b/src/api/User.py index a6ec545..1bbd569 100644 --- a/src/api/User.py +++ b/src/api/User.py @@ -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 ... # diff --git a/src/api/index.py b/src/api/index.py index 71e614d..a74f99e 100755 --- a/src/api/index.py +++ b/src/api/index.py @@ -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