[3690] | 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 | |
---|
| 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 | |
---|
[5193] | 58 | if review_state in ('returning',) and info['next_session'] != session: |
---|
[5171] | 59 | if session in ('06',): |
---|
[5164] | 60 | info['payment_method'] = "online_payment" |
---|
| 61 | else: |
---|
| 62 | info['payment_method'] = "first_instalment" |
---|
[5171] | 63 | elif review_state in ('cleared_and_validated',): |
---|
| 64 | if session in ('06','07',): |
---|
| 65 | info['payment_method'] = "online_payment" |
---|
| 66 | else: |
---|
| 67 | info['payment_method'] = "first_instalment" |
---|
[5175] | 68 | elif session in ('08','09',) and review_state in ('school_fee_paid','courses_registered','courses_validated',): |
---|
[5164] | 69 | second_instalment_records = aq_payments(Eq('student_id',student_id) & Eq('category','schoolfee2') & Eq('session_id',session) & Eq('status','paid')) |
---|
| 70 | if not second_instalment_records: |
---|
| 71 | info['payment_method'] = "second_instalment" |
---|
| 72 | else: |
---|
| 73 | pass |
---|
[3690] | 74 | info['prod_id'] = '105' |
---|
| 75 | |
---|
| 76 | # end customization |
---|
| 77 | |
---|
| 78 | info['student_name'] = student_record.name |
---|
| 79 | payments_path = "%s/campus/students/%s/payments" % (context.portal_url(),student_id) |
---|
| 80 | payments = [] |
---|
| 81 | payment_records = aq_payments(Eq('student_id',student_id)) # & Eq('session_id',student_record.session)) |
---|
| 82 | vocabularies = context.portal_vocabularies |
---|
| 83 | paid_fees = [] |
---|
| 84 | for payment in payment_records: |
---|
| 85 | if payment.status == "paid": |
---|
| 86 | paid_fees += "%s_%s" % (payment.category,payment.session_id), |
---|
| 87 | #info['pf'] = paid_fees |
---|
| 88 | for payment in payment_records: |
---|
| 89 | row = {} |
---|
| 90 | row['id'] = payment.key |
---|
| 91 | if payment.status == 'invalid': |
---|
| 92 | row['title'] = "Invalid Payment, Naira %s, %s" % (payment.amount, |
---|
| 93 | payment.date.strftime("%d/%m/%y %H:%M:%S")) |
---|
| 94 | else: |
---|
| 95 | row['title'] = "%s for Session %s, Naira %s, %s" % (vocabularies.payment_categories.get(payment.category), |
---|
| 96 | vocabularies.sessions.get(payment.session_id), |
---|
| 97 | payment.amount, |
---|
| 98 | payment.date.strftime("%d/%m/%y %H:%M:%S")) |
---|
| 99 | oid = payment.order_id |
---|
| 100 | onr = oid.rfind('-')+1 |
---|
| 101 | if onr > 0: |
---|
| 102 | start_pos = onr |
---|
| 103 | else: |
---|
| 104 | start_pos = 6 |
---|
| 105 | url = row['url'] = "%s/p%s" % (payments_path,oid[start_pos:]) |
---|
[3813] | 106 | row['is_requeryable'] = "%s_%s" % (payment.category,payment.session_id) not in paid_fees and not payment.resp_desc and payment.type == 'online' or str(member) in ('admin',) # customized too |
---|
[3690] | 107 | row['is_approvable'] = is_so and row['is_requeryable'] and payment.category == 'schoolfee' # does not make sense for maintenance |
---|
| 108 | row['resp_desc'] = payment.resp_desc or 'Payment Process Interrupted' |
---|
| 109 | row['trans_ref'] = payment.order_id |
---|
| 110 | if row['is_requeryable']: |
---|
[5164] | 111 | if payment.category == 'schoolfee': |
---|
| 112 | row['callback_url'] = "%(url)s/interswitch_cb" % row |
---|
| 113 | elif payment.category == 'schoolfee2': |
---|
| 114 | row['callback_url'] = "%(url)s/interswitch_cb2" % row |
---|
[3690] | 115 | # elif payment.category == 'hostel_maintenance': |
---|
| 116 | # row['callback_url'] = "%(url)s/interswitch_acco_cb" % row |
---|
| 117 | # else: |
---|
| 118 | href = '%(query_url)s' % info |
---|
| 119 | href += '?transRef=%(trans_ref)s' % row |
---|
| 120 | href += '&prodID=%(prod_id)s' % info |
---|
| 121 | href += '&redirectURL=%(callback_url)s' % row |
---|
| 122 | row['href'] = href |
---|
| 123 | if payment.status == 'paid': |
---|
| 124 | row['confirmed'] = 'active' |
---|
| 125 | else: |
---|
| 126 | row['confirmed'] = 'unsuccessful' |
---|
| 127 | row['is_editable'] = is_so and (row['confirmed'] == 'active') |
---|
| 128 | payments.append(row) |
---|
| 129 | |
---|
[3865] | 130 | payments.sort(cmp=lambda x,y: cmp(x['trans_ref'],y['trans_ref'])) |
---|
[3690] | 131 | info['payments'] = payments |
---|
| 132 | return info |
---|
| 133 | |
---|