|
|
@ -1,6 +1,11 @@
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
Steve L. Nyemba <steve@the-phi.com>
|
|
|
|
|
|
|
|
The Phi Technology, LLC - Store
|
|
|
|
|
|
|
|
|
|
|
|
This file handles customer & plans associated with a given product/app
|
|
|
|
This file handles customer & plans associated with a given product/app
|
|
|
|
The subscription works as follows:
|
|
|
|
We understand that a product will have multiple plans under it and we make sure that we always have a free version:
|
|
|
|
|
|
|
|
- Having a free product insures there is no excuse not to signup users
|
|
|
|
|
|
|
|
- If a product doesn't fall under this model we will find a way to fix it.
|
|
|
|
-
|
|
|
|
-
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
from __future__ import division
|
|
|
|
from __future__ import division
|
|
|
@ -34,49 +39,71 @@ COUCHDB = Server(uri=CONFIG['couchdb']['uri']) ;
|
|
|
|
This function will set the user information to the session and update the information
|
|
|
|
This function will set the user information to the session and update the information
|
|
|
|
@header uid user email address
|
|
|
|
@header uid user email address
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
@app.route("/init/<app_name>",methods=['POST'])
|
|
|
|
@app.route("/init/<product>",methods=['POST'])
|
|
|
|
def init(app_name):
|
|
|
|
def init(product):
|
|
|
|
plans = []
|
|
|
|
"""
|
|
|
|
handler = None
|
|
|
|
This function initializes a product to a given user,
|
|
|
|
uid = request.headers['uid']
|
|
|
|
if the user has provided a user identifier it will be used as her primary email. The understanding is that a product may have multiple plans under it but always a free one
|
|
|
|
plan = request.headers['pid']
|
|
|
|
@param uid user's email (primary)
|
|
|
|
auid = None
|
|
|
|
@param pid plan identifier
|
|
|
|
if 'uid' in request.headers and 'auid' not in request.headers:
|
|
|
|
"""
|
|
|
|
id = uid
|
|
|
|
email = request.headers['uid']
|
|
|
|
#couchdb = Couchdb(uri=CONFIG['couchdb']['uri'],dbname=app_name,uid=uid,create=False)
|
|
|
|
plan_id = request.headers['pid']
|
|
|
|
#DB = couchdb.dbase
|
|
|
|
user = User(stripe=stripe,store=CONFIG['couchdb'],product=product)
|
|
|
|
|
|
|
|
user.susbscribe(uid,plan_id)
|
|
|
|
if 'auid' in request.headers :
|
|
|
|
if 'auid' in request.headers :
|
|
|
|
auid = request.headers['auid']
|
|
|
|
auid = request.header['auid']
|
|
|
|
auid = json.loads(auid)if auid.startswith('[') else auid
|
|
|
|
user.update(emails=auid)
|
|
|
|
if isinstance(auid,list) :
|
|
|
|
user.post()
|
|
|
|
auid = list(set(auid) - set([uid]))
|
|
|
|
features = json.loads(users.me['subscriptions'][pid][0]['metadata'])
|
|
|
|
|
|
|
|
|
|
|
|
if len(auid) == 0:
|
|
|
|
|
|
|
|
auid = None
|
|
|
|
|
|
|
|
id = uid
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
auid = auid[0]
|
|
|
|
features = user.get(uid,key)
|
|
|
|
id = auid
|
|
|
|
user.refresh()
|
|
|
|
couchdb = Couchdb(uri=CONFIG['couchdb']['uri'],dbname=app_name,uid=id,create=False)
|
|
|
|
return json.dumps(features),200
|
|
|
|
DB = couchdb.dbase
|
|
|
|
|
|
|
|
#handler.update_user(id=handler.getId(auid),uid=uid)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handler = Domain.User(DB,stripe) ;
|
|
|
|
# @app.route("/init/<app_name>",methods=['POST'])
|
|
|
|
if auid is None :
|
|
|
|
# def init(app_name):
|
|
|
|
handler.init(uid,plan) ;
|
|
|
|
# plans = []
|
|
|
|
else:
|
|
|
|
# handler = None
|
|
|
|
if couchdb.isready() == False:
|
|
|
|
# uid = request.headers['uid']
|
|
|
|
handler.init(auid,plan)
|
|
|
|
# plan = request.headers['pid']
|
|
|
|
id = handler.getId(uid)
|
|
|
|
# auid = None
|
|
|
|
|
|
|
|
# if 'uid' in request.headers and 'auid' not in request.headers:
|
|
|
|
|
|
|
|
# id = uid
|
|
|
|
|
|
|
|
# #couchdb = Couchdb(uri=CONFIG['couchdb']['uri'],dbname=app_name,uid=uid,create=False)
|
|
|
|
|
|
|
|
# #DB = couchdb.dbase
|
|
|
|
|
|
|
|
# if 'auid' in request.headers :
|
|
|
|
|
|
|
|
# auid = request.headers['auid']
|
|
|
|
|
|
|
|
# auid = json.loads(auid)if auid.startswith('[') else auid
|
|
|
|
|
|
|
|
# if isinstance(auid,list) :
|
|
|
|
|
|
|
|
# auid = list(set(auid) - set([uid]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# if len(auid) == 0:
|
|
|
|
|
|
|
|
# auid = None
|
|
|
|
|
|
|
|
# id = uid
|
|
|
|
|
|
|
|
# else:
|
|
|
|
|
|
|
|
# auid = auid[0]
|
|
|
|
|
|
|
|
# id = auid
|
|
|
|
|
|
|
|
# couchdb = Couchdb(uri=CONFIG['couchdb']['uri'],dbname=app_name,uid=id,create=False)
|
|
|
|
|
|
|
|
# DB = couchdb.dbase
|
|
|
|
|
|
|
|
# #handler.update_user(id=handler.getId(auid),uid=uid)
|
|
|
|
|
|
|
|
|
|
|
|
handler.initialize(auid)
|
|
|
|
# handler = Domain.User(DB,stripe) ;
|
|
|
|
id = handler.getId(auid)
|
|
|
|
# if auid is None :
|
|
|
|
handler.update_user(id=id,uid=uid) ;
|
|
|
|
# handler.init(uid,plan) ;
|
|
|
|
|
|
|
|
# else:
|
|
|
|
|
|
|
|
# if couchdb.isready() == False:
|
|
|
|
|
|
|
|
# handler.init(auid,plan)
|
|
|
|
|
|
|
|
# id = handler.getId(uid)
|
|
|
|
|
|
|
|
|
|
|
|
plans = handler.plans()
|
|
|
|
# handler.initialize(auid)
|
|
|
|
#return json.dumps(plans)
|
|
|
|
# id = handler.getId(auid)
|
|
|
|
_features = features(app_name)
|
|
|
|
# handler.update_user(id=id,uid=uid) ;
|
|
|
|
return _features
|
|
|
|
|
|
|
|
|
|
|
|
# plans = handler.plans()
|
|
|
|
|
|
|
|
# #return json.dumps(plans)
|
|
|
|
|
|
|
|
# _features = features(app_name)
|
|
|
|
|
|
|
|
# return _features
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
This function will update the user's email
|
|
|
|
This function will update the user's email
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|