## Script (Python) "getPaymentsFolderInfo" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## # $Id: getPaymentsFolderInfo.py 8464 2012-05-16 14:25:15Z henrik $ """ Info for the PaymentsFolder """ from Products.AdvancedQuery import Eq, Between, Le,In mtool = context.portal_membership wftool = context.portal_workflow member = mtool.getAuthenticatedMember() payments_catalog = context.payments_catalog aq_payments = payments_catalog.evalAdvancedQuery if mtool.isAnonymousUser(): return None try: from Products.zdb import set_trace except: def set_trace(): pass import DateTime request = context.REQUEST #students = context.portal_url.getPortalObject().campus.students student_id = context.getStudentId() if student_id is None: return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) #student = getattr(students,student_id) student_record = context.students_catalog.getRecordByKey(student_id) info = {} is_so = info['is_so'] = context.isSectionOfficer() is_student = info['is_student'] = context.isStudent() info['student_name'] = student_record.name info['query_url'] = "https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx" info['query_url_tranzact'] = "https://www.etranzact.net/Query/queryPayoutletTransaction.jsp" review_state = info['review_state'] = student_record.review_state parttime = student_record.mode and student_record.mode.endswith('_pt') fulltime = student_record.mode and student_record.mode.endswith('_ft') session = student_record.session next_info = context.getNextInfo(student_record) info['next_session'] = next_info['next_session_id'] info['next_session_str'] = next_info['next_session_str'] info['payment_method'] = "" info['reasons'] = next_info['reasons'] # begin customization info['payment_method'] = "" if not next_info['payment_allowed']: pass elif review_state == 'cleared_and_validated' and session in ('11','12','13'): info['payment_method'] = "online_payment" elif review_state == 'returning' and session in ('11','12','13'): info['payment_method'] = "online_payment" elif review_state == 'returning' or review_state == 'cleared_and_validated': info['payment_method'] = "both_payments" else: info['payment_method'] = "" info['prod_id'] = '57' gown_records = aq_payments(Eq('student_id',student_id) & Eq('category','gown')) try: level = int(student_record.level) end_level = int(student_record.end_level) if level >= end_level and not gown_records: info['gown'] = True except: pass if review_state == 'admitted': info['acceptance'] = True else: info['acceptance'] = False # end customization info['student_name'] = student_record.name payments_path = "%s/campus/students/%s/payments" % (context.portal_url(),student_id) payments = [] payment_records = aq_payments(Eq('student_id',student_id)) # & Eq('session_id',student_record.session)) vocabularies = context.portal_vocabularies paid_fees = [] for payment in payment_records: if payment.status == "paid": paid_fees += "%s_%s" % (payment.category,payment.session_id), #info['pf'] = paid_fees for payment in payment_records: row = {} row['id'] = payment.key try: p_date = payment.date.strftime("%d/%m/%y %H:%M:%S") except: p_date = '(no payment date provided)' if payment.status == 'invalid': row['title'] = "Invalid Payment, Naira %s, %s" % (payment.amount, p_date) else: row['title'] = "%s for Session %s, Naira %s, %s" % (vocabularies.payment_categories.get(payment.category), vocabularies.sessions.get(payment.session_id), payment.amount, p_date) oid = payment.order_id onr = oid.rfind('-')+1 if onr > 0: start_pos = onr else: start_pos = 6 row['sort_param'] = payment.date url = row['url'] = "%s/p%s" % (payments_path,oid[start_pos:]) row['is_requeryable_interswitch'] = "%s_%s" % (payment.category,payment.session_id) not in paid_fees and payment.type == 'online' #or str(member) in ('admin',) row['is_requeryable_etranzact'] = "%s_%s" % (payment.category,payment.session_id) not in paid_fees and payment.type == 'etranzact' #or str(member) in ('admin',) row['is_approvable'] = is_so and (row['is_requeryable_interswitch'] or row['is_requeryable_etranzact']) row['resp_desc'] = payment.resp_desc or 'Payment Process Interrupted' row['trans_ref'] = payment.order_id if row['is_requeryable_interswitch']: row['callback_url_inter'] = "%(url)s/interswitch_cb" % row # if payment.category == 'schoolfee': # row['callback_url'] = "%(url)s/interswitch_cb" % row # elif payment.category == 'hostel_maintenance': # row['callback_url'] = "%(url)s/interswitch_acco_cb" % row # else: href = '%(query_url)s' % info href += '?transRef=%(trans_ref)s' % row href += '&prodID=%(prod_id)s' % info href += '&redirectURL=%(callback_url_inter)s' % row row['href_inter'] = href if row['is_requeryable_etranzact']: row['callback_url_tranzact'] = "%(url)s/etranzact_cb" % row # if payment.category == 'schoolfee': # row['callback_url'] = "%(url)s/interswitch_cb" % row # elif payment.category == 'hostel_maintenance': # row['callback_url'] = "%(url)s/interswitch_acco_cb" % row # else: href = 'enter_tranzact_pin' href += '?query_url=%(query_url_tranzact)s' % info href += '&redirectURL=%(callback_url_tranzact)s' % row row['href_tranzact'] = href if payment.status == 'paid': row['confirmed'] = 'active' else: row['confirmed'] = 'unsuccessful' row['is_editable'] = is_so and (row['confirmed'] == 'active') payments.append(row) payments.sort(cmp=lambda x,y: cmp(x['sort_param'],y['sort_param'])) info['payments'] = payments return info