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