legacy
Steve L. Nyemba 5 years ago
parent 9f6c896ff0
commit 60bbaab3a9

@ -17,7 +17,7 @@ from flask_cors import CORS
# from couchdbkit import Server, Document # from couchdbkit import Server, Document
import stripe import stripe
import json import json
from StringIO import StringIO # from StringIO import StringIO
import re import re
import os import os
from utils.params import PARAMS from utils.params import PARAMS
@ -66,10 +66,20 @@ def get_plans_json(id):
# Log this shit or not # Log this shit or not
pass pass
return "[]",HEADER return "[]",HEADER
@app.route("/ui/signup/<id>") @app.route("/signup",methods=['GET','POST'])
def get_stripe():
if request.method == 'GET' :
_object = {"data-key":CONFIG['stripe']['pub'].strip()}
return json.dumps(_object)
else:
print (request.args)
return 1
@app.route("/ui/signup/<id>",methods=['GET','PUT'])
def signup(id): def signup(id):
""" """
""" """
mystore = store.factory.instance(name=id) mystore = store.factory.instance(name=id)
plans = mystore.get.plans() plans = mystore.get.plans()
index = int(request.args['index']) index = int(request.args['index'])
@ -77,6 +87,8 @@ def signup(id):
args = {"product":id,"label":mystore.product['statement_descriptor'],"plan":plan,"context":CONTEXT,"now":datetime.now().year} args = {"product":id,"label":mystore.product['statement_descriptor'],"plan":plan,"context":CONTEXT,"now":datetime.now().year}
args['theme'] = 'theme-clouds' args['theme'] = 'theme-clouds'
args['cloud-view'] = CONFIG['cloud-view']
return render_template("signup.html",**args) return render_template("signup.html",**args)
@app.route("/ui/<id>") @app.route("/ui/<id>")
def get_plans_ui(id): def get_plans_ui(id):
@ -88,7 +100,8 @@ def get_plans_ui(id):
label = mystore.product['statement_descriptor'] label = mystore.product['statement_descriptor']
args = {"product":id,"label":label,"description":description,"context":CONTEXT,"plans":mystore.get.plans(),"now":datetime.now().year} args = {"product":id,"label":label,"description":description,"context":CONTEXT,"plans":mystore.get.plans(),"now":datetime.now().year}
args['theme'] = 'theme-clouds' args['theme'] = 'theme-clouds'
print (mystore.product.keys()) # print (mystore.product.keys())
session['cloud-view'] = CONFIG['cloud-view']
return render_template('plans.html',**args) return render_template('plans.html',**args)
@app.route("/init/<product>",methods=['POST']) @app.route("/init/<product>",methods=['POST'])
def init(product): def init(product):
@ -106,31 +119,42 @@ def init(product):
# #
# We should just pull the factory method and get a storage handler to handle the logs # We should just pull the factory method and get a storage handler to handle the logs
# #
store = dict(CONFIG['couchdb']) # store = dict(CONFIG['couchdb'])
store['dbname'] = product # store['dbname'] = product
user = User(stripe=stripe,store=store,product=product) # user = User(stripe=stripe,store=store,product=product)
user.subscribe(uid,plan_id) # user.subscribe(uid,plan_id)
sub = None # sub = None
if 'auid' in request.headers : # if 'auid' in request.headers :
auid = request.headers['auid'] # auid = request.headers['auid']
user.update(emails=auid) # user.update(emails=auid)
user.post() # user.post()
store = dict(CONFIG['couchdb'],**{}) # store = dict(CONFIG['couchdb'],**{})
store['dbname'] = product # store['dbname'] = product
store['uid'] = 'logs' # store['uid'] = 'logs'
sub = user.get(uid,'subscriptions') # sub = user.get(uid,'subscriptions')
features = {} # features = {}
for id in sub : # for id in sub :
if sub[id]['active'] is True : # if sub[id]['active'] is True :
features[id] = sub[id] # features[id] = sub[id]
user.refresh(uid) # user.refresh(uid)
session['key'] = user.user_key # session['key'] = user.user_key
session['uid'] = uid # session['uid'] = uid
mystore = store.factory.instance(name=product,email=uid)
user = mystore.user
user.init (uid)
if not user.plan.info() :
mystore.plan.subscribe(email = user.info()['email'])
features = user.plan.info()['metadata']['features'] if 'features' in user.plan.info()['metadata'] else {}
print (features)
return json.dumps(features),200 return json.dumps(features),200
@ -175,7 +199,7 @@ def subscribe(product):
session['key'] = user.user_key session['key'] = user.user_key
session['uid'] = uid session['uid'] = uid
session['active-plans'] = [item['id'] for item in plans] session['active-plans'] = [item['id'] for item in plans]
print session['active-plans'] print (session['active-plans'])
return (json.dumps(plans),200) return (json.dumps(plans),200)
def get_plans(product) : def get_plans(product) :
@ -323,3 +347,4 @@ if __name__ == '__main__' :
app.config['MAX_CONTENT_LENGTH'] = 1600 * 1024 * 1024 app.config['MAX_CONTENT_LENGTH'] = 1600 * 1024 * 1024
app.run(port=PORT,threaded=True,host='0.0.0.0') app.run(port=PORT,threaded=True,host='0.0.0.0')
# app.run() #'0.0.0.0',PORT,True,threaded=True)

@ -0,0 +1,20 @@
appdirs==1.4.3
click==6.7
couchdbkit==0.6.5
Flask==0.12.1
Flask-Cors==3.0.6
http-parser==0.8.3
itsdangerous==0.24
Jinja2==2.9.6
MarkupSafe==1.0
numpy==1.12.1
packaging==16.8
pika==0.10.0
pyparsing==2.2.0
requests==2.13.0
restkit==4.2.2
six==1.10.0
socketpool==0.5.3
stripe==1.82.1
Werkzeug==0.12.1
git+https://dev.the-phi.com/git/steve/data-transport.git

@ -1 +1,2 @@
class void :
pass

@ -1,4 +1,5 @@
from api.store import Store # from api.store import Store, factory
import api.store as store
import unittest import unittest
import json import json
import stripe import stripe
@ -9,22 +10,68 @@ class TestStore(unittest.TestCase):
def test_getPlans(self): def test_getPlans(self):
mystore = Store(product='music') mystore = store.factory.instance(name='music')
self.assertTrue(mystore.get.plans()) self.assertTrue(mystore.get.plans())
pass
def test_getProducts(self):
mystore = store.factory.instance(name='smart-top')
self.assertTrue(mystore.get.products())
def test_getUser(self): def test_getUser(self):
""" """
""" """
email='nyemba@gmail.com' email='nyemba@gmail.com'
mystore = Store(product='music') mystore = store.factory.instance(name='music',email=email)
self.assertTrue(mystore.get.user(email='nyemba@gmail.com')) # mystore.init('nyemba@gmail.com')
# self.assertTrue(mystore.get.user.info())
user = mystore.user
user.init(email)
self.assertTrue(user.info())
def test_UserPlan(self): def test_UserPlan(self):
""" """
For a given product we would like to know what our user's plan is For a given product we would like to know what our user's plan is
""" """
email = 'nyemba@gmail.com' email = 'nyemba@gmail.com'
mystore = Store(product='music') mystore = store.factory.instance(name='music',email=email)
print(mystore.get.plans(email=email))['id'] user = mystore.user
user.init (email)
user.plan.info()
def _test_CancelUserPlan(self) :
email = 'nyemba@gmail.com'
mystore = store.factory.instance(name='music',email=email)
user = mystore.user
# mystore.init(email)
# plan = mystore.get.user.plan()
user.init(email)
plan = user.plan.info()
self.assertTrue ('id' in plan)
mystore.plan.cancel(id=plan['id'])
self.assertTrue ('id' in plan)
# pass
pass
def test_SubscribeToPlan(self):
email = 'nyemba@gmail.com'
mystore = store.factory.instance(name='music',email=email)
user = mystore.user
user.init(email)
plans = mystore.get.plans()
uplan = user.plan.info()
# uplan = mystore.get.user.plan()
ids = [plan['id'] for plan in plans]
if not uplan :
id = [item for item in plans if item['amount'] == 0]
id = id[0]['id']
mystore.plan.subscribe(id=id,email=email)
pass
else:
new_id = list(set(ids) - set( [uplan['id']] ))[0]
mystore.plan.upgrade(new_id,email)
# mystore.plan.subscribe(new_id,email)
pass pass
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
Loading…
Cancel
Save