|
|
|
@ -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 = """
|
|
|
|
|
<form action="/pay" method="POST">
|
|
|
|
|
<script
|
|
|
|
|
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
|
|
|
|
|
data-key=":key"
|
|
|
|
|
data-email=":email"
|
|
|
|
|
data-amount=":amount"
|
|
|
|
|
data-name="The Phi Technology LLC"
|
|
|
|
|
data-description=""
|
|
|
|
|
|
|
|
|
|
data-image="https://s3.amazonaws.com/stripe-uploads/acct_15kiA1EUWsmgY81Amerchant-icon-1443577505909-the-phi-logo.png"
|
|
|
|
|
data-locale="auto">
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
</form>
|
|
|
|
|
"""
|
|
|
|
|
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
|
|
|
|
|