[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 1370 2007-01-28 16:22:06Z joachim $ |
---|
| 11 | """ |
---|
| 12 | pay online |
---|
| 13 | """ |
---|
| 14 | import logging |
---|
| 15 | from urllib import urlencode |
---|
[1358] | 16 | logger = logging.getLogger('EPayment.PayBySC') |
---|
[1274] | 17 | import DateTime |
---|
[1365] | 18 | |
---|
| 19 | if context.portal_membership.isAnonymousUser(): |
---|
| 20 | return None |
---|
| 21 | |
---|
[1274] | 22 | lt = context.portal_layouts |
---|
| 23 | request = context.REQUEST |
---|
| 24 | students = context.portal_url.getPortalObject().campus.students |
---|
| 25 | student_id = context.getStudentId() |
---|
| 26 | if student_id is None: |
---|
[1283] | 27 | return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
[1274] | 28 | |
---|
| 29 | student = getattr(students,student_id) |
---|
| 30 | sbrain = context.students_catalog(id=student_id)[0] |
---|
| 31 | amount,description = context.getSchoolFee(sbrain.faculty) |
---|
[1283] | 32 | |
---|
| 33 | validate = request.has_key("cpsdocument_create_button") |
---|
[1274] | 34 | res,psm,ds = lt.renderLayout(layout_id= 'student_schoolfee', |
---|
| 35 | schema_id= 'epayment', |
---|
| 36 | context=context, |
---|
[1283] | 37 | mapping=validate and request, |
---|
[1274] | 38 | ob={}, |
---|
| 39 | layout_mode="create", |
---|
| 40 | formaction = "pay_by_sc", |
---|
| 41 | button = 'Pay' |
---|
| 42 | ) |
---|
| 43 | if psm == 'invalid': |
---|
| 44 | psm = 'Please correct your errors!' |
---|
| 45 | return context.pay_by_sc_form(rendered = res, |
---|
| 46 | psm = psm, |
---|
| 47 | mode = 'edit', |
---|
| 48 | ds = ds, |
---|
| 49 | ) |
---|
| 50 | elif psm == '': |
---|
| 51 | return context.pay_by_sc_form(rendered = res, |
---|
| 52 | psm = None, |
---|
| 53 | mode = 'edit', |
---|
| 54 | ds = ds, |
---|
| 55 | ) |
---|
| 56 | elif psm == 'valid': |
---|
| 57 | pass |
---|
| 58 | if "payments" not in student.objectIds(): |
---|
| 59 | student.invokeFactory('PaymentsFolder','payments') |
---|
| 60 | payments = getattr(student,'payments') |
---|
| 61 | d = {} |
---|
| 62 | d['Title'] = 'Payments' |
---|
| 63 | payments.getContent().edit(mapping=d) |
---|
| 64 | wftool.doActionFor(payments,'open') |
---|
| 65 | else: |
---|
| 66 | payments = getattr(student,'payments') |
---|
[1283] | 67 | #from Products.zdb import set_trace; set_trace() |
---|
[1274] | 68 | info = {} |
---|
[1283] | 69 | order_id = ds.get('pin_n') |
---|
[1274] | 70 | p_id = "p%s" % order_id |
---|
| 71 | now = DateTime.DateTime() |
---|
| 72 | info['date'] = now |
---|
[1286] | 73 | info['amount'] = "n/a" |
---|
[1283] | 74 | pin = info['order_id'] = ds.get('pin') |
---|
[1286] | 75 | info['type_code'] = "%s" % pin |
---|
| 76 | info['type_description'] = 'School Fee SC %s' % pin |
---|
[1370] | 77 | info['resp_code'] = "SC" |
---|
| 78 | info['resp_desc'] = "Scratchcard Payment" |
---|
[1274] | 79 | payments.invokeFactory('Payment', p_id) |
---|
| 80 | payment = getattr(payments,p_id) |
---|
[1283] | 81 | wftool = context.portal_workflow |
---|
| 82 | wftool.doActionFor(payment,'open') |
---|
[1274] | 83 | payment.getContent().edit(mapping=info) |
---|
[1283] | 84 | wftool.doActionFor(payment,'close') |
---|
[1286] | 85 | wftool.doActionFor(student,'pay_school_fee') |
---|
[1357] | 86 | logger.info('"%s", "paid school fee by scratch card"' % student_id) |
---|
[1283] | 87 | url = "%s/payments" % (student.absolute_url()) |
---|
[1274] | 88 | request.RESPONSE.redirect(url) |
---|
| 89 | |
---|