bug fix: with plans

legacy
Steve L. Nyemba 4 years ago
parent 53a0725cbc
commit a138a8de41

@ -184,6 +184,7 @@ def me ():
pass pass
return render_template("none.html",context=CONTEXT) return render_template("none.html",context=CONTEXT)
# return redirect("http://healthcareio.the-phi.com") # return redirect("http://healthcareio.the-phi.com")
@app.route("/me/card",methods=['POST']) @app.route("/me/card",methods=['POST'])
def me_card (): def me_card ():
if 'auth' in session : if 'auth' in session :
@ -370,8 +371,11 @@ def init(product):
# #
# get product and plans # get product and plans
# #
uid = request.headers['uid'] if 'uid' in request.headers :
plan_id = request.headers['pid'] if 'pid' in request.headers else None uid = request.headers['uid']
plan_id = request.headers['pid'] if 'pid' in request.headers else None
else:
_info = request.json()
mystore = store.factory.instance(name=product,email=uid) mystore = store.factory.instance(name=product,email=uid)
@ -392,49 +396,6 @@ def init(product):
@app.route("/<id>/init",methods=['POST','PUT']) @app.route("/<id>/init",methods=['POST','PUT'])
def _init(id): def _init(id):
return init(id) return init(id)
# @app.route('/subscribe/<product>',methods=['POST'])
# def subscribe(product):
# """
# This function subscribes a user to a given service for an application
# This function guarantees not to duplicate subscriptions
# @resource name name of the application {cloud-music}
# @header key service/plan
# """
# #
# # The name is the full name of the service
# #
# resp = "0"
# user = User(stripe=stripe,store=CONFIG['couchdb'],product=product)
# if 'stripeToken' in request.form :
# stripeToken = request.form['stripeToken']
# uid = request.form['stripeEmail']
# tokenType = request.form['stripeTokenType']
# amount = request.form['amount']
# pid = request.form['plan']
# else:
# pid = request.headers['pid'] if 'pid' in request.headers else None
# uid = request.headers['uid']
# stripeToken = None
# user.subscribe(uid,pid,stripeToken)
# if 'auid' in request.headers :
# if request.headers['auid'].startswith('[') or request.headers['auid'].startswith("{") :
# auid = json.loads(request.headers['auid'])
# else:
# auid = [request.headers['auid']]
# user.update(emails=auid)
# user.refresh(uid)
# reader = CouchdbReader(uri=SYS_STORE['uri'],dbname=product,uid=uid,create=False)
# plans = reader.view('users/active_plan',key=user.user_key) #me['_id'])
# #session['plans'] = plans
# session['key'] = user.user_key
# session['uid'] = uid
# session['active-plans'] = [item['id'] for item in plans]
# print (session['active-plans'])
# return (json.dumps(plans),200)
def get_plans(product) : def get_plans(product) :
lproducts = stripe.Product.list() lproducts = stripe.Product.list()
@ -484,96 +445,6 @@ def features(product):
# formatting plans for the output # formatting plans for the output
# #
return json.dumps(plans),{"content-type":"application/json"} return json.dumps(plans),{"content-type":"application/json"}
# """
# This function returns a user's plans/status for an application
# @header uid user's email address
# """
# @app.route('/status/<app_name>')
# def status(app_name):
# uid = request.headers['uid']
# couchdb = CouchdbReader(uri=CONFIG['couchdb']['uri'],dbname=app_name,uid=uid,create=False)
# handler = Domain.User(couchdb.dbase,stripe)
# handler.initialize(uid)
# #lsub = handler.subscriptions()
# plans = handler.plans()
# return json.dumps(plans)
# """
# This endpoint is the signup form for a given application,
# It will allow user's to be able to signup for various plans
# @pre 'uid' in request.headers
# """
# @app.route('/signup/<product>')
# @app.route('/<product>/signup')
# def _signup(product) :
# apikey = CONFIG['stripe']['pub'].strip()
# #
# # This function returns the plans for a given application
# # We assume the application name is the prefix of the plan identifier in stripe
# #
# if 'user-info' in session :
# _info = session['user-info']
# session['uid'] = _info['uid']
# uid = session['uid'] if 'uid' in session else ''
# can_purchase = True
# if uid is None :
# uid = request.args.get('uid') if 'uid' in request.args else None
# plans = get_plans(product)
# #
# # @TODO: Mark the plans the current user is signed up for
# #
# if 'themes' in CONFIG:
# theme = CONFIG['themes'][product] if product in CONFIG['themes'] else CONFIG['theme']['default']
# else:
# theme = ''
# platform='web' if 'platform' not in request.args else request.args['platform']
# alias = plans[0]['product_alias']
# if 'user-plan' in session :
# user_plans = [item['id'] for item in session['user-plan']]
# else :
# user_plans = []
# # active_plan = session['active-plans'] if 'active-plans' in session else []
# args = {"context":CONTEXT,"theme":theme,"uid":uid,"alias":alias,"platform":platform,"app_name":product,"apikey":apikey,"plans":plans}
# args['active_plans'] = user_plans
# return render_template('subscribe.html',**args) #context=CONTEXT,uid=uid,alias=alias,platform=platform,app_name=product,plans=plans,apikey=apikey)
# @app.route('/subscribe/<name>',methods=['DELETE'])
# def cancel_subscribe(name) :
# pass
# """
# 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/<app_name>',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)
# r = couchdb.view('federation/uid_map',key=uid)
# id = r[0]['value']
# couchdb = CouchdbReader(uri=CONFIG['couchdb']['uri'],dbname=app_name,uid=id,create=False)
# info = couchdb.read()
# lsub = info['subscriptions']
# 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
# session['plans']
# amount = sum([item['amount'] for item in plans])
# apikey = CONFIG['stripe']['pub'].strip()
# amount = amount / 100
# return render_template('bill.html',context=CONTEXT,apikey=apikey,app_name=app_name.replace('-',' '),plans=plans,total_amount=amount)
if __name__ == '__main__' : if __name__ == '__main__' :
# #

@ -199,7 +199,8 @@ class User :
# self.user_plan = _found if _found else None # self.user_plan = _found if _found else None
def _has_plan(self,customer): def _has_plan(self,customer):
subscriptions = customer['subscriptions']['data'] subscriptions = customer['subscriptions']['data']
ids = [plan['id'] for plan in self.plans ]
ids = [plan['id'] for plan in self.plans if 'id' in plan and plan['active'] == True]
_found = None _found = None
for sub in subscriptions : for sub in subscriptions :
aplan = sub['plan'] aplan = sub['plan']
@ -316,6 +317,8 @@ class Plans(Store) :
setattr(item,'amount',item.unit_amount) setattr(item,'amount',item.unit_amount)
_item = item.to_dict_recursive() _item = item.to_dict_recursive()
_item['amount'] = item['unit_amount'] _item['amount'] = item['unit_amount']
if item.active == False :
continue
if item.recurring == None : if item.recurring == None :
self.checkout.append(_item) self.checkout.append(_item)
else: else:

Loading…
Cancel
Save