## 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 2135 2007-08-21 08:11:16Z 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 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) s_brain = context.students_catalog(id=student_id)[0] session = s_brain.session next_session, next_session_str = context.getNextSessionId(session) amount,description = context.getSchoolFee(s_brain.faculty,session) 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 = {} order_id = ds.get('pin_n') p_id = "p%s" % order_id 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 info['type_description'] = 'School Fee for Session %s' % next_session_str 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') if next_session == context.getSessionId()[-2:]: wftool.doActionFor(student,'pay_school_fee') else: study_course = getattr(student,'study_course') #wftool.doActionFor(study_course,'open') study_course_doc = study_course.getContent() next_level = "%s" % (int(s_brain.level) + 100) study_course_doc.edit(mapping= {'current_level': next_level, 'current_session': next_session,}) 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)