## Script (Python) "pay_interswitch"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
# $Id: pay_interswitch.py 2619 2007-11-10 17:39:36Z 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')
if not fee_dict:
return context.interswitch_form(info=info)
info['site_id'] = '117'
info['currency_id'] = '566'
if student_record.mode in ('pg_ft'):
pay_item_id = "11703"
elif student_record.review_state == 'cleared_and_validated' and student_record.level in ('100'):
pay_item_id = "11700"
elif student_record.review_state == 'cleared_and_validated' and student_record.level in ('200'):
pay_item_id = "11701"
elif student_record.review_state == 'cleared_and_validated' and student_record.level in ('300'):
pay_item_id = "11702"
elif student_record.review_state == 'returning' and student_record.level in ('100','110'):
pay_item_id = "11701"
elif student_record.review_state == 'returning' and student_record.level in ('200','210'):
pay_item_id = "11702"
elif student_record.review_state == 'returning' and student_record.level in ('300','310'):
pay_item_id = "11703"
elif student_record.review_state == 'returning' and student_record.level in ('400','410','500','510','600'):
pay_item_id = "11704"
else:
pay_item_id = ""
info['bank'] = ''
info['payment_possible'] = True
info['type_description'] = fee_dict['description']
info['pay_bill_to'] = student_record.name
info['student_id'] = student_id
info['student_name'] = student_record.name
info['type'] = 'online'
info['status'] = 'started'
info['session_id'] = fee_dict['next_session_id']
info['item'] = student_record.course
info['category'] = 'schoolfee'
info['student_email'] = student_record.email
now = DateTime.DateTime()
info['date'] = now
info['pay_ship_to'] = "Federal University of Technology, Minna, Nigeria"
timestamp = "%d" % int(now.timeTime()*1000)
info['order_id'] = "%s%s" % (student_id[1:],timestamp)
p_id = "p%s" % timestamp
info['surcharge'] = 0 # students don't have to pay the surcharge, FUT is paying for them
interswitch_amount = 300
info['amount'] = amount = fee_dict['all']
total_amount = 100*int(amount)
if student_id is None:
return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
if True:
info['action'] = "https://webpay.interswitchng.com/paydirect/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]
bt_amount = 1500
#fut_split = 0000 #not appicable
fut_amount = amount - bt_amount - interswitch_amount
xmldict = {}
xmldict['detail_ref'] = args['txn_ref']
xmldict['department'] = student_record.department
xmldict['level'] = student_record.level
xmldict['faculty'] = student_record.faculty
xmldict['fut_amount'] = "%d" % int(100*fut_amount)
xmldict['bt_amount'] = "%d" % int(100*bt_amount)
#xmldict['fut_split'] = "%d" % int(100*fut_split)
#students at all levels pay their school fees to different banks
if student_record.mode == 'jm_ft':
xmldict['fut_acct'] = "000000000000"
xmldict['bank_id'] = '0'
elif student_record.mode in ('pg_ft'):
xmldict['fut_acct'] = "2522040000134"
xmldict['bank_id'] = '8'
elif student_record.review_state == 'cleared_and_validated' and student_record.level in ('100'):
xmldict['fut_acct'] = "0030001000017110"
xmldict['bank_id'] = '89'
elif student_record.review_state == 'cleared_and_validated' and student_record.level in ('200'):
xmldict['fut_acct'] = "0591201005146"
xmldict['bank_id'] = '101'
elif student_record.review_state == 'cleared_and_validated' and student_record.level in ('300'):
xmldict['fut_acct'] = "6013803345"
xmldict['bank_id'] = '117'
elif student_record.review_state == 'returning' and student_record.level in ('100','110'):
xmldict['fut_acct'] = "0591201005146"
xmldict['bank_id'] = '101'
elif student_record.level in ('200','210'):
xmldict['fut_acct'] = "6013803345"
xmldict['bank_id'] = '117'
elif student_record.level in ('300','310'):
xmldict['fut_acct'] = "2522040000134"
xmldict['bank_id'] = '8'
#Change of acct from UBA to GTBank
elif student_record.level in ('400','410','500','510','600'):
xmldict['fut_acct'] = "3713516838111"
xmldict['bank_id'] = '10'
#remedial students
#elif student_record.level in ('000'):
#xmldict['fut_acct'] = "00000000000"
#xmldict['bank_id'] = '0'
else:
xmldict['fut_acct'] = "0000000000000"
xmldict['bank_id'] = '0'
xmltext = """
""" % xmldict
info['xml_data'] = """""" % xmltext
args['Amount'] = "%d" % (total_amount)
args['site_name'] = "futminna.waeup.org"
args['cust_name_desc'] = "Student Name"
args['pay_item_id'] = pay_item_id
args['pay_item_name'] = "FUT Minna 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)