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