[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 2678 2007-11-16 13:41:44Z 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 |
---|
[2454] | 26 | wftool = context.portal_workflow |
---|
[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] |
---|
[2454] | 36 | |
---|
| 37 | # session = s_brain.session |
---|
| 38 | # next_session, next_session_str = context.getNextSessionId(session) |
---|
| 39 | |
---|
[2451] | 40 | next_info = context.getNextInfo(s_brain) |
---|
[2454] | 41 | next_session_id = next_info['next_session_id'] |
---|
[2451] | 42 | next_session_str = next_info['next_session_str'] |
---|
[2454] | 43 | next_level_id = next_info['next_level_id'] |
---|
| 44 | next_transition = next_info['next_transition'] |
---|
[2475] | 45 | next_verdict = next_info['next_verdict'] |
---|
[2678] | 46 | next_previous_verdict = next_info['next_previous_verdict'] |
---|
[2451] | 47 | |
---|
[2454] | 48 | validate = request.has_key("cpsdocument_create_button") |
---|
[1274] | 49 | res,psm,ds = lt.renderLayout(layout_id= 'student_schoolfee', |
---|
[1376] | 50 | schema_id= 'payment', |
---|
[1274] | 51 | context=context, |
---|
[1283] | 52 | mapping=validate and request, |
---|
[1274] | 53 | ob={}, |
---|
| 54 | layout_mode="create", |
---|
| 55 | formaction = "pay_by_sc", |
---|
[1856] | 56 | button = 'Pay', |
---|
| 57 | commit = False, |
---|
[1274] | 58 | ) |
---|
| 59 | if psm == 'invalid': |
---|
| 60 | psm = 'Please correct your errors!' |
---|
| 61 | return context.pay_by_sc_form(rendered = res, |
---|
| 62 | psm = psm, |
---|
| 63 | mode = 'edit', |
---|
[1758] | 64 | next_session_str = next_session_str, |
---|
[1274] | 65 | ds = ds, |
---|
| 66 | ) |
---|
| 67 | elif psm == '': |
---|
| 68 | return context.pay_by_sc_form(rendered = res, |
---|
| 69 | psm = None, |
---|
| 70 | mode = 'edit', |
---|
[1758] | 71 | next_session_str = next_session_str, |
---|
[1274] | 72 | ds = ds, |
---|
| 73 | ) |
---|
| 74 | elif psm == 'valid': |
---|
| 75 | pass |
---|
| 76 | if "payments" not in student.objectIds(): |
---|
| 77 | student.invokeFactory('PaymentsFolder','payments') |
---|
| 78 | payments = getattr(student,'payments') |
---|
| 79 | d = {} |
---|
| 80 | d['Title'] = 'Payments' |
---|
| 81 | payments.getContent().edit(mapping=d) |
---|
| 82 | wftool.doActionFor(payments,'open') |
---|
| 83 | else: |
---|
| 84 | payments = getattr(student,'payments') |
---|
[1283] | 85 | #from Products.zdb import set_trace; set_trace() |
---|
[1274] | 86 | info = {} |
---|
[2619] | 87 | p_id = "p%s" % ds.get('pin_n') |
---|
[2059] | 88 | pin = str(ds.get('pin')) |
---|
| 89 | try: |
---|
| 90 | cost = context.portal_pins(pin="".join(pin.split('-')))[0].cost |
---|
| 91 | except: |
---|
| 92 | cost = "n/a" |
---|
| 93 | try: |
---|
| 94 | x = float(cost) |
---|
| 95 | except: |
---|
| 96 | cost = "n/a" |
---|
[2153] | 97 | |
---|
[1390] | 98 | if not hasattr(payments,p_id): |
---|
| 99 | now = DateTime.DateTime() |
---|
| 100 | info['date'] = now |
---|
[2059] | 101 | info['amount'] = cost |
---|
[2619] | 102 | pin = info['order_id'] = "%s" % pin |
---|
| 103 | info['type_code'] = "%s" % pin #type_code is redundant and will be removed soon |
---|
[1758] | 104 | info['type_description'] = 'School Fee for Session %s' % next_session_str |
---|
[1390] | 105 | info['resp_code'] = "SC" |
---|
| 106 | info['resp_desc'] = "SC Payment Successful" |
---|
| 107 | payments.invokeFactory('Payment', p_id) |
---|
| 108 | payment = getattr(payments,p_id) |
---|
| 109 | wftool = context.portal_workflow |
---|
| 110 | wftool.doActionFor(payment,'open') |
---|
| 111 | payment.getContent().edit(mapping=info) |
---|
| 112 | wftool.doActionFor(payment,'close') |
---|
[2454] | 113 | |
---|
| 114 | study_course = getattr(student,'study_course') |
---|
[2459] | 115 | try: |
---|
| 116 | wftool.doActionFor(study_course,'open') |
---|
| 117 | except: |
---|
[2475] | 118 | pass |
---|
[2454] | 119 | study_course.getContent().edit(mapping= {'current_level': next_level_id, |
---|
[2475] | 120 | 'current_session': next_session_id, |
---|
| 121 | 'current_verdict': next_verdict, |
---|
[2678] | 122 | 'previous_verdict': next_previous_verdict, |
---|
[2475] | 123 | }) |
---|
[2454] | 124 | if next_transition: |
---|
[2459] | 125 | wftool.doActionFor(student,next_transition) |
---|
| 126 | |
---|
[1568] | 127 | logger.info('%s paid school fee by scratch card' % student_id) |
---|
[1390] | 128 | else: |
---|
[1568] | 129 | logger.info('%s repeatedly paid school fee by scratch card' % student_id) |
---|
[1283] | 130 | url = "%s/payments" % (student.absolute_url()) |
---|
[1274] | 131 | request.RESPONSE.redirect(url) |
---|
| 132 | |
---|