[2644] | 1 | ## Script (Python) "getPaymentsFolderInfo" |
---|
| 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: getPaymentsFolderInfo.py 2480 2007-10-30 15:23:25Z joachim $ |
---|
| 11 | """ |
---|
| 12 | Info for the PaymentsFolder |
---|
| 13 | """ |
---|
| 14 | |
---|
| 15 | mtool = context.portal_membership |
---|
[2890] | 16 | member = mtool.getAuthenticatedMember() |
---|
[2644] | 17 | if mtool.isAnonymousUser(): |
---|
| 18 | return None |
---|
| 19 | try: |
---|
| 20 | from Products.zdb import set_trace |
---|
| 21 | except: |
---|
| 22 | def set_trace(): |
---|
| 23 | pass |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | #import logging |
---|
| 27 | #logger = logging.getLogger('Skins.getPaymentsFolderInfo') |
---|
| 28 | def cmp_id(a,b): |
---|
| 29 | s1 = "%(id)s" % a |
---|
| 30 | s2 = "%(id)s" % b |
---|
| 31 | if s1 == s2: |
---|
| 32 | return 0 |
---|
| 33 | if s1 > s2: |
---|
| 34 | return 1 |
---|
| 35 | return -1 |
---|
| 36 | |
---|
| 37 | import DateTime |
---|
| 38 | request = context.REQUEST |
---|
[2910] | 39 | students = context.portal_url.getPortalObject().campus.students |
---|
[2644] | 40 | student_id = context.getStudentId() |
---|
| 41 | if student_id is None: |
---|
| 42 | return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
[2908] | 43 | student = getattr(students,student_id) |
---|
[2871] | 44 | student_record = context.students_catalog.getRecordByKey(student_id) |
---|
[2943] | 45 | #context['updatePayments']() |
---|
[2644] | 46 | payments = [] |
---|
| 47 | |
---|
| 48 | info = {} |
---|
| 49 | is_so = info['is_so'] = context.isSectionOfficer() |
---|
| 50 | is_student = info['is_student'] = context.isStudent() |
---|
[2871] | 51 | info['student_name'] = student_record.name |
---|
[2644] | 52 | info['query_url'] = "https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx" |
---|
[2871] | 53 | review_state = info['review_state'] = student_record.review_state |
---|
| 54 | parttime = student_record.mode and student_record.mode.endswith('_pt') |
---|
| 55 | fulltime = student_record.mode and student_record.mode.endswith('_ft') |
---|
[2644] | 56 | |
---|
| 57 | #if review_state == 'cleared_and_validated' or (parttime and review_state == 'returning'): |
---|
| 58 | # online_payment = True |
---|
| 59 | #elif fulltime and review_state == 'returning': |
---|
| 60 | # sc_payment = True |
---|
| 61 | |
---|
[2871] | 62 | session = student_record.session |
---|
| 63 | next_info = context.getNextInfo(student_record) |
---|
[2644] | 64 | info['next_session'] = next_info['next_session_id'] |
---|
| 65 | info['next_session_str'] = next_info['next_session_str'] |
---|
| 66 | info['payment_method'] = "" |
---|
| 67 | info['reasons'] = next_info['reasons'] |
---|
| 68 | |
---|
[2657] | 69 | if review_state == 'cleared_and_validated': |
---|
[2644] | 70 | info['payment_method'] = "online_payment" |
---|
[2657] | 71 | elif review_state == 'returning' and info['next_session'] != session: |
---|
| 72 | info['payment_method'] = "online_payment" |
---|
[2834] | 73 | info['prod_id'] = '83' |
---|
[2644] | 74 | |
---|
[2871] | 75 | info['student_name'] = student_record.name |
---|
[2644] | 76 | payments_path = "%s/campus/students/%s/payments" % (context.portal_url.getPortalPath(),student_id) |
---|
| 77 | sos = context.portal_catalog(container_path=payments_path) |
---|
| 78 | info['is_so'] = is_so |
---|
| 79 | |
---|
| 80 | for so in sos: |
---|
| 81 | row = {} |
---|
| 82 | row['id'] = so.getId |
---|
| 83 | row['title'] = so.Title |
---|
| 84 | url = row['url'] = "%s/%s" % (payments_path,so.getId) |
---|
| 85 | so_doc = context.restrictedTraverse(url,default=None).getContent() |
---|
| 86 | row['type'] = so.portal_type |
---|
| 87 | review_state = row['review_state'] = so.review_state |
---|
| 88 | if so_doc.type_description.startswith('School Fee'): |
---|
| 89 | row['is_approvable'] = is_so and (review_state == "opened") and info['review_state'] in ('cleared_and_validated','returning') |
---|
| 90 | else: |
---|
[2943] | 91 | row['is_approvable'] = False # is_so and (review_state == "opened") |
---|
[2644] | 92 | row['is_requeryable'] = False |
---|
| 93 | #set_trace() |
---|
| 94 | row['resp_desc'] = getattr(so_doc,'resp_desc','no response') |
---|
| 95 | row['trans_ref'] = getattr(so_doc,'order_id','') |
---|
| 96 | if so_doc.type_description.startswith('School Fee'): |
---|
[2890] | 97 | if (review_state == 'opened' and info['review_state'] in ('cleared_and_validated','returning') and \ |
---|
[2900] | 98 | hasattr(so_doc, 'order_id') and not so_doc.resp_code) or str(member) in ('admin','delejason','isouaba'): |
---|
[2644] | 99 | row['is_requeryable'] = True |
---|
[2908] | 100 | row['callback_url'] = "%s/payments/%s/interswitch_cb" % (student.absolute_url(), |
---|
| 101 | so.getId) |
---|
[2644] | 102 | href = '%(query_url)s' % info |
---|
| 103 | href += '?transRef=%(trans_ref)s' % row |
---|
| 104 | href += '&prodID=%(prod_id)s' % info |
---|
| 105 | href += '&redirectURL=%(callback_url)s' % row |
---|
| 106 | row['href'] = href |
---|
[2943] | 107 | elif so_doc.type_description.startswith('Hostel'): |
---|
| 108 | if (review_state == 'opened' and \ |
---|
[3026] | 109 | hasattr(so_doc, 'order_id') and not so_doc.resp_code) or str(member) in ('admin','delejason','isouaba'): |
---|
[2943] | 110 | row['is_requeryable'] = True |
---|
[2964] | 111 | row['callback_url'] = "%s/payments/%s/interswitch_acco_cb" % (student.absolute_url(), |
---|
[2943] | 112 | so.getId) |
---|
| 113 | href = '%(query_url)s' % info |
---|
| 114 | href += '?transRef=%(trans_ref)s' % row |
---|
| 115 | href += '&prodID=%(prod_id)s' % info |
---|
| 116 | href += '&redirectURL=%(callback_url)s' % row |
---|
[2964] | 117 | row['href'] = href |
---|
[2644] | 118 | if (review_state == "closed") and so_doc.resp_code in ('SC','00','AP','IP',): |
---|
| 119 | row['confirmed'] = 'active' |
---|
| 120 | else: |
---|
| 121 | row['confirmed'] = 'unsuccessful' |
---|
[2758] | 122 | row['is_editable'] = is_so and (row['confirmed'] == 'active') |
---|
[2644] | 123 | payments.append(row) |
---|
| 124 | |
---|
| 125 | payments.sort(cmp_id) |
---|
| 126 | info['payments'] = payments |
---|
| 127 | return info |
---|
| 128 | |
---|