Simple layout for PaymentMethod - will be changed..

This commit is contained in:
Endre Karlson 2013-03-06 13:22:34 +00:00
parent 06fac02168
commit b4ee207181
2 changed files with 106 additions and 51 deletions

View File

@ -27,8 +27,7 @@ import wsmeext.pecan as wsme_pecan
from billingstack.openstack.common import log from billingstack.openstack.common import log
from billingstack.openstack.common import jsonutils from billingstack.openstack.common import jsonutils
from billingstack.api.v1.models import Currency, Language, PGProvider, PGMethod from billingstack.api.v1 import models
from billingstack.api.v1.models import Customer, Merchant, User, Plan, Product
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
@ -75,57 +74,57 @@ class RestBase(RestController):
class CurrenciesController(RestBase): class CurrenciesController(RestBase):
"""Currsencies controller""" """Currsencies controller"""
@wsme_pecan.wsexpose([Currency]) @wsme_pecan.wsexpose([models.Currency])
def get_all(self): def get_all(self):
rows = request.central_api.currency_list(request.ctxt) rows = request.central_api.currency_list(request.ctxt)
return [Currency(**i) for i in rows] return [models.Currency(**i) for i in rows]
class LanguagesController(RestBase): class LanguagesController(RestBase):
"""Languages controller""" """Languages controller"""
@wsme_pecan.wsexpose([Language]) @wsme_pecan.wsexpose([models.Language])
def get_all(self): def get_all(self):
rows = request.central_api.language_list(request.ctxt) rows = request.central_api.language_list(request.ctxt)
return [Language(**i) for i in rows] return [models.Language(**i) for i in rows]
class PGProvidersController(RestBase): class PGProvidersController(RestBase):
""" """
PaymentGatewayProviders PaymentGatewayProviders
""" """
@wsme_pecan.wsexpose([PGProvider]) @wsme_pecan.wsexpose([models.PGProvider])
def get_all(self): def get_all(self):
rows = request.central_api.pg_provider_list(request.ctxt) rows = request.central_api.pg_provider_list(request.ctxt)
return [PGProvider(**i) for i in rows] return [models.PGProvider(**i) for i in rows]
class PGMethodsController(RestBase): class PGMethodsController(RestBase):
""" """
PGMethods lister... PGMethods lister...
""" """
@wsme_pecan.wsexpose([PGMethod]) @wsme_pecan.wsexpose([models.PGMethod])
def get_all(self): def get_all(self):
rows = request.central_api.pg_method_list(request.ctxt) rows = request.central_api.pg_method_list(request.ctxt)
return [PGMethod(**row) for row in rows] return [models.PGMethod(**row) for row in rows]
class UserController(RestBase): class UserController(RestBase):
"""User controller""" """User controller"""
__id__ = 'user' __id__ = 'user'
@wsme_pecan.wsexpose(User, unicode) @wsme_pecan.wsexpose(models.User, unicode)
def get_all(self): def get_all(self):
row = request.central_api.user_get(request.ctxt, self.id_) row = request.central_api.user_get(request.ctxt, self.id_)
return User(**dict(row)) return models.User(**dict(row))
@wsme_pecan.wsexpose(User, body=User) @wsme_pecan.wsexpose(models.User, body=models.User)
def put(self, body): def put(self, body):
row = request.central_api.user_update( row = request.central_api.user_update(
request.ctxt, request.ctxt,
self.id_, self.id_,
body.as_dict()) body.as_dict())
return User(**row) return models.User(**row)
@wsme_pecan.wsexpose() @wsme_pecan.wsexpose()
def delete(self): def delete(self):
@ -136,7 +135,7 @@ class UsersController(RestBase):
"""Users controller""" """Users controller"""
__resource__ = UserController __resource__ = UserController
@wsme_pecan.wsexpose([User], unicode) @wsme_pecan.wsexpose([models.User], unicode)
def get_all(self): def get_all(self):
criterion = { criterion = {
'merchant_id': request.context['merchant_id'] 'merchant_id': request.context['merchant_id']
@ -149,32 +148,32 @@ class UsersController(RestBase):
request.ctxt, request.ctxt,
criterion=criterion) criterion=criterion)
return [User(**i) for i in rows] return [models.User(**i) for i in rows]
@wsme_pecan.wsexpose(User, body=User) @wsme_pecan.wsexpose(models.User, body=models.User)
def post(self, body): def post(self, body):
row = request.central_api.user_add( row = request.central_api.user_add(
request.ctxt, request.ctxt,
request.context['merchant_id'], request.context['merchant_id'],
body.as_dict()) body.as_dict())
return User(**row) return models.User(**row)
# Plans # Plans
class PlanController(RestBase): class PlanController(RestBase):
__id__ = 'plan' __id__ = 'plan'
@wsme_pecan.wsexpose(Plan) @wsme_pecan.wsexpose(models.Plan)
def get_all(self): def get_all(self):
row = request.central_api.plan_get(request.ctxt, self.id_) row = request.central_api.plan_get(request.ctxt, self.id_)
return Plan(**row) return models.Plan(**row)
@wsme_pecan.wsexpose(Plan, body=Plan) @wsme_pecan.wsexpose(models.Plan, body=models.Plan)
def put(self, body): def put(self, body):
row = request.central_api.plan_update( row = request.central_api.plan_update(
request.ctxt, request.ctxt,
self.id_, self.id_,
body.as_dict()) body.as_dict())
return Plan(**row) return models.Plan(**row)
@wsme_pecan.wsexpose() @wsme_pecan.wsexpose()
def delete(self): def delete(self):
@ -184,36 +183,83 @@ class PlanController(RestBase):
class PlansController(RestBase): class PlansController(RestBase):
__resource__ = PlanController __resource__ = PlanController
@wsme_pecan.wsexpose([Plan]) @wsme_pecan.wsexpose([models.Plan])
def get_all(self): def get_all(self):
rows = request.central_api.plan_list(request.ctxt) rows = request.central_api.plan_list(request.ctxt)
return [Plan(**i) for i in rows] return [models.Plan(**i) for i in rows]
@wsme_pecan.wsexpose(Plan, body=Plan) @wsme_pecan.wsexpose(models.Plan, body=models.Plan)
def post(self, body): def post(self, body):
row = request.central_api.plan_add( row = request.central_api.plan_add(
request.ctxt, request.ctxt,
request.context['merchant_id'], request.context['merchant_id'],
body.as_dict()) body.as_dict())
return Plan(**row) return models.Plan(**row)
class PaymentMethodController(RestBase):
"""PaymentMethod controller"""
__id__ = 'payment_method'
@wsme_pecan.wsexpose(models.PaymentMethod, unicode)
def get_all(self):
row = request.central_api.payment_method_get(request.ctxt, self.id_)
return models.PaymentMethod(**dict(row))
@wsme_pecan.wsexpose(models.PaymentMethod, body=models.PaymentMethod)
def put(self, body):
row = request.central_api.payment_method_update(
request.ctxt,
self.id_,
body.as_dict())
return models.PaymentMethod(**row)
@wsme_pecan.wsexpose()
def delete(self):
request.central_api.payment_method_delete(request.ctxt, self.id_)
class PaymentMethodsController(RestBase):
"""PaymentMethods controller"""
__resource__ = PaymentMethodController
@wsme_pecan.wsexpose([models.PaymentMethod], unicode)
def get_all(self):
criterion = {
'customer_id': request.context['customer_id']
}
rows = request.central_api.payment_method_list(
request.ctxt,
criterion=criterion)
return [models.PaymentMethod(**i) for i in rows]
@wsme_pecan.wsexpose(models.PaymentMethod, body=models.PaymentMethod)
def post(self, body):
row = request.central_api.payment_method_add(
request.ctxt,
request.context['customer_id'],
body.as_dict())
return models.PaymentMethod(**row)
# Products # Products
class ProductController(RestBase): class ProductController(RestBase):
__id__ = 'product' __id__ = 'product'
@wsme_pecan.wsexpose(Product) @wsme_pecan.wsexpose(models.Product)
def get_all(self): def get_all(self):
row = request.central_api.product_get(request.ctxt, self.id_) row = request.central_api.product_get(request.ctxt, self.id_)
return Product(**row) return models.Product(**row)
@wsme_pecan.wsexpose(Product, body=Product) @wsme_pecan.wsexpose(models.Product, body=models.Product)
def put(self, body): def put(self, body):
row = request.central_api.product_update( row = request.central_api.product_update(
request.ctxt, request.ctxt,
self.id_, self.id_,
body.as_dict()) body.as_dict())
return Product(**row) return models.Product(**row)
@wsme_pecan.wsexpose() @wsme_pecan.wsexpose()
def delete(self): def delete(self):
@ -223,18 +269,18 @@ class ProductController(RestBase):
class ProductsController(RestBase): class ProductsController(RestBase):
__resource__ = ProductController __resource__ = ProductController
@wsme_pecan.wsexpose([Product]) @wsme_pecan.wsexpose([models.Product])
def get_all(self): def get_all(self):
rows = request.central_api.product_list(request.ctxt) rows = request.central_api.product_list(request.ctxt)
return [Product(**i) for i in rows] return [models.Product(**i) for i in rows]
@wsme_pecan.wsexpose(Product, body=Product) @wsme_pecan.wsexpose(models.Product, body=models.Product)
def post(self, body): def post(self, body):
row = request.central_api.product_add( row = request.central_api.product_add(
request.ctxt, request.ctxt,
request.context['merchant_id'], request.context['merchant_id'],
body.as_dict()) body.as_dict())
return Product(**row) return models.Product(**row)
# Customers # Customers
@ -242,21 +288,22 @@ class CustomerController(RestBase):
"""Customer controller""" """Customer controller"""
__id__ = 'customer' __id__ = 'customer'
__resource__ = { __resource__ = {
"payment-methods": PaymentMethodsController,
"users": UsersController "users": UsersController
} }
@wsme_pecan.wsexpose(Customer, unicode) @wsme_pecan.wsexpose(models.Customer, unicode)
def get_all(self): def get_all(self):
row = request.central_api.customer_get(request.ctxt, self.id_) row = request.central_api.customer_get(request.ctxt, self.id_)
return Customer(**dict(row)) return models.Customer(**dict(row))
@wsme_pecan.wsexpose(Customer, body=Customer) @wsme_pecan.wsexpose(models.Customer, body=models.Customer)
def put(self, body): def put(self, body):
row = request.central_api.customer_update( row = request.central_api.customer_update(
request.ctxt, request.ctxt,
self.id_, self.id_,
body.as_dict()) body.as_dict())
return Customer(**row) return models.Customer(**row)
@wsme_pecan.wsexpose() @wsme_pecan.wsexpose()
def delete(self): def delete(self):
@ -267,19 +314,19 @@ class CustomersController(RestBase):
"""Customers controller""" """Customers controller"""
__resource__ = CustomerController __resource__ = CustomerController
@wsme_pecan.wsexpose([Customer]) @wsme_pecan.wsexpose([models.Customer])
def get_all(self): def get_all(self):
rows = request.central_api.customer_list( rows = request.central_api.customer_list(
request.ctxt, criterion={"merchant_id": self.parent.id_}) request.ctxt, criterion={"merchant_id": self.parent.id_})
return [Customer(**o) for o in rows] return [models.Customer(**o) for o in rows]
@wsme_pecan.wsexpose(Customer, body=Customer) @wsme_pecan.wsexpose(models.Customer, body=models.Customer)
def post(self, body): def post(self, body):
rows = request.central_api.customer_add( rows = request.central_api.customer_add(
request.ctxt, request.ctxt,
request.context['merchant_id'], request.context['merchant_id'],
body.as_dict()) body.as_dict())
return Customer(**rows) return models.Customer(**rows)
class MerchantController(RestBase): class MerchantController(RestBase):
@ -291,18 +338,18 @@ class MerchantController(RestBase):
"users": UsersController "users": UsersController
} }
@wsme_pecan.wsexpose(Merchant) @wsme_pecan.wsexpose(models.Merchant)
def get_all(self): def get_all(self):
row = request.central_api.merchant_get(request.ctxt, self.id_) row = request.central_api.merchant_get(request.ctxt, self.id_)
return Merchant(**dict(row)) return models.Merchant(**dict(row))
@wsme_pecan.wsexpose(Merchant, body=Merchant) @wsme_pecan.wsexpose(models.Merchant, body=models.Merchant)
def put(self, body): def put(self, body):
row = request.central_api.merchant_update( row = request.central_api.merchant_update(
request.ctxt, request.ctxt,
self.id_, self.id_,
body.as_dict()) body.as_dict())
return Merchant(**row) return models.Merchant(**row)
@wsme_pecan.wsexpose() @wsme_pecan.wsexpose()
def delete(self): def delete(self):
@ -313,17 +360,17 @@ class MerchantsController(RestBase):
"""Merchants controller""" """Merchants controller"""
__resource__ = MerchantController __resource__ = MerchantController
@wsme_pecan.wsexpose([Merchant]) @wsme_pecan.wsexpose([models.Merchant])
def get_all(self): def get_all(self):
rows = request.central_api.merchant_list(request.ctxt) rows = request.central_api.merchant_list(request.ctxt)
return [Merchant(**o) for o in rows] return [models.Merchant(**o) for o in rows]
@wsme_pecan.wsexpose(Merchant, body=Merchant) @wsme_pecan.wsexpose(models.Merchant, body=models.Merchant)
def post(self, body): def post(self, body):
row = request.central_api.merchant_add( row = request.central_api.merchant_add(
request.ctxt, request.ctxt,
body.as_dict()) body.as_dict())
return Merchant(**row) return models.Merchant(**row)
class V1Controller(RestBase): class V1Controller(RestBase):
@ -338,4 +385,4 @@ class V1Controller(RestBase):
languages = LanguagesController() languages = LanguagesController()
merchants = MerchantsController() merchants = MerchantsController()
users = UsersController() users = UsersController()

View File

@ -47,6 +47,14 @@ class Language(Base):
title = text title = text
class PaymentMethod(Base):
name = text
identifier = text
expires = text
properties = DictType(key_type=text, value_type=metadata_property)
class PGMethod(DescribedBase): class PGMethod(DescribedBase):
type = text type = text