[3790] | 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 | 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 |
---|
| 40 | #students = context.portal_url.getPortalObject().campus.students |
---|
| 41 | student_id = context.getStudentId() |
---|
| 42 | if student_id is None: |
---|
| 43 | return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
| 44 | #student = getattr(students,student_id) |
---|
| 45 | student_record = context.students_catalog.getRecordByKey(student_id) |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | info = {} |
---|
| 49 | is_so = info['is_so'] = context.isSectionOfficer() |
---|
| 50 | is_student = info['is_student'] = context.isStudent() |
---|
| 51 | info['student_name'] = student_record.name |
---|
| 52 | info['query_url'] = "https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx" |
---|
| 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') |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | session = student_record.session |
---|
| 59 | next_info = context.getNextInfo(student_record) |
---|
| 60 | info['next_session'] = next_info['next_session_id'] |
---|
| 61 | info['next_session_str'] = next_info['next_session_str'] |
---|
| 62 | info['payment_method'] = "" |
---|
| 63 | info['reasons'] = next_info['reasons'] |
---|
| 64 | |
---|
| 65 | # begin customization |
---|
[3791] | 66 | info['payment_method'] = "" |
---|
[3790] | 67 | info['prod_id'] = '00' |
---|
| 68 | info['gown'] = False |
---|
| 69 | # end customization |
---|
| 70 | |
---|
| 71 | info['student_name'] = student_record.name |
---|
| 72 | payments_path = "%s/campus/students/%s/payments" % (context.portal_url(),student_id) |
---|
| 73 | payments = [] |
---|
| 74 | payment_records = aq_payments(Eq('student_id',student_id)) # & Eq('session_id',student_record.session)) |
---|
| 75 | vocabularies = context.portal_vocabularies |
---|
| 76 | paid_fees = [] |
---|
| 77 | for payment in payment_records: |
---|
| 78 | if payment.status == "paid": |
---|
| 79 | paid_fees += "%s_%s" % (payment.category,payment.session_id), |
---|
| 80 | #info['pf'] = paid_fees |
---|
| 81 | for payment in payment_records: |
---|
| 82 | row = {} |
---|
| 83 | row['id'] = payment.key |
---|
| 84 | if payment.status == 'invalid': |
---|
| 85 | row['title'] = "Invalid Payment, Naira %s, %s" % (payment.amount, |
---|
| 86 | payment.date.strftime("%d/%m/%y %H:%M:%S")) |
---|
| 87 | else: |
---|
| 88 | row['title'] = "%s for Session %s, Naira %s, %s" % (vocabularies.payment_categories.get(payment.category), |
---|
| 89 | vocabularies.sessions.get(payment.session_id), |
---|
| 90 | payment.amount, |
---|
| 91 | payment.date.strftime("%d/%m/%y %H:%M:%S")) |
---|
| 92 | oid = payment.order_id |
---|
| 93 | onr = oid.rfind('-')+1 |
---|
| 94 | if onr > 0: |
---|
| 95 | start_pos = onr |
---|
| 96 | else: |
---|
| 97 | start_pos = 6 |
---|
| 98 | url = row['url'] = "%s/p%s" % (payments_path,oid[start_pos:]) |
---|
| 99 | row['is_requeryable'] = "%s_%s" % (payment.category,payment.session_id) not in paid_fees and payment.type == 'online' or str(member) in ('admin',) |
---|
| 100 | row['is_approvable'] = is_so and row['is_requeryable'] and payment.category == 'schoolfee' # does not make sense for maitenance |
---|
| 101 | row['resp_desc'] = payment.resp_desc or 'Payment Process Interrupted' |
---|
| 102 | row['trans_ref'] = payment.order_id |
---|
| 103 | if row['is_requeryable']: |
---|
| 104 | row['callback_url'] = "%(url)s/interswitch_cb" % row |
---|
| 105 | # if payment.category == 'schoolfee': |
---|
| 106 | # row['callback_url'] = "%(url)s/interswitch_cb" % row |
---|
| 107 | # elif payment.category == 'hostel_maintenance': |
---|
| 108 | # row['callback_url'] = "%(url)s/interswitch_acco_cb" % row |
---|
| 109 | # else: |
---|
| 110 | href = '%(query_url)s' % info |
---|
| 111 | href += '?transRef=%(trans_ref)s' % row |
---|
| 112 | href += '&prodID=%(prod_id)s' % info |
---|
| 113 | href += '&redirectURL=%(callback_url)s' % row |
---|
| 114 | row['href'] = href |
---|
| 115 | if payment.status == 'paid': |
---|
| 116 | row['confirmed'] = 'active' |
---|
| 117 | else: |
---|
| 118 | row['confirmed'] = 'unsuccessful' |
---|
| 119 | row['is_editable'] = is_so and (row['confirmed'] == 'active') |
---|
| 120 | payments.append(row) |
---|
| 121 | |
---|
| 122 | payments.sort(cmp_id) |
---|
| 123 | info['payments'] = payments |
---|
| 124 | return info |
---|
| 125 | |
---|