[1274] | 1 | ## Script (Python) "pay_by_sc" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
| 7 | ##parameters= |
---|
| 8 | ##title= |
---|
| 9 | ## |
---|
| 10 | # $Id: pay_by_sc.py 2130 2007-08-20 15:26:50Z henrik $ |
---|
| 11 | """ |
---|
| 12 | pay online |
---|
| 13 | """ |
---|
| 14 | import logging |
---|
| 15 | from urllib import urlencode |
---|
[1568] | 16 | logger = logging.getLogger('Skins.pay_by_sc') |
---|
[1274] | 17 | import DateTime |
---|
[1758] | 18 | try: |
---|
| 19 | from Products.zdb import set_trace |
---|
| 20 | except: |
---|
| 21 | def set_trace(): |
---|
| 22 | pass |
---|
[1365] | 23 | |
---|
| 24 | if context.portal_membership.isAnonymousUser(): |
---|
| 25 | return None |
---|
| 26 | |
---|
[1274] | 27 | lt = context.portal_layouts |
---|
| 28 | request = context.REQUEST |
---|
| 29 | students = context.portal_url.getPortalObject().campus.students |
---|
| 30 | student_id = context.getStudentId() |
---|
| 31 | if student_id is None: |
---|
[1283] | 32 | return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
[1274] | 33 | |
---|
| 34 | student = getattr(students,student_id) |
---|
[1758] | 35 | s_brain = context.students_catalog(id=student_id)[0] |
---|
| 36 | session = s_brain.session |
---|
| 37 | next_session, next_session_str = context.getNextSessionId(session) |
---|
[2005] | 38 | amount,description = context.getSchoolFee(s_brain.faculty,session) |
---|
[1283] | 39 | validate = request.has_key("cpsdocument_create_button") |
---|
[1274] | 40 | res,psm,ds = lt.renderLayout(layout_id= 'student_schoolfee', |
---|
[1376] | 41 | schema_id= 'payment', |
---|
[1274] | 42 | context=context, |
---|
[1283] | 43 | mapping=validate and request, |
---|
[1274] | 44 | ob={}, |
---|
| 45 | layout_mode="create", |
---|
| 46 | formaction = "pay_by_sc", |
---|
[1856] | 47 | button = 'Pay', |
---|
| 48 | commit = False, |
---|
[1274] | 49 | ) |
---|
| 50 | if psm == 'invalid': |
---|
| 51 | psm = 'Please correct your errors!' |
---|
| 52 | return context.pay_by_sc_form(rendered = res, |
---|
| 53 | psm = psm, |
---|
| 54 | mode = 'edit', |
---|
[1758] | 55 | next_session_str = next_session_str, |
---|
[1274] | 56 | ds = ds, |
---|
| 57 | ) |
---|
| 58 | elif psm == '': |
---|
| 59 | return context.pay_by_sc_form(rendered = res, |
---|
| 60 | psm = None, |
---|
| 61 | mode = 'edit', |
---|
[1758] | 62 | next_session_str = next_session_str, |
---|
[1274] | 63 | ds = ds, |
---|
| 64 | ) |
---|
| 65 | elif psm == 'valid': |
---|
| 66 | pass |
---|
| 67 | if "payments" not in student.objectIds(): |
---|
| 68 | student.invokeFactory('PaymentsFolder','payments') |
---|
| 69 | payments = getattr(student,'payments') |
---|
| 70 | d = {} |
---|
| 71 | d['Title'] = 'Payments' |
---|
| 72 | payments.getContent().edit(mapping=d) |
---|
| 73 | wftool.doActionFor(payments,'open') |
---|
| 74 | else: |
---|
| 75 | payments = getattr(student,'payments') |
---|
[1283] | 76 | #from Products.zdb import set_trace; set_trace() |
---|
[1274] | 77 | info = {} |
---|
[1283] | 78 | order_id = ds.get('pin_n') |
---|
[1274] | 79 | p_id = "p%s" % order_id |
---|
[2059] | 80 | pin = str(ds.get('pin')) |
---|
| 81 | try: |
---|
| 82 | cost = context.portal_pins(pin="".join(pin.split('-')))[0].cost |
---|
| 83 | except: |
---|
| 84 | cost = "n/a" |
---|
| 85 | try: |
---|
| 86 | x = float(cost) |
---|
| 87 | except: |
---|
| 88 | cost = "n/a" |
---|
[2130] | 89 | |
---|
[1390] | 90 | if not hasattr(payments,p_id): |
---|
| 91 | now = DateTime.DateTime() |
---|
| 92 | info['date'] = now |
---|
[2059] | 93 | info['amount'] = cost |
---|
| 94 | pin = info['order_id'] = "%s" % (pin) |
---|
[1390] | 95 | info['type_code'] = "%s" % pin |
---|
[1758] | 96 | info['type_description'] = 'School Fee for Session %s' % next_session_str |
---|
[1390] | 97 | info['resp_code'] = "SC" |
---|
| 98 | info['resp_desc'] = "SC Payment Successful" |
---|
| 99 | payments.invokeFactory('Payment', p_id) |
---|
| 100 | payment = getattr(payments,p_id) |
---|
| 101 | wftool = context.portal_workflow |
---|
| 102 | wftool.doActionFor(payment,'open') |
---|
| 103 | payment.getContent().edit(mapping=info) |
---|
| 104 | wftool.doActionFor(payment,'close') |
---|
[1771] | 105 | if next_session == context.getSessionId()[-2:]: |
---|
[1758] | 106 | wftool.doActionFor(student,'pay_school_fee') |
---|
[2130] | 107 | if int(session) < 6: |
---|
[1758] | 108 | study_course = getattr(student,'study_course') |
---|
[1764] | 109 | #wftool.doActionFor(study_course,'open') |
---|
[1758] | 110 | study_course_doc = study_course.getContent() |
---|
[2130] | 111 | if s_brain.verdict in ('A','B') or int(session) < 5: |
---|
| 112 | next_level = "%s" % (int(s_brain.level) + 100) |
---|
| 113 | else: |
---|
| 114 | next_level = s_brain.level |
---|
[1758] | 115 | study_course_doc.edit(mapping= {'current_level': next_level, |
---|
| 116 | 'current_session': next_session,}) |
---|
[1568] | 117 | logger.info('%s paid school fee by scratch card' % student_id) |
---|
[1390] | 118 | else: |
---|
[1568] | 119 | logger.info('%s repeatedly paid school fee by scratch card' % student_id) |
---|
[1283] | 120 | url = "%s/payments" % (student.absolute_url()) |
---|
[1274] | 121 | request.RESPONSE.redirect(url) |
---|
| 122 | |
---|