From cd14d6a4cf6c0747b980688c7979dac9555c828b Mon Sep 17 00:00:00 2001 From: "Steve L. Nyemba" Date: Mon, 24 Apr 2017 12:03:27 -0500 Subject: [PATCH] bug fix around endpoint --- src/Domain.py | 15 +++------------ src/api/index.py | 34 ++++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/Domain.py b/src/Domain.py index 30179b9..8028aca 100644 --- a/src/Domain.py +++ b/src/Domain.py @@ -64,23 +64,14 @@ class User: has_plan = False - - # lsub = lsub.data - # - # At this point We should either subscribe the user or not - # - if has_plan == False : r = self.subscribe(id,plans) lsub.data.append(r[0]) - - lsub = self.cast(lsub.data) - - # - # We need to save the document & the information # - + # Backing up the information to be processed later + # - We assume any interaction with the payment classes will start by updating information associated operation + lsub = self.cast(lsub.data) self.user['subscriptions'] = lsub self.db.save_doc(self.user) def subscriptions(self): diff --git a/src/api/index.py b/src/api/index.py index 93e5ac6..6404592 100644 --- a/src/api/index.py +++ b/src/api/index.py @@ -102,18 +102,28 @@ def cancel_subscribe(name) : This function defines if a given user is a customer or not We should be able to tell by how we create customers """ -@app.route('/checkout',methods=['GET']) -def is_customer (): - bill = {"amount":0,"count":0} - key = "" - if 'user-plans' in session : - plans = session['user-plans'] ; - amount = [plan['amount'] for plan in plans if plan['amount'] > 0] - if len(amount) > 0: - key = CONFIG['stripe']['pub'].strip() - bill['count'] = len(amount) - bill['amount']= sum(amount) - return render_template('checkout.html',bill=bill,key=key) +@app.route('/checkout/',methods=['GET']) +def is_customer (app_name): + uid = request.args.get('uid') + pid = request.args.get('pid') + couchdb = CouchdbReader(uri=CONFIG['couchdb']['uri'],dbname=app_name,uid=uid,create=False) + info = couchdb.read() + lsub = info['subscriptions'] + + plans = [dict(item['plan'],**{"status":item['status']}) for item in lsub] + if pid is not None: + plans = [item for item in plans if item['id'] == pid] + # bill = {"amount":0,"count":0} + # key = "" + # if 'user-plans' in session : + # plans = session['user-plans'] ; + # amount = [plan['amount'] for plan in plans if plan['amount'] > 0] + # if len(amount) > 0: + # key = CONFIG['stripe']['pub'].strip() + # bill['count'] = len(amount) + # bill['amount']= sum(amount) + amount = sum([item['amount'] for item in plans])/100 + return render_template('bill.html',app_name=app_name.replace('-',' '),plans=plans,key=None,total_amount=amount) """ This function is intended to performa an actual payment """