source: WAeUP_SRP/trunk/skins/waeup_uniben/pay_interswitch.py @ 8749

Last change on this file since 8749 was 8679, checked in by Henrik Bettermann, 12 years ago

Add penalty fee which is different for pg and ug students.

  • Property svn:keywords set to Id
File size: 8.0 KB
RevLine 
[7901]1##Script (Python) "pay_online"
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: pay_interswitch.py 8679 2012-06-11 11:28:03Z henrik $
11"""
12pay online
13"""
14from urllib import urlencode
15import logging
16logger = logging.getLogger('Skins.pay_interswitch')
17import DateTime
18
19if context.portal_membership.isAnonymousUser():
20    return None
21
22try:
23    from Products.zdb import set_trace
24except:
25    def set_trace():
26        pass
27request = context.REQUEST
28wftool = context.portal_workflow
29students = context.portal_url.getPortalObject().campus.students
30
31
32student_id = context.getStudentId()
33student = getattr(students,student_id)
34
35student_record = context.students_catalog.getRecordByKey(student_id)
36#amount,description = context.getSchoolFee(student_record.faculty,student_record.session,student_record.course)
37info = {}
38info['student'] = student_record
39info['payment_possible'] = False
40info['amount'] = '0'
41info['bank'] = ''
42info['type_description'] = ''
43info['pay_bill_to'] = ''
44fee_dict = context.getSchoolFee(student_record)
[8296]45
[7901]46fulltime = student_record.mode.endswith('_ft')
47new = student_record.review_state == 'cleared_and_validated'
48returning = student_record.review_state == 'returning'
[8005]49if not fee_dict or not (new or returning):
[7901]50    return context.interswitch_form(info=info)
51info['site_id'] = '57'
52info['currency_id'] = '566'
53if new:
54    amount = info['amount'] = fee_dict['new']
55elif returning:
56    amount = info['amount'] = fee_dict['returning']
[8296]57
[8679]58late_registration = False
59if new and int(student_record.session) < 11 and student_record.mode.startswith('ug'):
60    late_registration = True
61if returning and int(student_record.session) < 10 and student_record.mode.startswith('ug'):
62    late_registration = True
63if new and int(student_record.session) < 10 and student_record.mode.startswith('pg'):
64    late_registration = True
65if returning and int(student_record.session) < 9 and student_record.mode.startswith('pg'):
66    late_registration = True
67if late_registration:
[8296]68    amount_int = int(amount)
69    amount_int += 5000
70    amount = info['amount'] = '%d' % (amount_int)
71
[7901]72if fulltime:
73    pay_item_id = "5700"
74    info['bank'] = ''
75else:
76    pay_item_id = "5701"
77    info['bank'] = ''
78info['surcharge'] = '0'  # Uniben doesn't show the surcharge on the slip
79info['payment_possible'] = True
80info['type_description'] = fee_dict['description']
81info['pay_bill_to'] = student_record.name
82info['pay_ship_to'] = "University of Benin"
83info['student_id'] = student_id
84info['student_name'] = student_record.name
85info['student_email'] = student_record.email
86#info['session_id'] = student_record.session   # this holds only for new students und must be replaced when also previous session students will pay online !!!!!!
87info['session_id'] = fee_dict['next_session_id']
88info['type'] = 'online'
89info['status'] = 'started'
90info['item'] = student_record.course
91info['category'] = 'schoolfee'
92now = DateTime.DateTime()
93info['date'] = now
94timestamp = "%d" % int(now.timeTime()*1000)
95info['order_id'] = "%s%s" % (student_id[1:],timestamp)
96p_id = "p%s" % timestamp
97
98if student_id is None:
99    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
100
[8316]101# old: https://webpay.interswitchng.com/paydirect/webpay/pay.aspx
102
[7901]103if True or context.portal_url().find('uniben-demo.waeup.org') >-1 or\
104   context.portal_url().find('uniben.waeup.org') >-1:
105    #info['action'] = "https://webpay.interswitchng.com/test_paydirect/webpay/pay.aspx"
[8316]106    info['action'] = "https://webpay.interswitchng.com/webpayv4/webpay/pay.aspx"
[7901]107else:
108    info['action'] = "%s/payments/%s/simulate_callback" % (student.absolute_url(),p_id)
109
110
111if "payments" not in student.objectIds():
112    student.invokeFactory('PaymentsFolder','payments')
113    payments = getattr(student,'payments')
114    d = {}
115    d['Title'] = 'Payments'
116    payments.getContent().edit(mapping=d)
117    wftool.doActionFor(payments,'open')
118else:
119    payments = getattr(student,'payments')
120if request.has_key('epayment'):
121    return context.interswitch_form(info=info)
122
123
124payments.invokeFactory('Payment', p_id)
125payment = getattr(payments,p_id)
126wftool.doActionFor(payment,'open')
127d = {}
128d.update(info)
129payment.getContent().edit(mapping=d)
130info['callback_url'] = "%s/payments/%s/interswitch_cb?echo=%s" % (student.absolute_url(),
131                                                                  p_id,
132                                                                  p_id)
133
134logger.info('%(student_id)s initiated online school fee payment with order_id %(order_id)s and callback url %(callback_url)s' % info)
135payment_fields = (('product_id','site_id'),
136                  ('site_redirect_url','callback_url'),
137                  ('Currency','currency_id'),
138                  ('cust_id','student_id'),
139                  ('cust_id_desc','type_description'),
140                  ('cust_name','student_name'),
141                  ('txn_ref','order_id'),
142                  ('Amount','amount'),
143                  )
144args = {}
145for arg,field in payment_fields:
146    args[arg] = info[field]
147itotal = int(amount)*100
[8110]148
149#BT Amount Varies
150if student_record.mode.endswith('_ft') and student_record.review_state == 'return':
151        bt_amount = 60000
152else:
153        bt_amount = 150000
[8238]154#Interswitch amount 150 naira
155interswitch_amount = 15000
[8060]156uniben_amount = itotal - bt_amount - interswitch_amount
[7901]157xmldict = {}
158xmldict['detail_ref'] = args['txn_ref']
159xmldict['department'] = student_record.department
160xmldict['faculty'] = student_record.faculty
161xmldict['bt_amt'] = "%d" % bt_amount
162xmldict['uniben_amt'] = "%d" % uniben_amount
[8060]163
[7901]164#Full and Part-time students School Fees go into different Accounts
[8060]165
[8456]166# Default bank account
167xmldict['uniben_acct'] = "6220027556"
168xmldict['bank_id'] = '51'
169
[7901]170if student_record.mode.endswith('_ft'):
[8060]171        #post-grad full-time students of all faculties
172        if student_record.level in ('700','710','800','810','900','910'):
173            xmldict['uniben_acct'] = "1012842833"
174            xmldict['bank_id'] = '117'
175        #all other part-time students depending on faculty     
176        elif student_record.faculty in ('SSC','LAW','MED'):
177            xmldict['uniben_acct'] = "0005986938"
178            xmldict['bank_id'] = '31'
179        elif student_record.faculty in ('ENG','PSC','PHA'):
180            xmldict['uniben_acct'] = "0014413973"
181            xmldict['bank_id'] = '129'
182        elif student_record.faculty in ('LSC','DEN','AGR'):
183            xmldict['uniben_acct'] = "1012801319"
184            xmldict['bank_id'] = '117'
185        elif student_record.faculty in ('ART','EDU','MGS','BMS'):
186            xmldict['uniben_acct'] = "6220027556"
187            xmldict['bank_id'] = '51'
188elif student_record.mode.endswith('_pt'):
189        #post-grad part-time students of all faculties
190        if student_record.level in ('700','710','800','810','900','910'):
191            xmldict['uniben_acct'] = "0023708207"
192            xmldict['bank_id'] = '72'
193        #all other part-time students depending on faculty     
194        elif student_record.faculty in ('ENG','LAW','MGS'):
195            xmldict['uniben_acct'] = "2019006824"
196            xmldict['bank_id'] = '8'
197        elif student_record.faculty in ('IPA','PHA','SSC','AGR','EDU'):
198            xmldict['uniben_acct'] = "0122012109"
199            xmldict['bank_id'] = '16' 
[7901]200
[8060]201
[7901]202xmltext = """<payment_item_detail>
203<item_details detail_ref="%(detail_ref)s" college="UNIBEN" department="%(department)s" faculty="%(faculty)s">
204<item_detail item_id="1" item_name="UNIBEN School Fee" item_amt="%(uniben_amt)s" bank_id="%(bank_id)s" acct_num="%(uniben_acct)s" />
[8423]205<item_detail item_id="2" item_name="BT" item_amt="%(bt_amt)s" bank_id="117" acct_num="1010764827" />
[7901]206</item_details>
207</payment_item_detail>""" % xmldict
208
209info['xml_data'] = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
210
211args['Amount'] = "%d" % (itotal)
212args['site_name'] = "uniben.waeup.org"
213args['cust_name_desc'] = "Student Name"
214args['pay_item_id'] = pay_item_id
215args['pay_item_name'] = "UNIBEN Tuition Payments"
216args['payment_params'] = 'college_split'
217#args['xml_data'] = ''
218#args['xml_data'] = xmltext   # info['xml_data']can be used instead
219info['args'] = args
220
[8060]221return context.goto_interswitch_form(info=info)
Note: See TracBrowser for help on using the repository browser.