本文整理汇总了Python中users.User.subscription方法的典型用法代码示例。如果您正苦于以下问题:Python User.subscription方法的具体用法?Python User.subscription怎么用?Python User.subscription使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类users.User
的用法示例。
在下文中一共展示了User.subscription方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: modsub_page
# 需要导入模块: from users import User [as 别名]
# 或者: from users.User import subscription [as 别名]
def modsub_page():
'''Dashboard Modify Subscription:
This will allow a user to modify their subscription and account plan
'''
verify = verifyLogin(
app.config['SECRET_KEY'], app.config['COOKIE_TIMEOUT'], request.cookies)
if verify:
user = User()
user.get('uid', verify, g.rdb_conn)
data = startData(user)
data['active'] = 'dashboard'
data['url'] = '/dashboard/mod-subscription'
data['uid'] = user.uid
tmpl = 'member/mod-subscription.html'
data['js_bottom'].append('forms/subscribe.js')
form = []
# Stripe vs ASM stuff
if user.payments == "ASM":
headers = {
"content-type": "application/json",
"Authorization": app.config['ASSEMBLY_PRIVATE_KEY']
}
paymenturl = app.config['ASSEMBLY_PAYMENTS_URL']
else:
from base64 import b64encode
api_key = b64encode(app.config['STRIPE_PRIVATE_KEY']).decode("ascii")
headers = {
"Authorization": "Basic " + api_key,
}
paymenturl = app.config['STRIPE_PAYMENTS_URL']
from generalforms import subscribe
if data['upgraded'] is False:
# Upgrade Users
if request.method == "POST" and \
"stripeToken" in request.form and "plan" in request.form:
stripeToken = request.form['stripeToken']
plan = request.form['plan']
if stripeToken:
result = None
monitor = Monitor()
payload = {
'email': user.email,
'quantity': monitor.count(user.uid, g.rdb_conn),
'source': stripeToken,
'plan': plan
}
json_payload = json.dumps(payload)
url = paymenturl + "/customers"
print ("Making request to %s") % url
try:
# Send Request to Payment system to create user and subscribe
# them to desired plan
result = requests.post(
url=url, headers=headers,
params=payload, verify=True)
except:
print("Critical Error making request to Payments")
flash('There was an error processing \
your card details.', 'danger')
print("Got {0} status code from Payments".format(
result.status_code))
if result.status_code >= 200 and result.status_code <= 299:
rdata = json.loads(result.text)
user.stripeid = rdata['id']
user.stripe = stripeToken
user.subplans = payload['quantity']
user.subscription = payload['plan']
if "pro_plus" in plan:
user.acttype = "proplus"
else:
user.acttype = "pro"
print("Setting UID %s Subscription to: %s") % (
user.uid, user.acttype)
subres = user.setSubscription(g.rdb_conn)
stathat.ez_count(
app.config['STATHAT_EZ_KEY'],
app.config['ENVNAME'] + ' User Upgrades', 1)
if subres:
newdata = startData(user)
data['limit'] = newdata['limit']
data['rlimit'] = newdata['rlimit']
data['acttype'] = newdata['acttype']
data['subplans'] = newdata['subplans']
data['cost'] = newdata['cost']
data['subscription'] = newdata['subscription']
flash('Subscription successfully created.',
'success')
else:
flash('Subscription not successfully created.',
'danger')
else:
flash('Subscription not created got status code: %d' % result.status_code, 'danger')
# Increase subscription
if data['upgraded']:
form = subscribe.AddPackForm(request.form)
if request.method == "POST" and "stripeToken" not in request.form:
if form.validate():
add_packs = int(form.add_packs.data)
#.........这里部分代码省略.........
示例2: modsub_page
# 需要导入模块: from users import User [as 别名]
# 或者: from users.User import subscription [as 别名]
def modsub_page():
'''Dashboard Modify Subscription:
This will allow a user to modify their subscription and account plan
'''
verify = verifyLogin(
app.config['SECRET_KEY'], app.config['COOKIE_TIMEOUT'], request.cookies)
if verify:
user = User()
user.get('uid', verify, g.rdb_conn)
data = startData(user)
data['active'] = 'dashboard'
data['url'] = '/dashboard/mod-subscription'
data['uid'] = user.uid
tmpl = 'member/mod-subscription.html'
data['js_bottom'].append('forms/subscribe.js')
form = []
headers = {
"content-type": "application/json",
"Authorization": app.config['ASSEMBLY_PRIVATE_KEY']
}
from generalforms import subscribe
if data['acttype'] == "Lite":
# Upgrade Users
if request.method == "POST" and \
"stripeToken" in request.form and "plan" in request.form:
stripeToken = request.form['stripeToken']
plan = request.form['plan']
if stripeToken:
result = None
monitor = Monitor()
payload = {
'email': user.email,
'quantity': monitor.count(user.uid, g.rdb_conn),
'card': stripeToken,
'plan': plan
}
json_payload = json.dumps(payload)
url = app.config['ASSEMBLY_PAYMENTS_URL'] + "/customers"
print ("Making request to %s") % url
try:
# Send Request to Assembly to create user and subscribe
# them to desired plan
result = requests.post(
url=url, headers=headers,
data=json_payload, verify=True)
except:
print("Critical Error making request to ASM Payments")
data['msg'] = "There was an error processing your card details"
data['error'] = True
print(
"Got %d status code from Assembly") % result.status_code
if result.status_code >= 200 and result.status_code <= 299:
rdata = json.loads(result.text)
user.stripeid = rdata['id']
user.stripe = stripeToken
user.subplans = payload['quantity']
user.subscription = payload['plan']
user.acttype = "pro"
print("Setting UID %s Subscription to: %s") % (
user.uid, user.acttype)
subres = user.setSubscription(g.rdb_conn)
stathat.ez_count(
app.config['STATHAT_EZ_KEY'],
app.config['ENVNAME'] + ' User Upgrades', 1)
if subres:
newdata = startData(user)
data['limit'] = newdata['limit']
data['rlimit'] = newdata['rlimit']
data['acttype'] = newdata['acttype']
data['subplans'] = newdata['subplans']
data['cost'] = newdata['cost']
data['subscription'] = newdata['subscription']
data['msg'] = "Subscription successfully created"
data['error'] = False
else:
data[
'msg'] = "Subscription not successfully created"
data['error'] = True
# Increase subscription
if data['acttype'] != "Lite":
form = subscribe.AddPackForm(request.form)
if request.method == "POST" and "stripeToken" not in request.form:
if form.validate():
add_packs = int(form.add_packs.data)
# Set subscription quantity to desired monitor count
payload = {'quantity': add_packs}
json_payload = json.dumps(payload)
url = app.config[
'ASSEMBLY_PAYMENTS_URL'] + "/customers/" + user.stripeid
print("Making request to %s") % url
try:
# Get Subscription ID
result = requests.get(
url=url, headers=headers, verify=True)
if result.status_code == 200:
rdata = json.loads(result.text)
subsid = rdata['subscriptions']['data'][0]['id']
url = url + "/subscriptions/" + subsid
print("Making request to %s") % url
# Set Quantity
#.........这里部分代码省略.........