##Script (Python) "pay_online"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
# $Id: pay_interswitch.py 8918 2012-07-05 05:44:02Z henrik $
"""
pay online
"""
from urllib import urlencode
import logging
logger = logging.getLogger('Skins.pay_interswitch')
import DateTime
if context.portal_membership.isAnonymousUser():
return None
try:
from Products.zdb import set_trace
except:
def set_trace():
pass
request = context.REQUEST
wftool = context.portal_workflow
students = context.portal_url.getPortalObject().campus.students
student_id = context.getStudentId()
student = getattr(students,student_id)
student_record = context.students_catalog.getRecordByKey(student_id)
#amount,description = context.getSchoolFee(student_record.faculty,student_record.session,student_record.course)
info = {}
info['student'] = student_record
info['payment_possible'] = False
info['amount'] = '0'
info['bank'] = ''
info['type_description'] = ''
info['pay_bill_to'] = ''
fee_dict = context.getSchoolFee(student_record)
fulltime = student_record.mode.endswith('_ft')
new = student_record.review_state == 'cleared_and_validated'
returning = student_record.review_state == 'returning'
if not fee_dict or not (new or returning):
return context.interswitch_form(info=info)
info['site_id'] = '57'
info['currency_id'] = '566'
if new:
amount = info['amount'] = fee_dict['new']
elif returning:
amount = info['amount'] = fee_dict['returning']
late_registration = False
if new and int(student_record.session) < 11 and student_record.mode.startswith('ug'):
late_registration = True
if returning and int(student_record.session) < 10 and student_record.mode.startswith('ug'):
late_registration = True
if new and int(student_record.session) < 10 and student_record.mode.startswith('pg'):
late_registration = True
if returning and int(student_record.session) < 9 and student_record.mode.startswith('pg'):
late_registration = True
if late_registration:
amount_int = int(amount)
amount_int += 5000
amount = info['amount'] = '%d' % (amount_int)
final_year = False
if fee_dict['next_level_id'] == getattr(student_record, 'end_level', None) and not student_record.mode.startswith('pg'):
final_year = True
if final_year:
amount_int = int(amount)
amount_int += 3000
amount = info['amount'] = '%d' % (amount_int)
if fulltime:
pay_item_id = "5700"
info['bank'] = ''
else:
pay_item_id = "5701"
info['bank'] = ''
info['surcharge'] = '0' # Uniben doesn't show the surcharge on the slip
info['payment_possible'] = True
info['type_description'] = fee_dict['description']
info['pay_bill_to'] = student_record.name
info['pay_ship_to'] = "University of Benin"
info['student_id'] = student_id
info['student_name'] = student_record.name
info['student_email'] = student_record.email
#info['session_id'] = student_record.session # this holds only for new students und must be replaced when also previous session students will pay online !!!!!!
info['session_id'] = fee_dict['next_session_id']
info['type'] = 'online'
info['status'] = 'started'
info['item'] = student_record.course
info['category'] = 'schoolfee'
now = DateTime.DateTime()
info['date'] = now
timestamp = "%d" % int(now.timeTime()*1000)
info['order_id'] = "%s%s" % (student_id[1:],timestamp)
p_id = "p%s" % timestamp
if student_id is None:
return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
# old: https://webpay.interswitchng.com/paydirect/webpay/pay.aspx
if True or context.portal_url().find('uniben-demo.waeup.org') >-1 or\
context.portal_url().find('uniben.waeup.org') >-1:
#info['action'] = "https://webpay.interswitchng.com/test_paydirect/webpay/pay.aspx"
info['action'] = "https://webpay.interswitchng.com/webpayv4/webpay/pay.aspx"
else:
info['action'] = "%s/payments/%s/simulate_callback" % (student.absolute_url(),p_id)
if "payments" not in student.objectIds():
student.invokeFactory('PaymentsFolder','payments')
payments = getattr(student,'payments')
d = {}
d['Title'] = 'Payments'
payments.getContent().edit(mapping=d)
wftool.doActionFor(payments,'open')
else:
payments = getattr(student,'payments')
if request.has_key('epayment'):
return context.interswitch_form(info=info)
payments.invokeFactory('Payment', p_id)
payment = getattr(payments,p_id)
wftool.doActionFor(payment,'open')
d = {}
d.update(info)
payment.getContent().edit(mapping=d)
info['callback_url'] = "%s/payments/%s/interswitch_cb?echo=%s" % (student.absolute_url(),
p_id,
p_id)
logger.info('%(student_id)s initiated online school fee payment with order_id %(order_id)s and callback url %(callback_url)s' % info)
payment_fields = (('product_id','site_id'),
('site_redirect_url','callback_url'),
('Currency','currency_id'),
('cust_id','student_id'),
('cust_id_desc','type_description'),
('cust_name','student_name'),
('txn_ref','order_id'),
('Amount','amount'),
)
args = {}
for arg,field in payment_fields:
args[arg] = info[field]
itotal = int(amount)*100
#BT Amount Varies
if student_record.mode.endswith('_ft') and student_record.review_state == 'returning':
bt_amount = 60000
else:
bt_amount = 150000
#Interswitch amount 150 naira
interswitch_amount = 15000
uniben_amount = itotal - bt_amount - interswitch_amount
xmldict = {}
xmldict['detail_ref'] = args['txn_ref']
xmldict['department'] = student_record.department
xmldict['faculty'] = student_record.faculty
xmldict['bt_amt'] = "%d" % bt_amount
xmldict['uniben_amt'] = "%d" % uniben_amount
#Full and Part-time students School Fees go into different Accounts
# Default bank account
xmldict['uniben_acct'] = "6220027556"
xmldict['bank_id'] = '51'
if student_record.mode.endswith('_ft'):
#post-grad full-time students of all faculties
if student_record.level in ('700','710','800','810','900','910'):
xmldict['uniben_acct'] = "1012842833"
xmldict['bank_id'] = '117'
#all other part-time students depending on faculty
elif student_record.faculty in ('SSC','LAW','MED'):
xmldict['uniben_acct'] = "0005986938"
xmldict['bank_id'] = '31'
elif student_record.faculty in ('ENG','PSC','PHA'):
xmldict['uniben_acct'] = "0014413973"
xmldict['bank_id'] = '129'
elif student_record.faculty in ('LSC','DEN','AGR'):
xmldict['uniben_acct'] = "1012801319"
xmldict['bank_id'] = '117'
elif student_record.faculty in ('ART','EDU','MGS','BMS'):
xmldict['uniben_acct'] = "6220027556"
xmldict['bank_id'] = '51'
elif student_record.mode.endswith('_pt'):
#post-grad part-time students of all faculties
if student_record.level in ('700','710','800','810','900','910'):
xmldict['uniben_acct'] = "0023708207"
xmldict['bank_id'] = '72'
#all other part-time students depending on faculty
elif student_record.faculty in ('ENG','LAW','MGS'):
xmldict['uniben_acct'] = "2019006824"
xmldict['bank_id'] = '8'
elif student_record.faculty in ('IPA','PHA','SSC','AGR','EDU'):
xmldict['uniben_acct'] = "0122012109"
xmldict['bank_id'] = '16'
xmltext = """
""" % xmldict
info['xml_data'] = """""" % xmltext
args['Amount'] = "%d" % (itotal)
args['site_name'] = "uniben.waeup.org"
args['cust_name_desc'] = "Student Name"
args['pay_item_id'] = pay_item_id
args['pay_item_name'] = "UNIBEN Tuition Payments"
args['payment_params'] = 'college_split'
#args['xml_data'] = ''
#args['xml_data'] = xmltext # info['xml_data']can be used instead
info['args'] = args
return context.goto_interswitch_form(info=info)