[3709] | 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 2761 2007-11-26 09:45:58Z henrik $ |
---|
| 11 | """ |
---|
| 12 | Info for the PaymentsFolder |
---|
| 13 | """ |
---|
| 14 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
| 15 | |
---|
| 16 | mtool = context.portal_membership |
---|
| 17 | wftool = context.portal_workflow |
---|
| 18 | member = mtool.getAuthenticatedMember() |
---|
| 19 | payments_catalog = context.payments_catalog |
---|
| 20 | aq_payments = payments_catalog.evalAdvancedQuery |
---|
| 21 | if mtool.isAnonymousUser(): |
---|
| 22 | return None |
---|
| 23 | try: |
---|
| 24 | from Products.zdb import set_trace |
---|
| 25 | except: |
---|
| 26 | def set_trace(): |
---|
| 27 | pass |
---|
| 28 | |
---|
| 29 | import DateTime |
---|
| 30 | request = context.REQUEST |
---|
| 31 | #students = context.portal_url.getPortalObject().campus.students |
---|
| 32 | student_id = context.getStudentId() |
---|
| 33 | if student_id is None: |
---|
| 34 | return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
| 35 | #student = getattr(students,student_id) |
---|
| 36 | student_record = context.students_catalog.getRecordByKey(student_id) |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | info = {} |
---|
| 40 | is_so = info['is_so'] = context.isSectionOfficer() |
---|
| 41 | is_student = info['is_student'] = context.isStudent() |
---|
| 42 | info['student_name'] = student_record.name |
---|
| 43 | info['query_url'] = "https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx" |
---|
| 44 | review_state = info['review_state'] = student_record.review_state |
---|
| 45 | parttime = student_record.mode and student_record.mode.endswith('_pt') |
---|
| 46 | fulltime = student_record.mode and student_record.mode.endswith('_ft') |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | session = student_record.session |
---|
| 50 | next_info = context.getNextInfo(student_record) |
---|
| 51 | info['next_session'] = next_info['next_session_id'] |
---|
| 52 | info['next_session_str'] = next_info['next_session_str'] |
---|
| 53 | info['payment_method'] = "" |
---|
| 54 | info['reasons'] = next_info['reasons'] |
---|
| 55 | |
---|
| 56 | # begin customization |
---|
| 57 | |
---|
[5044] | 58 | # special handling of 06 DPA students (ticket 658) |
---|
| 59 | if review_state == 'cleared_and_validated' and session in ('06') and student_record.course == 'DPA': |
---|
| 60 | info['payment_method'] = "sc_payment" |
---|
| 61 | # special handling of 06 payments for testing purposes |
---|
| 62 | elif review_state == 'cleared_and_validated' and session in ('06'): |
---|
[4818] | 63 | info['payment_method'] = "online_payment" |
---|
| 64 | elif review_state == 'returning' and info['next_session'] == '06': |
---|
[4294] | 65 | info['payment_method'] = "both_payments" |
---|
[4818] | 66 | elif review_state == 'cleared_and_validated' and session not in ('07','08'): |
---|
| 67 | info['payment_method'] = "both_payments" |
---|
[4198] | 68 | elif review_state == 'cleared_and_validated' and session in ('07','08'): |
---|
| 69 | info['payment_method'] = "sc_payment" |
---|
| 70 | elif review_state == 'returning' and info['next_session'] != session: |
---|
| 71 | info['payment_method'] = "sc_payment" |
---|
[4193] | 72 | |
---|
| 73 | |
---|
[4198] | 74 | |
---|
[3709] | 75 | info['prod_id'] = '61' |
---|
| 76 | |
---|
[3863] | 77 | gown_records = aq_payments(Eq('student_id',student_id) & Eq('category','gown')) |
---|
[3736] | 78 | try: |
---|
| 79 | level = int(student_record.level) |
---|
| 80 | end_level = int(student_record.end_level) |
---|
[3863] | 81 | if level >= end_level and not gown_records: |
---|
[3736] | 82 | info['gown'] = True |
---|
| 83 | except: |
---|
| 84 | pass |
---|
| 85 | |
---|
[3709] | 86 | # end customization |
---|
| 87 | |
---|
| 88 | info['student_name'] = student_record.name |
---|
| 89 | payments_path = "%s/campus/students/%s/payments" % (context.portal_url(),student_id) |
---|
| 90 | payments = [] |
---|
| 91 | payment_records = aq_payments(Eq('student_id',student_id)) # & Eq('session_id',student_record.session)) |
---|
| 92 | vocabularies = context.portal_vocabularies |
---|
| 93 | paid_fees = [] |
---|
| 94 | for payment in payment_records: |
---|
| 95 | if payment.status == "paid": |
---|
| 96 | paid_fees += "%s_%s" % (payment.category,payment.session_id), |
---|
| 97 | #info['pf'] = paid_fees |
---|
| 98 | for payment in payment_records: |
---|
| 99 | row = {} |
---|
| 100 | row['id'] = payment.key |
---|
| 101 | if payment.status == 'invalid': |
---|
| 102 | row['title'] = "Invalid Payment, Naira %s, %s" % (payment.amount, |
---|
| 103 | payment.date.strftime("%d/%m/%y %H:%M:%S")) |
---|
| 104 | else: |
---|
| 105 | row['title'] = "%s for Session %s, Naira %s, %s" % (vocabularies.payment_categories.get(payment.category), |
---|
| 106 | vocabularies.sessions.get(payment.session_id), |
---|
| 107 | payment.amount, |
---|
| 108 | payment.date.strftime("%d/%m/%y %H:%M:%S")) |
---|
| 109 | oid = payment.order_id |
---|
| 110 | onr = oid.rfind('-')+1 |
---|
| 111 | if onr > 0: |
---|
| 112 | start_pos = onr |
---|
| 113 | else: |
---|
| 114 | start_pos = 6 |
---|
[5222] | 115 | row['sort_param'] = payment.date |
---|
[3709] | 116 | url = row['url'] = "%s/p%s" % (payments_path,oid[start_pos:]) |
---|
| 117 | row['is_requeryable'] = "%s_%s" % (payment.category,payment.session_id) not in paid_fees and payment.type == 'online' or str(member) in ('admin',) |
---|
| 118 | row['is_approvable'] = is_so and row['is_requeryable'] and payment.category == 'schoolfee' # does not make sense for maitenance |
---|
| 119 | row['resp_desc'] = payment.resp_desc or 'Payment Process Interrupted' |
---|
| 120 | row['trans_ref'] = payment.order_id |
---|
| 121 | if row['is_requeryable']: |
---|
| 122 | row['callback_url'] = "%(url)s/interswitch_cb" % row |
---|
| 123 | # if payment.category == 'schoolfee': |
---|
| 124 | # row['callback_url'] = "%(url)s/interswitch_cb" % row |
---|
| 125 | # elif payment.category == 'hostel_maintenance': |
---|
| 126 | # row['callback_url'] = "%(url)s/interswitch_acco_cb" % row |
---|
| 127 | # else: |
---|
| 128 | href = '%(query_url)s' % info |
---|
| 129 | href += '?transRef=%(trans_ref)s' % row |
---|
| 130 | href += '&prodID=%(prod_id)s' % info |
---|
| 131 | href += '&redirectURL=%(callback_url)s' % row |
---|
| 132 | row['href'] = href |
---|
| 133 | if payment.status == 'paid': |
---|
| 134 | row['confirmed'] = 'active' |
---|
| 135 | else: |
---|
| 136 | row['confirmed'] = 'unsuccessful' |
---|
| 137 | row['is_editable'] = is_so and (row['confirmed'] == 'active') |
---|
| 138 | payments.append(row) |
---|
| 139 | |
---|
[5222] | 140 | payments.sort(cmp=lambda x,y: cmp(x['sort_param'],y['sort_param'])) |
---|
[3709] | 141 | info['payments'] = payments |
---|
| 142 | return info |
---|