## 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 1390 2007-02-05 09:02:07Z joachim $ """ pay online """ import logging from urllib import urlencode logger = logging.getLogger('EPayment.PayBySC') import DateTime 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) sbrain = context.students_catalog(id=student_id)[0] amount,description = context.getSchoolFee(sbrain.faculty) 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' ) if psm == 'invalid': psm = 'Please correct your errors!' return context.pay_by_sc_form(rendered = res, psm = psm, mode = 'edit', ds = ds, ) elif psm == '': return context.pay_by_sc_form(rendered = res, psm = None, mode = 'edit', 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 if not hasattr(payments,p_id): now = DateTime.DateTime() info['date'] = now info['amount'] = "n/a" pin = info['order_id'] = ds.get('pin') info['type_code'] = "%s" % pin info['type_description'] = 'School Fee for Session 2006/2007' 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') wftool.doActionFor(student,'pay_school_fee') 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)