Steve L. Nyemba 6 years ago
parent 0368d78496
commit 4c1e326b51

BIN
.DS_Store vendored

Binary file not shown.

BIN
src/.DS_Store vendored

Binary file not shown.

BIN
src/api/.DS_Store vendored

Binary file not shown.

@ -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
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
@ -34,49 +39,71 @@ COUCHDB = Server(uri=CONFIG['couchdb']['uri']) ;
This function will set the user information to the session and update the information
@header uid user email address
"""
@app.route("/init/<app_name>",methods=['POST'])
def init(app_name):
plans = []
handler = None
uid = request.headers['uid']
plan = request.headers['pid']
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
@app.route("/init/<product>",methods=['POST'])
def init(product):
"""
This function initializes a product to a given user,
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
@param uid user's email (primary)
@param pid plan identifier
"""
email = request.headers['uid']
plan_id = request.headers['pid']
user = User(stripe=stripe,store=CONFIG['couchdb'],product=product)
user.susbscribe(uid,plan_id)
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 = Domain.User(DB,stripe) ;
if auid is None :
handler.init(uid,plan) ;
auid = request.header['auid']
user.update(emails=auid)
user.post()
features = json.loads(users.me['subscriptions'][pid][0]['metadata'])
else:
if couchdb.isready() == False:
handler.init(auid,plan)
id = handler.getId(uid)
features = user.get(uid,key)
user.refresh()
return json.dumps(features),200
handler.initialize(auid)
id = handler.getId(auid)
handler.update_user(id=id,uid=uid) ;
# @app.route("/init/<app_name>",methods=['POST'])
# def init(app_name):
# plans = []
# handler = None
# uid = request.headers['uid']
# plan = request.headers['pid']
# 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]))
plans = handler.plans()
#return json.dumps(plans)
_features = features(app_name)
return _features
# 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 = Domain.User(DB,stripe) ;
# if auid is None :
# handler.init(uid,plan) ;
# else:
# if couchdb.isready() == False:
# handler.init(auid,plan)
# id = handler.getId(uid)
# handler.initialize(auid)
# id = handler.getId(auid)
# handler.update_user(id=id,uid=uid) ;
# plans = handler.plans()
# #return json.dumps(plans)
# _features = features(app_name)
# return _features
"""
This function will update the user's email
"""

Binary file not shown.

Before

Width:  |  Height:  |  Size: 357 KiB

After

Width:  |  Height:  |  Size: 357 KiB

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 9.6 KiB

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save