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

@ -17,3 +17,4 @@ six==1.10.0
socketpool==0.5.3 socketpool==0.5.3
stripe==1.82.1 stripe==1.82.1
Werkzeug==0.12.1 Werkzeug==0.12.1
git+https://dev.the-phi.com/git/steve/data-transport.git

@ -51,11 +51,13 @@ body{
text-align:center; text-align:center;
} }
.button .text {color:#ffffff}
.button:hover { .button:hover {
background-color:#ffffff; background-color:#ffffff;
color:#4682b4; color:#4682b4;
} }
.button:hover .text { color :#4682B4;}
.active { .active {
font-weight:bold; font-weight:bold;
@ -75,7 +77,7 @@ body{
width: 0px; width: 0px;
} }
.bold { font-weight:bold} .bold { font-weight:bold; }
.caption { .caption {
font-size:28px; font-weight:bold ; font-size:28px; font-weight:bold ;
font-family:sans-serif; font-family:sans-serif;

@ -1 +1 @@
Subproject commit df17531499104b155e5ac97ee2755a8bf10bf8ff Subproject commit 3599fff083f1661a1762992d3891210d6c3aec05

@ -73,39 +73,56 @@ class User :
# email = args['email'] # email = args['email']
# self.user_plan = [] # self.user_plan = []
# self.customer = {} # self.customer = {}
customers = stripe.customer.Customer.list(email=email).to_dict_recursive()['data'] customer = stripe.customer.Customer.list(email=email).to_dict_recursive()['data']
if customers : free_plan = [item for item in self.plans if item['amount'] == 0]
customers = customers[0] if customer :
customer = customer[0]
else: else:
# #
# The user doesn't exist, we must create the user (without payment initially) # The user doesn't exist, we must create the user (without payment initially)
# We can probably assign the user to a free plan if available # We can probably assign the user to a free plan if available
# #
customers = stripe.customer.Customer.Create(email=email) customer = stripe.customer.Customer.create(email=email)
free_plan = [item for item in self.plans if item['amount'] == 0]
if free_plan : # if free_plan :
free_plan = free_plan[0] # free_plan = free_plan[0]
self.plan.subscribe(free_plan['id'],email) # self.plan.subscribe(free_plan['id'],email)
# self.customer = {"email":email,"id":customers['id']} # self.customer = {"email":email,"id":customers['id']}
self.me["customer"] = {"email":email,"id":customers['id']} self.me["customer"] = {"email":email,"id":customer['id']}
# #
# extract payments available, # extract payments available,
if 'sources' in customers and 'data' in customers['sources'] : if 'sources' in customer and 'data' in customer['sources'] :
if customers['sources']['data'] : if customer['sources']['data'] :
# self.payment = [ card.to_dict_recursive() for card in customers['sources']['data'] ] # self.payment = [ card.to_dict_recursive() for card in customers['sources']['data'] ]
self.me['payments'] = [ card.to_dict_recursive() for card in customers['sources']['data'] ] self.me['payments'] = [ card.to_dict_recursive() for card in customer['sources']['data'] ]
info = customers #self.me['customer'] # if not self._has_plan(customer) and free_plan:
subscriptions = info['subscriptions']['data'] # free_plan = free_plan[0]
# self.subscribe(free_plan['id'],email)
# info = customers #self.me['customer']
# subscriptions = info['subscriptions']['data']
# ids = [plan['id'] for plan in self.plans ]
# _found = None
# for sub in subscriptions :
# aplan = sub['plan']
# if set([aplan['id']]) & set(ids):
# _found = sub.to_dict_recursive()
# break
self.me["plan"] = self._has_plan(customer) #_found if _found else []
# self.user_plan = _found if _found else None
def _has_plan(self,customer):
subscriptions = customer['subscriptions']['data']
ids = [plan['id'] for plan in self.plans ] ids = [plan['id'] for plan in self.plans ]
_found = None _found = None
for sub in subscriptions : for sub in subscriptions :
aplan = sub['plan'] aplan = sub['plan']
if set([aplan['id']]) & set(ids): if set([aplan['id']]) & set(ids):
_found = sub.to_dict_recursive() _found = sub.to_dict_recursive()['plan']
if 'features' in _found['metadata'] :
_found ['metadata']['features'] = json.loads(_found['metadata']['features'])
break break
self.me["plan"] = _found if _found else [] return _found if _found else []
# self.user_plan = _found if _found else None
class Store : class Store :
def __init__(self,**args): def __init__(self,**args):
""" """
@ -136,7 +153,68 @@ class Store :
:email :email
""" """
pass pass
class Product(Store):
"""
This class implements a wrapper around products, services or just simple donations
we are inheriting product, plans
"""
def __init__(self,**args):
Store.__init__(self,**args)
def set(self,key,value):
if key == 'plan' :
#
# do we have this plan
found = [item for item in self.plans if item['id'] == value['id']]
if not found :
plan = value
else:
plan = dict(found[0],**value)
if 'metadata' in value :
plan['metadata'] = self.meta(plan,value)
self.save('plan',plan)
pass
else :
if key in ['type','name','id','statement_descriptor'] :
if value :
self.product[key] = value
elif key in self.product :
del self.product[key]
elif key == 'metadata' :
self.product['metadata'] = self.meta(self.product,value)
self.save('product',self.product)
def meta(self,object,value) :
for k in value :
if value[k] :
object['metadata'][k] = json.dumps(value[k]) if type(value[k]) == dict else value[k]
else:
del object['metadata'][k]
return object
def save(self,id,object):
pointer = None
if id == 'product' :
p = 'about' in object['metadata']
q = 'uri' in object['metadata']
if p and q :
pointer = stripe.product.Product
return 1
else :
return 0
elif self.product['id']:
pointer = stripe.plan.Plan
object = dict(object,**{"product":{"name":self.product['id']}} )
if pointer :
pointer.create(**object)
return 1
return 0
def get(self):
pass
class Plans(Store) : class Plans(Store) :
def __init__(self,**args): def __init__(self,**args):
""" """
@ -193,14 +271,24 @@ class Plans(Store) :
return 1 return 1
pass pass
def subscribe(self,id,email): # def subscribe(self,id,email):
def subscribe(self,**args):
""" """
Subscribe a user to a given plan assuming the user has already been initialized Subscribe a user to a given plan assuming the user has already been initialized
The responsibility falls upon the calling code to perform the cancellatioin of the existing plan and perform an upgrade The responsibility falls upon the calling code to perform the cancellatioin of the existing plan and perform an upgrade
:email user's email
:id plan id (optional) will default to free plan
""" """
free_plan = [item['id'] for item in self.plans if item['amount'] == 0]
if free_plan :
free_plan = free_plan[0]
# id = args['id'] if 'id' in args else free_plan
email = args['email']
if not self.user : if not self.user :
self.user = User(email,self.plans) self.user = User(email,self.plans)
plan = {"plan": id}
plan = {"plan": args['id'] if 'id' in args else free_plan}
amount = sum([item['amount'] for item in self.plans if item['id'] == 0]) amount = sum([item['amount'] for item in self.plans if item['id'] == 0])
if 'email' in self.user.info() and email == self.user.info()['email'] : if 'email' in self.user.info() and email == self.user.info()['email'] :
@ -210,17 +298,24 @@ class Plans(Store) :
# #
# We must insure the user is one of our customers i.e perhaps # We must insure the user is one of our customers i.e perhaps
if amount == 0 or self.payment : if amount == 0 or self.payment :
stripe.subscription.Subscription.create( r = stripe.subscription.Subscription.create(
customer=self.user.info()['id'], #if not email else email, customer = self.user.info()['id'],
items = [plan] items = [plan]
) )
# stripe.subscription.Subscription.create(
# customer=self.user.info()['id'], #if not email else email,
# items=[plan]
# )
self.user.init(email)
return 1 return 1
else: else:
return 0 return 0
class factory: class factory:
@staticmethod @staticmethod
def instance (**args) : def instance (**args) :
return Plans(**args) p = Plans(**args)
# p.user.subscribe = p.subscribe
return p
# if 'email' in args : # if 'email' in args :
# store = Plans(**args) # store = Plans(**args)

@ -0,0 +1,10 @@
<body>
<input type="text" disabled/>
<input type="text" placeholder="card number"/>
<div>
<div>
{% for i in range(12) %}
{% endfor %}
</div>
</div>
</body>

@ -0,0 +1,50 @@
<meta charset="UTF-8">
<meta http-equiv="cache-control" content="no-cache">
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1">
<link rel="shortcut icon" href="{{context}}/static/img/logo-0.png">
<link href="{{ context }}/static/css/fa/css/font-awesome.css" rel="stylesheet" type="text/css">
<!--
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.css" />
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid-theme.min.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.js"></script>
-->
<script type="text/javascript" src="{{ context }}/static/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="{{ context }}/static/js/jx/rpc.js"></script>
<script type="text/javascript" src="{{ context }}/static/js/jx/utils.js"></script>
<script type="text/javascript" src="{{ context }}/static/js/jx/dom.js"></script>
<link href="{{context}}/static/css/default.css" rel="stylesheet" type="text/css">
<title style="text-transform: capitalize">Store</title>
<style>
.grid {
padding:4px;
display:grid;
grid-template-columns: repeat(auto-fit,minmax(45%,1fr)) ;
grid-gap:4px;
align-content: center;
align-items: center;
}
.grid .tile {
height:300px;
font-size:14px;
}
</style>
<body>
<div class="grid theme-clouds border border-round">
{% for item in products %}
<div class="tile">
<div class="caption border-bottom">
<p>
{{item.name.replace('-',' ')}}
</p>
</div>
<div class="default">
<p>
{{item.metadata.about}}
</p>
</div>
</div>
{% endfor %}
</div>
</body>

@ -14,18 +14,98 @@
<script type="text/javascript" src="{{ context }}/static/js/jx/utils.js"></script> <script type="text/javascript" src="{{ context }}/static/js/jx/utils.js"></script>
<script type="text/javascript" src="{{ context }}/static/js/jx/dom.js"></script> <script type="text/javascript" src="{{ context }}/static/js/jx/dom.js"></script>
<script type="text/javascript" src="{{ context }}/static/js/jx/ext/modal.js"></script> <script type="text/javascript" src="{{ context }}/static/js/jx/ext/modal.js"></script>
<script type="text/javascript" src="{{ context }}/static/js/jx/ext/cloud-view.js"></script>
<title style="text-transform: capitalize">{{product.replace('-',' ')}}</title> <title style="text-transform: capitalize">{{product.replace('-',' ')}}</title>
<script> <script>
var signup_form = function(index){ var signup_form = function(index,caller){
var url = '{{context}}/ui/signup/{{product}}?index=:index'.replace(/:index/,index) var url = '{{context}}/ui/signup/{{product}}?index=:index'.replace(/:index/,index)
var httpclient = HttpClient.instance() var httpclient = HttpClient.instance()
httpclient.get(url,function(x){ httpclient.get(url,function(x){
var html = x.responseText ; var html = x.responseText ;
jx.modal.show({html:html}) jx.modal.show({html:html,id:'signup'})
bind( JSON.parse( $(caller).attr('data')) )
}) })
} }
var signup_card = function(p){
var http = HttpClient.instance()
http.get('{{context}}/card.html')
}
/*
* Binding buttons to oauth 2.0 interface
*/
var bind = function(data){
var buttons = $('.signup-button')
jx.utils.patterns.visitor(buttons,function(button){
$(button).attr('data',data)
$(button).click(function(event){
var id = ( $(this).attr('data-value'))
var plan_id = ( $(this).attr('plan-id'))
var protocol = window.location.href.match(/^(https|http)/)[0]
var host = window.location.href.match(/^.+\/\/([a-z,-,.]+)\/.+$/)[1]
var key = ([protocol,'://',host,'/cloud-view/oauth']).join('')
jx.cloudview.init(host,protocol)
jx.cloudview.oauth.init(id,key,function(p){
//
// @TODO:
// At this point we need to provide a screen to provide credit card information
// And or redirect to application framework
//
//var data = $(button).attr('data')
console.log(data)
console.log(data.id)
var http = HttpClient.instance()
http.get('{{context}}/signup',function(x){
x = JSON.parse(x.responseText)
var form = jx.dom.get.instance('FORM')
form.id = data.id
form.method = 'POST'
form.action = '{{context}}/signup'
var script = jx.dom.get.instance('SCRIPT')
var input = jx.dom.get.instance('INPUT')
input.type = 'submit'
input.type = 'stripe-button'
script.setAttribute('data-key', x['data-key'].trim())
script.setAttribute('data-email', p.user.uid)
script.setAttribute('data-name', data.nickname)
script.setAttribute('data-amount', data.amount)
script.setAttribute('data-description','{{description|safe}} ' + data.nickname)
script.src = 'https://checkout.stripe.com/checkout.js'
script.setAttribute('data-amount',data.amount)
script.setAttribute('data-image','https://s3.amazonaws.com/stripe-uploads/acct_15kiA1EUWsmgY81Amerchant-icon-1493912370912-logo-0.png')
script.setAttribute('data-label',(['Pay $',data.amount,data.interval]).join(' '))
script.className = 'stripe-button'
form.appendChild(script)
form.appendChild(input)
//jx.dom.set.value('form','')
//jx.dom.append('form',form)
jx.modal.close('signup')
$('#form').html('')
$('#form').append(form)
setTimeout(function(){
console.log('###')
$('.stripe-button-el').click()
},500)
})
})
//alert(window.location.href.match(/^(https|http):\/\/([a-z,-,.]+)/)[2])
})
})
}
</script> </script>
<body > <body >
@ -55,7 +135,7 @@
{% for item in plans%} {% for item in plans%}
<div class="plan {{theme}}"> <div class="plan {{theme}}">
<div class="title" align="center"> <div class="title" align="center">
<div>{{ item.nickname }}</div> <div class="nickname">{{ item.nickname }}</div>
{% if item.id in active_plans %} {% if item.id in active_plans %}
<div class="current-plan"></div> <div class="current-plan"></div>
{% else %} {% else %}
@ -76,7 +156,7 @@
</div> </div>
<div class=""> <div class="">
{% for key,value in item.metadata['features'].iteritems() %} {% for key,value in item.metadata['features'].items() %}
<div class="feature"> <div class="feature">
<div class="label">{{ key }}</div> <div class="label">{{ key }}</div>
{% if value == True %} {% if value == True %}
@ -93,8 +173,21 @@
<div align="right" class="border-top"> <div align="right" class="border-top">
<p> <p>
<div class="button " onclick="signup_form({{loop.index-1}})"> <div class="button " data='{{item|tojson|safe}}' onclick="signup_form( {{loop.index-1}} , this )">
Signup Now <div>Signup Now</div>
{% if item.amount == 0%}
<div class="small text">
<span class="bold">Free</span>
</div>
{%else%}
<div class="small text" >
<span class="bold">$ {{ item.amount/100 }}</span>
/ <span >{{item.interval[:]}}</span>
</div>
{% endif %}
</div> </div>
</p> </p>
@ -108,11 +201,13 @@
</div> </div>
</div> </div>
<div id="form" class="border-top" style="display:none">
</div>
<div class="small footer"> <div class="small footer">
<div>support@the-phi.com</div> <div>support@the-phi.com</div>
<div> <div>
all rights reserved &copy; {{ now }}, The Phi Technology all rights reserved &copy; {{ now }}, The Phi Technologys
</div> </div>
<div> <div>
Privacy & Terms Privacy & Terms

@ -21,7 +21,7 @@
align-content: center; align-content: center;
grid-gap:1px; grid-gap:1px;
grid-template-columns: 50% auto; grid-template-columns: 50% auto;
width:auto; min-width:650px;
@ -70,10 +70,27 @@
grid-template-columns: 32px auto; grid-template-columns: 32px auto;
align-items: center; align-items: center;
} }
.input-form input[type=text] {
padding:6px; width:100%;
margin:4px;
color:gray;
border:2px solid transparent;
}
.input-form input[type=text]:focus{
outline:none;
border-left-color:#4682b4 ;
}
</style> </style>
<body> <body>
<div class="border-round {{theme}}">
<div class="border-bottom" align="right" style="padding:4px;">
<span class="active" onclick="jx.modal.close()">
<i class="fa fa-times fa-2x"></i>
</span>
</div>
<p></p> <p></p>
<div class="pane border-round {{theme}}" > <div class="pane " >
<div class=" border-right"> <div class=" border-right">
<div class="title"> <div class="title">
@ -94,7 +111,7 @@
<p> <p>
<div class="plan border-none " > <div class="plan border-none " >
{% for key,value in plan.metadata.features.iteritems() %} {% for key,value in plan.metadata.features.items() %}
<div class="feature"> <div class="feature">
<div class="label"> <div class="label">
{{key}} {{key}}
@ -120,16 +137,16 @@
<p> <p>
<div align="center" style="display:grid; align-content:center; justify-content:center" > <div align="center" style="display:grid; align-content:center; justify-content:center" >
<input type="image" src="{{context}}/static/assets/google/normal.png" style="height:48px;" data-value="google-drive"/> <input type="image" src="{{context}}/static/assets/google/normal.png" style="height:48px;" data-value="google-drive" plan-id="{{plan.id}}"/>
<div class="signup-button" data-value="dropbox"> <div class="signup-button" data-value="dropbox" plan-id="{{plan.id}}">
<img src="{{context}}/static/img/accounts/dropbox.png"> <img src="{{context}}/static/img/accounts/dropbox.png">
<span>Dropbox</span> <span>Dropbox</span>
</div> </div>
<div class="border-left border-bottom signup-button" data-value="one-drive"> <div class="border-left border-bottom signup-button" data-value="one-drive" plan-id="{{plan.id}}">
<img src="{{context}}/static/img/accounts/microsoft.png"> <span>One Drive</span> <img src="{{context}}/static/img/accounts/microsoft.png"> <span>One Drive</span>
</div> </div>
<div class="border-left border-bottom signup-button" data-value="box"> <div class="border-left border-bottom signup-button" data-value="box" plan-id="{{plan.id}}">
<img src="{{context}}/static/img/accounts/box.png"> <span>Box</span> <img src="{{context}}/static/img/accounts/box.png"> <span>Signin with box</span>
</div> </div>
</div> </div>
@ -138,4 +155,5 @@
</div> </div>
</div>
</body> </body>

@ -232,7 +232,7 @@
</div> </div>
<div class=""> <div class="">
{% for key,value in item.metadata['features'].iteritems() %} {% for key,value in item.metadata['features'].items() %}
<div class="feature"> <div class="feature">
<div class="label">{{ key }}</div> <div class="label">{{ key }}</div>
{% if value == True %} {% if value == True %}

@ -0,0 +1,27 @@
#!/bin/bash
export PYTHONPATH=$PWD
install(){
virtualenv sandbox
sandbox/bin/pip install -r requirements.txt
}
start(){
python3 api/index.py --path $PWD/config.json --port 8084 --context store & > log
}
stop(){
ps -eo pid,command |grep python |grep $PWD |grep -E "^ {0,}[0-9]+" -o |xargs kill -9
}
check(){
pid=`ps -eo pid,command |grep python |grep $PWD |grep -E "^ {0,}[0-9]+" -o -m 1`
if [ "$pid" ]; then
echo "*** Online $pid"
else
echo "*** Offline"
fi
}
status(){
check
}
$1
Loading…
Cancel
Save