Many more changes
This commit is contained in:
parent
da54a59ca2
commit
1a76d2b5f3
11 changed files with 386 additions and 283 deletions
38
helper.py
38
helper.py
|
|
@ -1,26 +1,14 @@
|
|||
import config
|
||||
from stripe_utils import StripeUtils
|
||||
import logging
|
||||
|
||||
etcd_client = config.etcd_client
|
||||
from stripe_utils import StripeUtils
|
||||
|
||||
|
||||
def get_plan_id_from_product(product):
|
||||
plan_id = 'ucloud-v1-'
|
||||
plan_id += product['name'].strip().replace(' ', '-')
|
||||
# plan_id += '-' + product['type']
|
||||
return plan_id
|
||||
|
||||
|
||||
def get_order_id():
|
||||
order_id_kv = etcd_client.get('/v1/last_order_id')
|
||||
if order_id_kv is not None:
|
||||
order_id = int(order_id_kv.value) + 1
|
||||
else:
|
||||
order_id = 0
|
||||
etcd_client.put('/v1/last_order_id', str(order_id))
|
||||
return 'OR-{}'.format(order_id)
|
||||
|
||||
|
||||
def get_pricing(price_in_chf_cents, product_type, recurring_period):
|
||||
if product_type == 'recurring':
|
||||
return 'CHF {}/{}'.format(price_in_chf_cents/100, recurring_period)
|
||||
|
|
@ -53,10 +41,26 @@ def get_token(card_number, cvc, exp_month, exp_year):
|
|||
return None
|
||||
|
||||
|
||||
def resolve_product_usable_id(usable_id, etcd_client):
|
||||
def resolve_product(usable_id, etcd_client):
|
||||
products = etcd_client.get_prefix('/v1/products/', value_in_json=True)
|
||||
for p in products:
|
||||
if p.value['usable-id'] == usable_id:
|
||||
print(p.value['uuid'], usable_id)
|
||||
return p.value['uuid']
|
||||
return p.value
|
||||
return None
|
||||
|
||||
|
||||
def calculate_charges(specification, data):
|
||||
logging.debug('Calculating charges for specs:{} and data:{}'.format(specification, data))
|
||||
one_time_charge = 0
|
||||
recurring_charge = 0
|
||||
for feature_name, feature_detail in specification['features'].items():
|
||||
if feature_detail['constant']:
|
||||
data[feature_name] = 1
|
||||
|
||||
if feature_detail['unit']['type'] != 'str':
|
||||
one_time_charge += feature_detail['one_time_fee']
|
||||
recurring_charge += (
|
||||
feature_detail['price_per_unit_per_period'] * data[feature_name] /
|
||||
feature_detail['unit']['value']
|
||||
)
|
||||
return one_time_charge, recurring_charge
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue