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