## Script (Python) "pay_by_sc" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## # $Id: pay_by_sc.py 5205 2010-05-25 17:30:20Z henrik $ """ pay online """ import logging from urllib import urlencode logger = logging.getLogger('Skins.pay_by_sc') import DateTime try: from Products.zdb import set_trace except: def set_trace(): pass if context.portal_membership.isAnonymousUser(): return None wftool = context.portal_workflow lt = context.portal_layouts request = context.REQUEST students = context.portal_url.getPortalObject().campus.students student_id = context.getStudentId() if student_id is None: return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) student = getattr(students,student_id) student_record = context.students_catalog.getRecordByKey(student_id) # session = student_record.session # next_session, next_session_str = context.getNextSessionId(session) next_info = context.getNextInfo(student_record) next_session_id = next_info['next_session_id'] next_session_str = next_info['next_session_str'] next_level_id = next_info['next_level_id'] next_transition = next_info['next_transition'] next_verdict = next_info['next_verdict'] next_previous_verdict = next_info['next_previous_verdict'] if not next_info['payment_allowed']: logger.info('%s called pay_by_sc manually' % student_id) return 'Do not call this form manually!' validate = request.has_key("cpsdocument_create_button") res,psm,ds = lt.renderLayout(layout_id= 'student_schoolfee', schema_id= 'payment', context=context, mapping=validate and request, ob={}, layout_mode="create", formaction = "pay_by_sc", button = 'Pay', commit = False, ) if psm == 'invalid': psm = 'Please correct your errors!' return context.pay_by_sc_form(rendered = res, psm = psm, mode = 'edit', next_session_str = next_session_str, ds = ds, ) elif psm == '': return context.pay_by_sc_form(rendered = res, psm = None, mode = 'edit', next_session_str = next_session_str, ds = ds, ) elif psm == 'valid': pass if "payments" not in student.objectIds(): student.invokeFactory('PaymentsFolder','payments') payments = getattr(student,'payments') d = {} d['Title'] = 'Payments' payments.getContent().edit(mapping=d) wftool.doActionFor(payments,'open') else: payments = getattr(student,'payments') #from Products.zdb import set_trace; set_trace() info = {} p_id = "p%s" % ds.get('pin_n') pin = str(ds.get('pin')) try: cost = context.portal_pins(pin="".join(pin.split('-')))[0].cost except: cost = "n/a" try: x = float(cost) except: cost = "n/a" if not hasattr(payments,p_id): now = DateTime.DateTime() info['date'] = now info['amount'] = cost pin = info['order_id'] = "%s" % pin #info['type_code'] = "%s" % pin #type_code is redundant and will be removed soon info['type_description'] = 'School Fee for Session %s' % next_session_str info['type'] = 'sc' info['status'] = 'paid' info['session_id'] = next_session_id info['item'] = student_record.course info['category'] = 'schoolfee' info['resp_code'] = "SC" info['resp_desc'] = "SC Payment Successful" payments.invokeFactory('Payment', p_id) payment = getattr(payments,p_id) wftool = context.portal_workflow wftool.doActionFor(payment,'open') payment.getContent().edit(mapping=info) wftool.doActionFor(payment,'close') study_course = getattr(student,'study_course') try: wftool.doActionFor(study_course,'open') except: pass study_course.getContent().edit(mapping= {'current_level': next_level_id, 'current_session': next_session_id, 'current_verdict': next_verdict, 'previous_verdict': next_previous_verdict, }) if next_transition: wftool.doActionFor(student,next_transition) logger.info('%s paid school fee by scratch card' % student_id) else: logger.info('%s repeatedly paid school fee by scratch card' % student_id) url = "%s/payments" % (student.absolute_url()) request.RESPONSE.redirect(url)