## 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 1358 2007-01-26 08:16:41Z henrik $ """ pay online """ import logging from urllib import urlencode logger = logging.getLogger('EPayment.PayBySC') import DateTime 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) res = context.portal_catalog(portal_type="Certificate", id = sbrain.course) if not res: logger.info('"%s","certificate not found", "%s"' % (student_id,sbrain.course)) prefix = "" else: prefix = res[0].getObject().getContent().school_fee_code if not prefix or prefix == 'none': prefix = res[0].getPath().split('/')[-4] validate = request.has_key("cpsdocument_create_button") res,psm,ds = lt.renderLayout(layout_id= 'student_schoolfee', schema_id= 'epayment', 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 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 SC %s' % pin 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) url = "%s/payments" % (student.absolute_url()) request.RESPONSE.redirect(url)