From 059b5debf0f00db362795187d89a00cbbbbe58cc Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 13 Sep 2019 10:58:05 +0530 Subject: [PATCH 01/21] Add product command --- commands/product.py | 55 +++++++++++++++++++++++++++++++++++++++++++++ ucloud.py | 2 ++ 2 files changed, 57 insertions(+) create mode 100755 commands/product.py diff --git a/commands/product.py b/commands/product.py new file mode 100755 index 0000000..16dbb31 --- /dev/null +++ b/commands/product.py @@ -0,0 +1,55 @@ +import click +import requests + +from decouple import config +from .helper import OTPCredentials, load_dump_pretty + + +def product_command(command, otp): + data = {**otp.get_json(), "action": command} + r = requests.post(f"{config('UCLOUD_PAY_SERVER')}/product/action", + json=data) + return r + + +@click.group() +def product(): + pass + + +@product.command("list") +def list(): + r = requests.get(f"{config('UCLOUD_PAY_SERVER')}/product/list") + 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-duration", required=False, + help="Only used for products with recurring costs", + type=int) +@click.option("--product-recurring-duration-units", required=False, type=int, + help="Unit of the recurring costs", default=0) +def add(name, realm, seed, product_name, product_description, product_type, + product_price, product_recurring_duration, + product_recurring_duration_units): + 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_duration": product_recurring_duration, + "product_recurring_duration_units": product_recurring_duration_units + } + r = requests.post(f"{config('UCLOUD_API_SERVER')}/product/add", json=data) + print(load_dump_pretty(r.content)) diff --git a/ucloud.py b/ucloud.py index ceb26fc..7f80b92 100755 --- a/ucloud.py +++ b/ucloud.py @@ -4,6 +4,7 @@ from commands.vm import vm from commands.user import user from commands.host import host from commands.image import image +from commands.product import product @click.group() @@ -15,6 +16,7 @@ entry_point.add_command(vm) entry_point.add_command(user) entry_point.add_command(image) entry_point.add_command(host) +entry_point.add_command(product) if __name__ == "__main__": entry_point() From 7a316a4a321ad3a7b1c618befbe0143ede0a4dc8 Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 13 Sep 2019 11:10:22 +0530 Subject: [PATCH 02/21] Update README.md --- README.md | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 38b595d..14de994 100755 --- a/README.md +++ b/README.md @@ -1 +1,32 @@ -# ucloud-cli \ No newline at end of file +# ucloud-cli + + +### Listing available ucloud products + +``` +(ucloud-cli) [test@ungleich ucloud-cli]$ UCLOUD_PAY_SERVER=http://127.0.0.1:5000 python ucloud.py product list +{ + "/v1/products/": { + "description": "YEARLY IPV6 subscription", + "name": "IPV6 VPN", + "price": 12000, + "recurring_duration": 31536000, + "recurring_duration_units": 0, + "type": "recurring" + } +} +``` + +### Adding new products +``` +(ucloud-cli) [test@ungleich ucloud-cli]$ UCLOUD_PAY_SERVER=http://127.0.0.1:5000 python ucloud.py product add \ +--name mravi \ +--realm test \ +--seed stest \ +--product-name "IPV6 VPN" \ +--product-description="YEARLY IPV6 subscription" \ +--product-type=recurring \ +--product-recurring-duration=31536000 \ +--product-price=12000 + +``` \ No newline at end of file From 984005977d9c1fa3ddbf39707b4c80ab7806cd08 Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 13 Sep 2019 11:17:05 +0530 Subject: [PATCH 03/21] Remove unused code --- commands/product.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/commands/product.py b/commands/product.py index 16dbb31..abb76e1 100755 --- a/commands/product.py +++ b/commands/product.py @@ -5,13 +5,6 @@ from decouple import config from .helper import OTPCredentials, load_dump_pretty -def product_command(command, otp): - data = {**otp.get_json(), "action": command} - r = requests.post(f"{config('UCLOUD_PAY_SERVER')}/product/action", - json=data) - return r - - @click.group() def product(): pass From 5215ff1edf754ee823c1554027be9682f94d0307 Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 13 Sep 2019 19:26:56 +0530 Subject: [PATCH 04/21] Change a couple of f-strings to format --- commands/product.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/commands/product.py b/commands/product.py index abb76e1..9b7a239 100755 --- a/commands/product.py +++ b/commands/product.py @@ -12,7 +12,7 @@ def product(): @product.command("list") def list(): - r = requests.get(f"{config('UCLOUD_PAY_SERVER')}/product/list") + r = requests.get("{}/product/list".format(config('UCLOUD_PAY_SERVER'))) print(load_dump_pretty(r.content)) @@ -44,5 +44,6 @@ def add(name, realm, seed, product_name, product_description, product_type, "product_recurring_duration": product_recurring_duration, "product_recurring_duration_units": product_recurring_duration_units } - r = requests.post(f"{config('UCLOUD_API_SERVER')}/product/add", json=data) + r = requests.post("{}/product/add".format(config('UCLOUD_API_SERVER')), + json=data) print(load_dump_pretty(r.content)) From 48c852ce731234f25cade4357ef9ee1133f237ea Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 13 Sep 2019 23:40:23 +0530 Subject: [PATCH 05/21] Add user register-payment --- commands/user.py | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/commands/user.py b/commands/user.py index cd23d31..e73e1db 100755 --- a/commands/user.py +++ b/commands/user.py @@ -1,8 +1,7 @@ import click -import json import requests - from decouple import config + from .helper import OTPCredentials, load_dump_pretty @@ -17,7 +16,8 @@ def user(): @click.option("--seed", envvar="OTP_SEED", required=True) def list_files(name, realm, seed): data = OTPCredentials(name, realm, seed).get_json() - r = requests.get(f"{config('UCLOUD_API_SERVER')}/user/files", json=data) + r = requests.get("{}/user/files".format(config('UCLOUD_API_SERVER')), + json=data) print(load_dump_pretty(r.content)) @@ -27,5 +27,35 @@ def list_files(name, realm, seed): @click.option("--seed", envvar="OTP_SEED", required=True) def list_vms(name, realm, seed): data = OTPCredentials(name, realm, seed).get_json() - r = requests.get(f"{config('UCLOUD_API_SERVER')}/user/vms", json=data) + r = requests.get("{}/user/vms".format(config('UCLOUD_API_SERVER')), + json=data) + print(load_dump_pretty(r.content)) + + +@user.command("register-payment") +@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("--cc", required=True) +@click.option("--number", required=True) +@click.option("--cvc", required=True) +@click.option("--expiry-month", required=True, help="MM", type=str) +@click.option("--expiry-year", required=True, help="YY", type=str) +@click.option("--card-holder-name", required=True, + help="The name as printed on the card", type=str) +@click.option("--email", required=True, help="Email address", type=str) +def register_payment(name, realm, seed, number, cvc, expiry_year, expiry_month, + card_holder_name, email): + data = { + **OTPCredentials(name, realm, seed).get_json(), + "card_number": number, + "cvc": cvc, + "expiry_year": expiry_year, + "expiry_month": expiry_month, + "card_holder_name": card_holder_name, + "email": email + } + r = requests.get( + "{}/user/register_payment".format(config('UCLOUD_PAY_SERVER')), + json=data) print(load_dump_pretty(r.content)) From 22c6c2312027dd064a1e9e5dbcda6d5ad673bab8 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 14 Sep 2019 00:36:55 +0530 Subject: [PATCH 06/21] Make cc a flag and use post --- commands/user.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/commands/user.py b/commands/user.py index e73e1db..ca78c6b 100755 --- a/commands/user.py +++ b/commands/user.py @@ -36,7 +36,7 @@ def list_vms(name, realm, seed): @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("--cc", required=True) +@click.option("--cc", required=True, is_flag=True) @click.option("--number", required=True) @click.option("--cvc", required=True) @click.option("--expiry-month", required=True, help="MM", type=str) @@ -45,7 +45,7 @@ def list_vms(name, realm, seed): help="The name as printed on the card", type=str) @click.option("--email", required=True, help="Email address", type=str) def register_payment(name, realm, seed, number, cvc, expiry_year, expiry_month, - card_holder_name, email): + card_holder_name, email, cc): data = { **OTPCredentials(name, realm, seed).get_json(), "card_number": number, @@ -55,7 +55,7 @@ def register_payment(name, realm, seed, number, cvc, expiry_year, expiry_month, "card_holder_name": card_holder_name, "email": email } - r = requests.get( + r = requests.post( "{}/user/register_payment".format(config('UCLOUD_PAY_SERVER')), json=data) print(load_dump_pretty(r.content)) From 32428e00e07e4ad211bdd0b32a7dcd8657d8bdfe Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 14 Sep 2019 12:47:45 +0530 Subject: [PATCH 07/21] Add products on ucloud pay server --- commands/product.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/product.py b/commands/product.py index 9b7a239..9bf6538 100755 --- a/commands/product.py +++ b/commands/product.py @@ -44,6 +44,6 @@ def add(name, realm, seed, product_name, product_description, product_type, "product_recurring_duration": product_recurring_duration, "product_recurring_duration_units": product_recurring_duration_units } - r = requests.post("{}/product/add".format(config('UCLOUD_API_SERVER')), + r = requests.post("{}/product/add".format(config('UCLOUD_PAY_SERVER')), json=data) print(load_dump_pretty(r.content)) From 8945f557f9dfbf802b2290d074676736db02beee Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 14 Sep 2019 12:58:39 +0530 Subject: [PATCH 08/21] Add order list/product commands --- commands/order.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 commands/order.py diff --git a/commands/order.py b/commands/order.py new file mode 100644 index 0000000..e69de29 From ccde9d9f5b1e781bba80f4411885e82de26471a0 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 14 Sep 2019 13:23:11 +0530 Subject: [PATCH 09/21] Make command "product order" rather than "order product" --- commands/order.py | 0 commands/product.py | 15 +++++++++++++++ 2 files changed, 15 insertions(+) delete mode 100644 commands/order.py diff --git a/commands/order.py b/commands/order.py deleted file mode 100644 index e69de29..0000000 diff --git a/commands/product.py b/commands/product.py index 9bf6538..1a61ae6 100755 --- a/commands/product.py +++ b/commands/product.py @@ -47,3 +47,18 @@ def add(name, realm, seed, product_name, product_description, product_type, r = requests.post("{}/product/add".format(config('UCLOUD_PAY_SERVER')), json=data) 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) +@click.option("--product-id", help="The uuid of the product", required=True) +def order(name, realm, seed, product_id): + data = { + **OTPCredentials(name, realm, seed).get_json(), + "product_id": product_id + } + r = requests.post("{}/order/product".format(config('UCLOUD_PAY_SERVER')), + json=data) + print(load_dump_pretty(r.content)) \ No newline at end of file From 1fbb5974f2d56f81e64be354c64351aca160fe42 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 14 Sep 2019 13:23:42 +0530 Subject: [PATCH 10/21] Change url of the request --- commands/product.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/product.py b/commands/product.py index 1a61ae6..1564b54 100755 --- a/commands/product.py +++ b/commands/product.py @@ -59,6 +59,6 @@ def order(name, realm, seed, product_id): **OTPCredentials(name, realm, seed).get_json(), "product_id": product_id } - r = requests.post("{}/order/product".format(config('UCLOUD_PAY_SERVER')), + r = requests.post("{}/product/order".format(config('UCLOUD_PAY_SERVER')), json=data) print(load_dump_pretty(r.content)) \ No newline at end of file From e1316bd07ce68581f64bbbde2405deb56e16e7ec Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 14 Sep 2019 16:55:24 +0530 Subject: [PATCH 11/21] Update README --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 14de994..c736436 100755 --- a/README.md +++ b/README.md @@ -29,4 +29,19 @@ --product-recurring-duration=31536000 \ --product-price=12000 +``` + +### Register a payment method (cc for now) + +``` +(ucloud-cli) [test@ungleich ucloud-cli]$ UCLOUD_PAY_SERVER=http://127.0.0.1:5000 python ucloud.py user register-payment \ + --name xxxxxxxxxxxx \ + --realm xxxxxxxx \ + --seed xxxxxxxxxx \ + --cc --number 4242424242424242 \ + --cvc 225 \ + --expiry-month 08 \ + --expiry-year 2022 \ + --card-holder-name "The tester" \ + --email "monty@python.com" ``` \ No newline at end of file From c91454e0d2e8accb5f49782bcd4f2be83971794e Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 14 Sep 2019 17:38:10 +0530 Subject: [PATCH 12/21] Also pass email of the user for now --- commands/product.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/commands/product.py b/commands/product.py index 1564b54..2d45a38 100755 --- a/commands/product.py +++ b/commands/product.py @@ -53,11 +53,13 @@ def add(name, realm, seed, product_name, product_description, product_type, @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("--email", required=True) @click.option("--product-id", help="The uuid of the product", required=True) -def order(name, realm, seed, product_id): +def order(name, realm, seed, product_id, email): data = { **OTPCredentials(name, realm, seed).get_json(), - "product_id": product_id + "product_id": product_id, + "email": email } r = requests.post("{}/product/order".format(config('UCLOUD_PAY_SERVER')), json=data) From a968918eeea13a4bd8159f547b15c86878fee762 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 14 Sep 2019 22:45:56 +0530 Subject: [PATCH 13/21] Add order list command --- commands/order.py | 25 +++++++++++++++++++++++++ ucloud.py | 2 ++ 2 files changed, 27 insertions(+) create mode 100644 commands/order.py diff --git a/commands/order.py b/commands/order.py new file mode 100644 index 0000000..beb6b70 --- /dev/null +++ b/commands/order.py @@ -0,0 +1,25 @@ +import click +import requests + +from decouple import config +from .helper import OTPCredentials, load_dump_pretty + + +@click.group() +def order(): + pass + + +@order.command("list") +@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("--email", required=True) +def list(name, realm, seed, email): + data = { + **OTPCredentials(name, realm, seed).get_json(), + "email": email + } + r = requests.get("{}/order/list".format(config('UCLOUD_PAY_SERVER')), + json=data) + print(load_dump_pretty(r.content)) diff --git a/ucloud.py b/ucloud.py index 7f80b92..964ade8 100755 --- a/ucloud.py +++ b/ucloud.py @@ -5,6 +5,7 @@ from commands.user import user from commands.host import host from commands.image import image from commands.product import product +from commands.order import order @click.group() @@ -17,6 +18,7 @@ entry_point.add_command(user) entry_point.add_command(image) entry_point.add_command(host) entry_point.add_command(product) +entry_point.add_command(order) if __name__ == "__main__": entry_point() From 2b5262f5302909a56c52e1a5d1170ee36746c2a1 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 14 Sep 2019 22:52:37 +0530 Subject: [PATCH 14/21] Update README --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index c736436..af32172 100755 --- a/README.md +++ b/README.md @@ -44,4 +44,25 @@ --expiry-year 2022 \ --card-holder-name "The tester" \ --email "monty@python.com" +``` + +### Order a product + +``` +(ucloud-cli) [test@ungleich ucloud-cli]$ UCLOUD_PAY_SERVER=http://127.0.0.1:5000 python ucloud.py product order \ +--name xxxxxxxxxxxxxxxxx \ +--realm xxxxxxxxxxxxxxxx \ +--seed xxxxxxxxxxxxxxxx \ +--email "monty@python.com" \ +--product-id aabc34208e514803a0ee62d697b37e8c +``` + +### Listing different orders + +``` +(ucloud-cli) [test@ungleich ucloud-cli]$ UCLOUD_PAY_SERVER=127.0.0.1:5000 python ucloud.py order list \ +--name xxxxxxxxxxxxxxx \ +--realm xxxxxxxxxxxxxxx \ +--seed xxxxxxxxxxxxxxxxx \ +--email "monty@python.com" ``` \ No newline at end of file From a8a53ff28f6f18501e2ff630ee957d341cf7a80c Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 19 Sep 2019 10:54:36 +0530 Subject: [PATCH 15/21] Add minimum_subscription_duration for product --- commands/product.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/commands/product.py b/commands/product.py index 2d45a38..9ae4b72 100755 --- a/commands/product.py +++ b/commands/product.py @@ -32,9 +32,13 @@ def list(): type=int) @click.option("--product-recurring-duration-units", required=False, type=int, help="Unit of the recurring costs", default=0) +@click.option("--product-minimum-subscription-duration", required=False, + type=int, help="Minimum duration for which a user needs to " + "subscribe the product for", default=0) def add(name, realm, seed, product_name, product_description, product_type, product_price, product_recurring_duration, - product_recurring_duration_units): + product_recurring_duration_units, + product_minimum_subscription_duration): data = { **OTPCredentials(name, realm, seed).get_json(), "product_name": product_name, @@ -42,7 +46,9 @@ def add(name, realm, seed, product_name, product_description, product_type, "product_type": product_type, "product_price": product_price, "product_recurring_duration": product_recurring_duration, - "product_recurring_duration_units": product_recurring_duration_units + "product_recurring_duration_units": product_recurring_duration_units, + "product_minimum_subscription_duration": + product_minimum_subscription_duration } r = requests.post("{}/product/add".format(config('UCLOUD_PAY_SERVER')), json=data) From c17d9b9059d90b10500cf9e21bbbb0a977110d38 Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 19 Sep 2019 11:26:10 +0530 Subject: [PATCH 16/21] Don't ask product-recurring-duration-units, change duration -> period --- README.md | 11 ++++++----- commands/product.py | 20 ++++++++------------ 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index af32172..c9a8e11 100755 --- a/README.md +++ b/README.md @@ -20,14 +20,15 @@ ### Adding new products ``` (ucloud-cli) [test@ungleich ucloud-cli]$ UCLOUD_PAY_SERVER=http://127.0.0.1:5000 python ucloud.py product add \ ---name mravi \ ---realm test \ ---seed stest \ +--name xxxxxxxxxxxx \ +--realm xxxxxxxxxxxx \ +--seed xxxxxxxxxxxx \ --product-name "IPV6 VPN" \ --product-description="YEARLY IPV6 subscription" \ --product-type=recurring \ ---product-recurring-duration=31536000 \ ---product-price=12000 +--product-recurring-period=year \ +--product-price=12000 \ +--product-minimum-subscription-period=year ``` diff --git a/commands/product.py b/commands/product.py index 9ae4b72..6afd10e 100755 --- a/commands/product.py +++ b/commands/product.py @@ -27,28 +27,24 @@ def list(): type=click.Choice(['one-time', 'recurring'])) @click.option("--product-price", required=True, help="Price in CHF cents", type=int) -@click.option("--product-recurring-duration", required=False, +@click.option("--product-recurring-period", required=False, help="Only used for products with recurring costs", type=int) -@click.option("--product-recurring-duration-units", required=False, type=int, - help="Unit of the recurring costs", default=0) -@click.option("--product-minimum-subscription-duration", required=False, - type=int, help="Minimum duration for which a user needs to " +@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) def add(name, realm, seed, product_name, product_description, product_type, - product_price, product_recurring_duration, - product_recurring_duration_units, - product_minimum_subscription_duration): + product_price, product_recurring_period, + product_minimum_subscription_period): 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_duration": product_recurring_duration, - "product_recurring_duration_units": product_recurring_duration_units, - "product_minimum_subscription_duration": - product_minimum_subscription_duration + "product_recurring_period": product_recurring_period, + "product_minimum_subscription_period": + product_minimum_subscription_period } r = requests.post("{}/product/add".format(config('UCLOUD_PAY_SERVER')), json=data) From ed74b2ecb34aedec9c76276aba70dfca4875ae97 Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 19 Sep 2019 15:49:09 +0530 Subject: [PATCH 17/21] Remove email dependency for order --- commands/order.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/commands/order.py b/commands/order.py index beb6b70..ca52006 100644 --- a/commands/order.py +++ b/commands/order.py @@ -14,11 +14,9 @@ def 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) -@click.option("--email", required=True) -def list(name, realm, seed, email): +def list(name, realm, seed): data = { - **OTPCredentials(name, realm, seed).get_json(), - "email": email + **OTPCredentials(name, realm, seed).get_json() } r = requests.get("{}/order/list".format(config('UCLOUD_PAY_SERVER')), json=data) From 22ac971db8f479200d61f9a86aa2a6dbc06b5cdc Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 19 Sep 2019 15:50:14 +0530 Subject: [PATCH 18/21] Remove email dependency for product --- commands/product.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/commands/product.py b/commands/product.py index 6afd10e..33861d2 100755 --- a/commands/product.py +++ b/commands/product.py @@ -1,7 +1,7 @@ import click import requests - from decouple import config + from .helper import OTPCredentials, load_dump_pretty @@ -28,11 +28,10 @@ def list(): @click.option("--product-price", required=True, help="Price in CHF cents", type=int) @click.option("--product-recurring-period", required=False, - help="Only used for products with recurring costs", - type=int) + help="Only used for products with recurring costs") @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) + help="Minimum period for which a user needs to " + "subscribe the product for") def add(name, realm, seed, product_name, product_description, product_type, product_price, product_recurring_period, product_minimum_subscription_period): @@ -55,14 +54,12 @@ def add(name, realm, seed, product_name, product_description, product_type, @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("--email", required=True) @click.option("--product-id", help="The uuid of the product", required=True) -def order(name, realm, seed, product_id, email): +def order(name, realm, seed, product_id): data = { **OTPCredentials(name, realm, seed).get_json(), - "product_id": product_id, - "email": email + "product_id": product_id } r = requests.post("{}/product/order".format(config('UCLOUD_PAY_SERVER')), json=data) - print(load_dump_pretty(r.content)) \ No newline at end of file + print(load_dump_pretty(r.content)) From 54eac5677e6162b324a5ca47e1a89e18e35d4208 Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 19 Sep 2019 15:50:36 +0530 Subject: [PATCH 19/21] Remove email dependency for user --- commands/user.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/commands/user.py b/commands/user.py index ca78c6b..77dc487 100755 --- a/commands/user.py +++ b/commands/user.py @@ -43,17 +43,15 @@ def list_vms(name, realm, seed): @click.option("--expiry-year", required=True, help="YY", type=str) @click.option("--card-holder-name", required=True, help="The name as printed on the card", type=str) -@click.option("--email", required=True, help="Email address", type=str) def register_payment(name, realm, seed, number, cvc, expiry_year, expiry_month, - card_holder_name, email, cc): + card_holder_name, cc): data = { **OTPCredentials(name, realm, seed).get_json(), "card_number": number, "cvc": cvc, "expiry_year": expiry_year, "expiry_month": expiry_month, - "card_holder_name": card_holder_name, - "email": email + "card_holder_name": card_holder_name } r = requests.post( "{}/user/register_payment".format(config('UCLOUD_PAY_SERVER')), From 3ab363cdbe487f6ba27e45ce8262b3e9fc2b7f8d Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 19 Sep 2019 17:44:20 +0530 Subject: [PATCH 20/21] Remove email dependency README --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c9a8e11..29ed1d8 100755 --- a/README.md +++ b/README.md @@ -43,8 +43,7 @@ --cvc 225 \ --expiry-month 08 \ --expiry-year 2022 \ - --card-holder-name "The tester" \ - --email "monty@python.com" + --card-holder-name "The tester" ``` ### Order a product @@ -54,7 +53,6 @@ --name xxxxxxxxxxxxxxxxx \ --realm xxxxxxxxxxxxxxxx \ --seed xxxxxxxxxxxxxxxx \ ---email "monty@python.com" \ --product-id aabc34208e514803a0ee62d697b37e8c ``` @@ -64,6 +62,5 @@ (ucloud-cli) [test@ungleich ucloud-cli]$ UCLOUD_PAY_SERVER=127.0.0.1:5000 python ucloud.py order list \ --name xxxxxxxxxxxxxxx \ --realm xxxxxxxxxxxxxxx \ ---seed xxxxxxxxxxxxxxxxx \ ---email "monty@python.com" +--seed xxxxxxxxxxxxxxxxx ``` \ No newline at end of file From c744ba113404133ffa0078438937c5bdd0a7d22b Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 19 Sep 2019 22:04:53 +0530 Subject: [PATCH 21/21] Update README to include creating one-time payment products --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 29ed1d8..e6df687 100755 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ ``` ### Adding new products + +##### Recurring product (subscription) ``` (ucloud-cli) [test@ungleich ucloud-cli]$ UCLOUD_PAY_SERVER=http://127.0.0.1:5000 python ucloud.py product add \ --name xxxxxxxxxxxx \ @@ -32,6 +34,18 @@ ``` +##### One-time payment product +``` +(ucloud-cli) [test@ungleich ucloud-cli]$ UCLOUD_PAY_SERVER=https://ucloud-pay-dev.ungleich.ch python ucloud.py product add \ +--name xxxxxxxxxxxx \ +--realm xxxxxxxxxxxx \ +--seed xxxxxxxxxxxx \ +--product-name "One time membership" \ +--product-description="One time membership fees" \ +--product-type=one-time \ +--product-price=3500 +``` + ### Register a payment method (cc for now) ```