Changeset 12295 for main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba
- Timestamp:
- 22 Dec 2014, 16:14:04 (10 years ago)
- Location:
- main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments/interfaces.py
r12276 r12295 17 17 ## 18 18 import decimal 19 from zc.sourcefactory.basic import BasicSourceFactory 19 20 from zope import schema 21 from zope.component import getUtilitiesFor 20 22 from zope.interface import Interface 21 23 from waeup.ikoba.interfaces import ( 22 24 IIkobaObject, SimpleIkobaVocabulary, ContextualDictSourceFactoryBase) 23 25 from waeup.ikoba.interfaces import MessageFactory as _ 24 26 from waeup.ikoba.payments.currencies import ISO_4217_CURRENCIES_VOCAB 25 27 26 28 #: Possible states of payments … … 36 38 37 39 40 class PaymentGatewayServicesSource(BasicSourceFactory): 41 """A source that lists available payment services. 42 43 Suitable for forms etc. Token and value correspond to the name the 44 respective IPaymentGatewayService utility is registered with. 45 """ 46 47 _services = None 48 49 @classmethod 50 def services(cls): 51 """Cache the services registered on startup. 52 53 We assume that services do not change after startup. 54 """ 55 if cls._services is None: 56 cls._services = dict(getUtilitiesFor(IPaymentGatewayService)) 57 return cls._services 58 59 def getValues(self): 60 """Get payment gateway registration names. 61 """ 62 return sorted(PaymentGatewayServicesSource.services().keys()) 63 64 def getTitle(self, value): 65 """Get title of the respective service, if it exists. 66 """ 67 service = PaymentGatewayServicesSource.services().get(value, None) 68 if service is not None: 69 return service.title 70 71 38 72 class IPaymentGatewayService(Interface): 39 73 """A financial gateway service. … … 51 85 required=True, 52 86 ) 87 88 def create_payment(payer_id, payee_id, payment_item_id): 89 """Create a payment. 90 """ 53 91 54 92 … … 105 143 payed_item_id = schema.TextLine( 106 144 title=u'Payed Item ID', 145 default=None, 146 required=True, 147 ) 148 149 gateway_service = schema.Choice( 150 title=u'Payment Gateway', 151 description=u'Payment gateway that handles this transaction.', 152 source=PaymentGatewayServicesSource(), 107 153 default=None, 108 154 required=True, … … 188 234 def approve(): 189 235 "Approve an online payment and set to paid." 236 237 238 class IPayer(Interface): 239 """A payer. 240 """ 241 payer_id = schema.TextLine( 242 title=u'Payer ID', 243 required=True, 244 ) 245 246 247 class IPayee(Interface): 248 """A person or institution being paid. 249 """ 250 payee_id = schema.TextLine( 251 title=u'Payee ID', 252 required=True 253 ) 254 255 256 class IPaymentItem(Interface): 257 """Something to sell. 258 """ 259 item_id = schema.TextLine( 260 title=u'Payment Item ID', 261 required=True, 262 ) 263 264 title = schema.TextLine( 265 title=u'Title', 266 description=u'A short title of the good sold.', 267 required=True, 268 default=u'Unnamed' 269 ) 270 271 amount = schema.Decimal( 272 title=u'Amount', 273 description=u'Total amount, includung any taxes, fees, etc.', 274 required=True, 275 default=decimal.Decimal('0.00'), 276 ) 277 278 currency = schema.Choice( 279 title=u'Currency', 280 source=ISO_4217_CURRENCIES_VOCAB, 281 required=True, 282 default='USD', 283 ) -
main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments/tests/test_interfaces.py
r12159 r12295 20 20 """ 21 21 from zope.interface.verify import verifyClass, verifyObject 22 from waeup.ikoba.payments.interfaces import IPaymentsContainer 22 from waeup.ikoba.payments.interfaces import ( 23 IPaymentsContainer, PaymentGatewayServicesSource, 24 ) 23 25 from waeup.ikoba.payments.container import PaymentsContainer 24 26 from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase) … … 48 50 self.assertRaises( 49 51 NotImplementedError, container.clear) 52 53 def test_payment_gateway_services_source(self): 54 # the payment gateway services source provides a list of registered 55 # payment gateways 56 source = PaymentGatewayServicesSource() 57 services = list(source) 58 assert len(services) > 0 59 60 def test_payment_gateway_services_source_title(self): 61 # we can get titles from gateway sources 62 source = PaymentGatewayServicesSource() 63 service1 = list(source)[0] 64 title = source.factory.getTitle(service1) 65 assert title != service1 66 assert isinstance(title, basestring)
Note: See TracChangeset for help on using the changeset viewer.