[3736] | 1 | ## Script (Python) "request_gown" |
---|
| 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: request_gown.py 3256 2008-02-29 06:51:46Z henrik $ |
---|
| 11 | """ |
---|
| 12 | pay online |
---|
| 13 | """ |
---|
| 14 | import logging |
---|
| 15 | from urllib import urlencode |
---|
| 16 | logger = logging.getLogger('Skins.request_gown') |
---|
| 17 | import DateTime |
---|
| 18 | try: |
---|
| 19 | from Products.zdb import set_trace |
---|
| 20 | except: |
---|
| 21 | def set_trace(): |
---|
| 22 | pass |
---|
| 23 | |
---|
| 24 | if context.portal_membership.isAnonymousUser(): |
---|
| 25 | return None |
---|
| 26 | wftool = context.portal_workflow |
---|
| 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: |
---|
| 32 | return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
| 33 | |
---|
| 34 | student = getattr(students,student_id) |
---|
| 35 | student_record = context.students_catalog.getRecordByKey(student_id) |
---|
| 36 | session = context.getSessionId() |
---|
| 37 | |
---|
| 38 | validate = request.has_key("cpsdocument_create_button") |
---|
| 39 | res,psm,ds = lt.renderLayout(layout_id= 'student_gown', |
---|
| 40 | schema_id= 'payment', |
---|
| 41 | context=context, |
---|
| 42 | mapping=validate and request, |
---|
| 43 | ob={}, |
---|
| 44 | layout_mode="create", |
---|
| 45 | formaction = "request_gown", |
---|
| 46 | button = 'Pay', |
---|
| 47 | commit = False, |
---|
| 48 | ) |
---|
| 49 | if psm == 'invalid': |
---|
| 50 | psm = 'Please correct your errors!' |
---|
| 51 | return context.request_gown_form(rendered = res, |
---|
| 52 | psm = psm, |
---|
| 53 | mode = 'edit', |
---|
| 54 | #session_str = session[1], |
---|
| 55 | ds = ds, |
---|
| 56 | ) |
---|
| 57 | elif psm == '': |
---|
| 58 | return context.request_gown_form(rendered = res, |
---|
| 59 | psm = None, |
---|
| 60 | mode = 'edit', |
---|
| 61 | #session_str = session[1], |
---|
| 62 | ds = ds, |
---|
| 63 | ) |
---|
| 64 | elif psm == 'valid': |
---|
| 65 | pass |
---|
| 66 | if "payments" not in student.objectIds(): |
---|
| 67 | student.invokeFactory('PaymentsFolder','payments') |
---|
| 68 | payments = getattr(student,'payments') |
---|
| 69 | d = {} |
---|
| 70 | d['Title'] = 'Payments' |
---|
| 71 | payments.getContent().edit(mapping=d) |
---|
| 72 | wftool.doActionFor(payments,'open') |
---|
| 73 | else: |
---|
| 74 | payments = getattr(student,'payments') |
---|
| 75 | #from Products.zdb import set_trace; set_trace() |
---|
| 76 | info = {} |
---|
| 77 | p_id = "p%s" % ds.get('pin_n') |
---|
| 78 | pin = str(ds.get('pin')) |
---|
| 79 | try: |
---|
| 80 | cost = context.portal_pins(pin="".join(pin.split('-')))[0].cost |
---|
| 81 | except: |
---|
| 82 | cost = "n/a" |
---|
| 83 | try: |
---|
| 84 | x = float(cost) |
---|
| 85 | except: |
---|
| 86 | cost = "n/a" |
---|
| 87 | |
---|
| 88 | if not hasattr(payments,p_id): |
---|
| 89 | now = DateTime.DateTime() |
---|
| 90 | info['date'] = now |
---|
| 91 | info['amount'] = cost |
---|
| 92 | pin = info['order_id'] = "%s" % pin |
---|
| 93 | #info['type_code'] = "%s" % pin #type_code is redundant and will be removed soon |
---|
| 94 | info['type_description'] = 'Gown Hire' |
---|
| 95 | info['type'] = 'sc' |
---|
| 96 | info['status'] = 'paid' |
---|
| 97 | info['session_id'] = session[0] |
---|
| 98 | info['item'] = '' |
---|
| 99 | info['category'] = 'gown' |
---|
| 100 | info['resp_code'] = "SC" |
---|
| 101 | info['resp_desc'] = "SC Payment Successful" |
---|
| 102 | payments.invokeFactory('Payment', p_id) |
---|
| 103 | payment = getattr(payments,p_id) |
---|
| 104 | wftool = context.portal_workflow |
---|
| 105 | wftool.doActionFor(payment,'open') |
---|
| 106 | payment.getContent().edit(mapping=info) |
---|
| 107 | wftool.doActionFor(payment,'close') |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | logger.info('%s paid gown by scratch card' % student_id) |
---|
| 111 | else: |
---|
| 112 | logger.info('%s repeatedly paid gown by scratch card' % student_id) |
---|
| 113 | url = "%s/payments" % (student.absolute_url()) |
---|
| 114 | request.RESPONSE.redirect(url) |
---|
| 115 | |
---|