本文整理汇总了Python中cloudrunner_server.api.util.JsonOutput.billing方法的典型用法代码示例。如果您正苦于以下问题:Python JsonOutput.billing方法的具体用法?Python JsonOutput.billing怎么用?Python JsonOutput.billing使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cloudrunner_server.api.util.JsonOutput
的用法示例。
在下文中一共展示了JsonOutput.billing方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: account
# 需要导入模块: from cloudrunner_server.api.util import JsonOutput [as 别名]
# 或者: from cloudrunner_server.api.util.JsonOutput import billing [as 别名]
def account(self, *args, **kwargs):
"""
.. http:get:: /billing/account
Returns basic account information
>header: Auth token
"""
CS = request.braintree.CustomerSearch
customers = [c for c in request.braintree.Customer.search(
CS.company == request.user.org).items]
if not customers:
# Try to create customer
user = User.visible(request).filter(
User.username == request.user.username).one()
result = request.braintree.Customer.create({
"first_name": user.first_name,
"last_name": user.last_name,
"company": user.org.name,
"email": user.email,
"phone": user.phone,
})
if not result.is_success:
return O.error("Cannot fetch data from billing system")
customers = [result.customer]
customer = customers[0]
card, subs = {}, {}
if customer.credit_cards:
cc = customer.credit_cards[0]
card['number'] = cc.masked_number
card['expire'] = cc.expiration_date
card['type'] = cc.card_type
if cc.subscriptions:
sub = cc.subscriptions[0]
subs['next_date'] = sub.next_billing_date
subs['next_amount'] = sub.next_billing_period_amount
TS = request.braintree.TransactionSearch
history = request.braintree.Transaction.search([
TS.customer_company == request.user.org])
return O.billing(transactions=[serialize_t(h) for h in history.items],
plan=subs, cards=card)