diff --git a/src/api/index.py b/src/api/index.py index 6404592..936fc0c 100644 --- a/src/api/index.py +++ b/src/api/index.py @@ -110,9 +110,16 @@ def is_customer (app_name): info = couchdb.read() lsub = info['subscriptions'] - plans = [dict(item['plan'],**{"status":item['status']}) for item in lsub] + plans = [dict(dict(item['plan'],**{"status":item['status']}),**{"subscription":item['id']}) for item in lsub] if pid is not None: plans = [item for item in plans if item['id'] == pid] + # + # Caching the subscription identifiers so we can create an invoice later on (if need be) + # @TODO Improve this process later on by allowing user's to pay for what they can (not everything) + # + session['plans'] = plans + + # bill = {"amount":0,"count":0} # key = "" # if 'user-plans' in session : @@ -122,8 +129,28 @@ def is_customer (app_name): # 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) + html = """ +
+ +
+ """ + session['plans'] + amount = sum([item['amount'] for item in plans]) + apikey = CONFIG['stripe']['pub'].strip() + html = html.replace(":email",uid).replace(":amount",str(amount)).replace(":key",apikey) + amount = amount / 100 + return render_template('bill.html',apikey=apikey,app_name=app_name.replace('-',' '),plans=plans,total_amount=amount,html=html) """ This function is intended to performa an actual payment """ @@ -133,9 +160,13 @@ def pay(): token = request.form['stripeToken'] uid = request.form['stripeEmail'] tokenType = request.form['stripeTokenType'] - - DB = COUCHDB.get_db(CONFIG['couchdb']['db']) ; + couchdb = CouchdbReader(uri=CONFIG['couchdb']['uri'],dbname=app_name,uid=uid,create=False) + DB = couchdb.dbase #COUCHDB.get_db(CONFIG['couchdb']['db']) ; handler = Domain.User(DB,stripe) ; + plans = session['plans'] + # Assuming all is fine, we must do the following at this point + # - create an invoice with the designated subscriptions + # - create a charge on the invoice # # Let's insure the preconditions are met i.e # card,invoice diff --git a/src/api/static/img/logo-0.png b/src/api/static/img/logo-0.png new file mode 100644 index 0000000..bcc6a63 Binary files /dev/null and b/src/api/static/img/logo-0.png differ diff --git a/src/api/templates/bill.html b/src/api/templates/bill.html index 3aa6e8a..fd77ac2 100644 --- a/src/api/templates/bill.html +++ b/src/api/templates/bill.html @@ -43,7 +43,7 @@ } @media only screen and (min-device-width: 768px){ body {font-size:12px} - table {width:70%; margin-left:15%} + table {width:60%; margin-left:20%} } @@ -55,7 +55,7 @@
- +
The Phi Technology
{{ app_name }}
@@ -87,9 +87,11 @@ {% endfor %} - Amount Due $ {{ total_amount }} + Amount Due $ {{ total_amount }} - Purchase + + {{html|safe}} +