[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 | """
|
---|
| 12 | pay online
|
---|
| 13 | """
|
---|
| 14 | from urllib import urlencode
|
---|
| 15 | import logging
|
---|
| 16 | logger = logging.getLogger('Skins.pay_interswitch')
|
---|
| 17 | import DateTime
|
---|
| 18 |
|
---|
| 19 | if context.portal_membership.isAnonymousUser():
|
---|
| 20 | return None
|
---|
| 21 |
|
---|
| 22 | try:
|
---|
| 23 | from Products.zdb import set_trace
|
---|
| 24 | except:
|
---|
| 25 | def set_trace():
|
---|
| 26 | pass
|
---|
| 27 | request = context.REQUEST
|
---|
| 28 | wftool = context.portal_workflow
|
---|
| 29 | students = context.portal_url.getPortalObject().campus.students
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | student_id = context.getStudentId()
|
---|
| 33 | student = getattr(students,student_id)
|
---|
| 34 |
|
---|
| 35 | student_record = context.students_catalog.getRecordByKey(student_id)
|
---|
| 36 | #amount,description = context.getSchoolFee(student_record.faculty,student_record.session,student_record.course)
|
---|
| 37 | info = {}
|
---|
| 38 | info['student'] = student_record
|
---|
| 39 | info['payment_possible'] = False
|
---|
| 40 | info['amount'] = '0'
|
---|
| 41 | info['bank'] = ''
|
---|
| 42 | info['type_description'] = ''
|
---|
| 43 | info['pay_bill_to'] = ''
|
---|
| 44 | fee_dict = context.getSchoolFee(student_record)
|
---|
[8296] | 45 |
|
---|
[7901] | 46 | fulltime = student_record.mode.endswith('_ft')
|
---|
| 47 | new = student_record.review_state == 'cleared_and_validated'
|
---|
| 48 | returning = student_record.review_state == 'returning'
|
---|
[8005] | 49 | if not fee_dict or not (new or returning):
|
---|
[7901] | 50 | return context.interswitch_form(info=info)
|
---|
| 51 | info['site_id'] = '57'
|
---|
| 52 | info['currency_id'] = '566'
|
---|
| 53 | if new:
|
---|
| 54 | amount = info['amount'] = fee_dict['new']
|
---|
| 55 | elif returning:
|
---|
| 56 | amount = info['amount'] = fee_dict['returning']
|
---|
[8296] | 57 |
|
---|
[8679] | 58 | late_registration = False
|
---|
| 59 | if new and int(student_record.session) < 11 and student_record.mode.startswith('ug'):
|
---|
| 60 | late_registration = True
|
---|
| 61 | if returning and int(student_record.session) < 10 and student_record.mode.startswith('ug'):
|
---|
| 62 | late_registration = True
|
---|
| 63 | if new and int(student_record.session) < 10 and student_record.mode.startswith('pg'):
|
---|
| 64 | late_registration = True
|
---|
| 65 | if returning and int(student_record.session) < 9 and student_record.mode.startswith('pg'):
|
---|
| 66 | late_registration = True
|
---|
| 67 | if late_registration:
|
---|
[8296] | 68 | amount_int = int(amount)
|
---|
| 69 | amount_int += 5000
|
---|
| 70 | amount = info['amount'] = '%d' % (amount_int)
|
---|
| 71 |
|
---|
[7901] | 72 | if fulltime:
|
---|
| 73 | pay_item_id = "5700"
|
---|
| 74 | info['bank'] = ''
|
---|
| 75 | else:
|
---|
| 76 | pay_item_id = "5701"
|
---|
| 77 | info['bank'] = ''
|
---|
| 78 | info['surcharge'] = '0' # Uniben doesn't show the surcharge on the slip
|
---|
| 79 | info['payment_possible'] = True
|
---|
| 80 | info['type_description'] = fee_dict['description']
|
---|
| 81 | info['pay_bill_to'] = student_record.name
|
---|
| 82 | info['pay_ship_to'] = "University of Benin"
|
---|
| 83 | info['student_id'] = student_id
|
---|
| 84 | info['student_name'] = student_record.name
|
---|
| 85 | info['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 !!!!!!
|
---|
| 87 | info['session_id'] = fee_dict['next_session_id']
|
---|
| 88 | info['type'] = 'online'
|
---|
| 89 | info['status'] = 'started'
|
---|
| 90 | info['item'] = student_record.course
|
---|
| 91 | info['category'] = 'schoolfee'
|
---|
| 92 | now = DateTime.DateTime()
|
---|
| 93 | info['date'] = now
|
---|
| 94 | timestamp = "%d" % int(now.timeTime()*1000)
|
---|
| 95 | info['order_id'] = "%s%s" % (student_id[1:],timestamp)
|
---|
| 96 | p_id = "p%s" % timestamp
|
---|
| 97 |
|
---|
| 98 | if 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] | 103 | if 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] | 107 | else:
|
---|
| 108 | info['action'] = "%s/payments/%s/simulate_callback" % (student.absolute_url(),p_id)
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 | if "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')
|
---|
| 118 | else:
|
---|
| 119 | payments = getattr(student,'payments')
|
---|
| 120 | if request.has_key('epayment'):
|
---|
| 121 | return context.interswitch_form(info=info)
|
---|
| 122 |
|
---|
| 123 |
|
---|
| 124 | payments.invokeFactory('Payment', p_id)
|
---|
| 125 | payment = getattr(payments,p_id)
|
---|
| 126 | wftool.doActionFor(payment,'open')
|
---|
| 127 | d = {}
|
---|
| 128 | d.update(info)
|
---|
| 129 | payment.getContent().edit(mapping=d)
|
---|
| 130 | info['callback_url'] = "%s/payments/%s/interswitch_cb?echo=%s" % (student.absolute_url(),
|
---|
| 131 | p_id,
|
---|
| 132 | p_id)
|
---|
| 133 |
|
---|
| 134 | logger.info('%(student_id)s initiated online school fee payment with order_id %(order_id)s and callback url %(callback_url)s' % info)
|
---|
| 135 | payment_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 | )
|
---|
| 144 | args = {}
|
---|
| 145 | for arg,field in payment_fields:
|
---|
| 146 | args[arg] = info[field]
|
---|
| 147 | itotal = int(amount)*100
|
---|
[8110] | 148 |
|
---|
| 149 | #BT Amount Varies
|
---|
| 150 | if student_record.mode.endswith('_ft') and student_record.review_state == 'return':
|
---|
| 151 | bt_amount = 60000
|
---|
| 152 | else:
|
---|
| 153 | bt_amount = 150000
|
---|
[8238] | 154 | #Interswitch amount 150 naira
|
---|
| 155 | interswitch_amount = 15000
|
---|
[8060] | 156 | uniben_amount = itotal - bt_amount - interswitch_amount
|
---|
[7901] | 157 | xmldict = {}
|
---|
| 158 | xmldict['detail_ref'] = args['txn_ref']
|
---|
| 159 | xmldict['department'] = student_record.department
|
---|
| 160 | xmldict['faculty'] = student_record.faculty
|
---|
| 161 | xmldict['bt_amt'] = "%d" % bt_amount
|
---|
| 162 | xmldict['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
|
---|
| 167 | xmldict['uniben_acct'] = "6220027556"
|
---|
| 168 | xmldict['bank_id'] = '51'
|
---|
| 169 |
|
---|
[7901] | 170 | if 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'
|
---|
| 188 | elif 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] | 202 | xmltext = """<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 |
|
---|
| 209 | info['xml_data'] = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext
|
---|
| 210 |
|
---|
| 211 | args['Amount'] = "%d" % (itotal)
|
---|
| 212 | args['site_name'] = "uniben.waeup.org"
|
---|
| 213 | args['cust_name_desc'] = "Student Name"
|
---|
| 214 | args['pay_item_id'] = pay_item_id
|
---|
| 215 | args['pay_item_name'] = "UNIBEN Tuition Payments"
|
---|
| 216 | args['payment_params'] = 'college_split'
|
---|
| 217 | #args['xml_data'] = ''
|
---|
| 218 | #args['xml_data'] = xmltext # info['xml_data']can be used instead
|
---|
| 219 | info['args'] = args
|
---|
| 220 |
|
---|
[8060] | 221 | return context.goto_interswitch_form(info=info)
|
---|