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