Index: main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/__init__.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/__init__.py	(revision 6935)
+++ main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/__init__.py	(revision 6936)
@@ -18,5 +18,6 @@
 from waeup.sirp.accesscodes.accesscode import (
     get_access_code, invalidate_accesscode, disable_accesscode,
-    reenable_accesscode, AccessCode, AccessCodeBatch, AccessCodeBatchContainer)
+    reenable_accesscode, purchase_accesscode,
+    AccessCode, AccessCodeBatch, AccessCodeBatchContainer)
 
 # Public API of this submodule
@@ -29,3 +30,4 @@
     'disable_accesscode',
     'reenable_accesscode',
+    'purchase_accesscode',
     ]
Index: main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscode.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscode.py	(revision 6935)
+++ main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscode.py	(revision 6936)
@@ -143,9 +143,9 @@
         """Create the entries for this batch.
         """
-        for num, pin in enumerate(self._getNewRandomNum(num=self.entry_num)):
+        for num, pin in enumerate(self.getNewRandomNum(num=self.entry_num)):
             self.addAccessCode(num, pin)
         return
 
-    def _getNewRandomNum(self, num=1):
+    def getNewRandomNum(self, num=1):
         """Create a set of ``num`` random numbers of 10 digits each.
 
@@ -177,8 +177,10 @@
         return self[ac_id]
 
-    def addAccessCode(self, num, pin):
+    def addAccessCode(self, num, pin, owner=None):
         """Add an access-code.
         """
         ac = AccessCode(num, pin)
+        if owner:
+            ac.owner = owner
         ac.__parent__ = self
         self[ac.representation] = ac
@@ -546,2 +548,17 @@
     """
     return fire_transition(access_code, 'reenable', comment=comment)
+
+def purchase_accesscode(batch_prefix, batch_num, owner):
+    """
+    """
+    batch_id = '%s-%s' % (batch_prefix, batch_num)
+    try:
+        batch = grok.getSite()['accesscodes'][batch_id]
+    except KeyError:
+        return None, u'No activation code available.'
+    rand_num = list(batch.getNewRandomNum())[0]
+    #import pdb; pdb.set_trace()
+    num = len(batch) + 1
+    batch.addAccessCode(num, rand_num, owner)
+    pin = u'%s-%s-%s' % (batch_prefix,batch_num,rand_num)
+    return pin, None
Index: main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py
===================================================================
--- main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py	(revision 6935)
+++ main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py	(revision 6936)
@@ -21,5 +21,6 @@
 from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
 from zope.component import createObject
-from waeup.sirp.accesscodes import invalidate_accesscode, get_access_code
+from waeup.sirp.accesscodes import (
+    invalidate_accesscode, get_access_code, purchase_accesscode)
 from waeup.sirp.accesscodes.workflow import USED
 from waeup.sirp.browser import (
@@ -924,4 +925,5 @@
     # from the incoming request.
     def update(self):
+        student = self.context.getStudent()
         self.context.r_amount_approved = self.context.amount_auth
         self.context.r_card_num = u'0000'
@@ -930,10 +932,19 @@
         self.context.payment_date = datetime.now()
         if self.context.p_category == 'clearance':
-            # Find valid CLR access code
-            pass
+            # Create CLR access code
+            pin, error = purchase_accesscode('CLR',0,student.student_id)
+            if error:
+                self.flash(error)
+                return
+            self.context.ac = pin
+            return
         elif self.context.p_category == 'schoolfee':
-            # Find valid SFE access code
-            pass
-        return
+            # Create SFE access code
+            pin, error = purchase_accesscode('SFE',0)
+            if error:
+                self.flash(error)
+                return
+            self.context.ac = pin
+            return
 
     def render(self):
@@ -1076,4 +1087,8 @@
 
     def update(self, SUBMIT=None):
+        if not self.context.state == 'admitted':
+            self.flash("Wrong state.")
+            self.redirect(self.url(self.context))
+            return
         self.ac_series = self.request.form.get('ac_series', None)
         self.ac_number = self.request.form.get('ac_number', None)
@@ -1084,10 +1099,10 @@
         code = get_access_code(pin)
         if not code:
-            self.flash('Access code is invalid.')
+            self.flash('Activation code is invalid.')
             return
         # Mark pin as used (this also fires a pin related transition)
         # and fire transition start_clearance
         if code.state == USED:
-            self.flash('Access code has already been used.')
+            self.flash('Activation code has already been used.')
             return
         else:
