uncloud-cli/commands/product.py

68 lines
2.5 KiB
Python
Raw Normal View History

2019-09-13 05:28:05 +00:00
import click
import requests
from decouple import config
from .helper import OTPCredentials, load_dump_pretty
@click.group()
def product():
pass
@product.command("list")
def list():
2019-09-13 13:56:56 +00:00
r = requests.get("{}/product/list".format(config('UCLOUD_PAY_SERVER')))
2019-09-13 05:28:05 +00:00
print(load_dump_pretty(r.content))
@product.command("add")
@click.option("--name", envvar="OTP_NAME", required=True)
@click.option("--realm", envvar="OTP_REALM", required=True)
@click.option("--seed", envvar="OTP_SEED", required=True)
@click.option("--product-name", required=True)
@click.option("--product-description", required=True)
@click.option("--product-type", required=True,
help="Either one-time or recurring",
type=click.Choice(['one-time', 'recurring']))
@click.option("--product-price", required=True, help="Price in CHF cents",
type=int)
@click.option("--product-recurring-period", required=False,
2019-09-13 05:28:05 +00:00
help="Only used for products with recurring costs",
type=int)
@click.option("--product-minimum-subscription-period", required=False,
type=int, help="Minimum period for which a user needs to "
"subscribe the product for", default=0)
2019-09-13 05:28:05 +00:00
def add(name, realm, seed, product_name, product_description, product_type,
product_price, product_recurring_period,
product_minimum_subscription_period):
2019-09-13 05:28:05 +00:00
data = {
**OTPCredentials(name, realm, seed).get_json(),
"product_name": product_name,
"product_description": product_description,
"product_type": product_type,
"product_price": product_price,
"product_recurring_period": product_recurring_period,
"product_minimum_subscription_period":
product_minimum_subscription_period
2019-09-13 05:28:05 +00:00
}
2019-09-14 07:17:45 +00:00
r = requests.post("{}/product/add".format(config('UCLOUD_PAY_SERVER')),
2019-09-13 13:56:56 +00:00
json=data)
2019-09-13 05:28:05 +00:00
print(load_dump_pretty(r.content))
@product.command("order")
@click.option("--name", envvar="OTP_NAME", required=True)
@click.option("--realm", envvar="OTP_REALM", required=True)
@click.option("--seed", envvar="OTP_SEED", required=True)
2019-09-14 12:08:10 +00:00
@click.option("--email", required=True)
@click.option("--product-id", help="The uuid of the product", required=True)
2019-09-14 12:08:10 +00:00
def order(name, realm, seed, product_id, email):
data = {
**OTPCredentials(name, realm, seed).get_json(),
2019-09-14 12:08:10 +00:00
"product_id": product_id,
"email": email
}
2019-09-14 07:53:42 +00:00
r = requests.post("{}/product/order".format(config('UCLOUD_PAY_SERVER')),
json=data)
print(load_dump_pretty(r.content))