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 2664 2007-11-15 14:35:05Z 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) |
---|
45 | fulltime = student_record.mode.endswith('_ft') |
---|
46 | new = student_record.review_state == 'cleared_and_validated' |
---|
47 | returning = student_record.review_state == 'returning' |
---|
48 | if not fee_dict or (not new and fulltime) or not (new or returning): |
---|
49 | return context.interswitch_form(info=info) |
---|
50 | info['site_id'] = '61' |
---|
51 | info['currency_id'] = '566' |
---|
52 | if new: |
---|
53 | amount = info['amount'] = fee_dict['new'] |
---|
54 | elif returning: |
---|
55 | amount = info['amount'] = fee_dict['returning'] |
---|
56 | if fulltime: |
---|
57 | pay_item_id = "6100" |
---|
58 | #info['type_code'] = student_record.faculty #type_code is redundant and will be removed soon |
---|
59 | info['bank'] = '' |
---|
60 | else: |
---|
61 | pay_item_id = "6101" |
---|
62 | #info['type_code'] = student_record.course #type_code is redundant and will be removed soon |
---|
63 | info['bank'] = '' |
---|
64 | info['payment_possible'] = True |
---|
65 | info['type_description'] = fee_dict['description'] |
---|
66 | info['pay_bill_to'] = student_record.name |
---|
67 | info['pay_ship_to'] = "University of Benin" |
---|
68 | info['student_id'] = student_id |
---|
69 | info['student_name'] = student_record.name |
---|
70 | info['student_email'] = student_record.email |
---|
71 | info['session_id'] = student_record.session # this holds only for new students |
---|
72 | info['type'] = 'online' |
---|
73 | info['status'] = 'started' |
---|
74 | info['item'] = student_record.course |
---|
75 | info['category'] = 'schoolfee' |
---|
76 | now = DateTime.DateTime() |
---|
77 | info['date'] = now |
---|
78 | timestamp = "%d" % int(now.timeTime()*1000) |
---|
79 | info['order_id'] = "%s%s" % (student_id[1:],timestamp) |
---|
80 | p_id = "p%s" % timestamp |
---|
81 | |
---|
82 | if student_id is None: |
---|
83 | return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
84 | |
---|
85 | if True or context.portal_url().find('uniben-demo.waeup.org') >-1 or\ |
---|
86 | context.portal_url().find('uniben.waeup.org') >-1: |
---|
87 | info['action'] = "https://webpay.interswitchng.com/paydirect/webpay/pay.aspx" |
---|
88 | else: |
---|
89 | #pass |
---|
90 | #return None |
---|
91 | info['action'] = "%s/payments/%s/simulate_callback" % (student.absolute_url(),p_id) |
---|
92 | |
---|
93 | |
---|
94 | if "payments" not in student.objectIds(): |
---|
95 | student.invokeFactory('PaymentsFolder','payments') |
---|
96 | payments = getattr(student,'payments') |
---|
97 | d = {} |
---|
98 | d['Title'] = 'Payments' |
---|
99 | payments.getContent().edit(mapping=d) |
---|
100 | wftool.doActionFor(payments,'open') |
---|
101 | else: |
---|
102 | payments = getattr(student,'payments') |
---|
103 | if request.has_key('epayment'): |
---|
104 | return context.interswitch_form(info=info) |
---|
105 | |
---|
106 | |
---|
107 | payments.invokeFactory('Payment', p_id) |
---|
108 | payment = getattr(payments,p_id) |
---|
109 | wftool.doActionFor(payment,'open') |
---|
110 | d = {} |
---|
111 | d.update(info) |
---|
112 | #from Products.zdb import set_trace;set_trace() |
---|
113 | payment.getContent().edit(mapping=d) |
---|
114 | #wftool.doActionFor(payment,'close') |
---|
115 | #wftool.doActionFor(student,'pay_school_fee') |
---|
116 | info['callback_url'] = "%s/payments/%s/interswitch_cb?echo=%s" % (student.absolute_url(), |
---|
117 | p_id, |
---|
118 | p_id) |
---|
119 | |
---|
120 | logger.info('%(student_id)s initiated online school fee payment with order_id %(order_id)s and callback url %(callback_url)s' % info) |
---|
121 | payment_fields = (('product_id','site_id'), |
---|
122 | ('site_redirect_url','callback_url'), |
---|
123 | ('Currency','currency_id'), |
---|
124 | ('cust_id','student_id'), |
---|
125 | ('cust_id_desc','type_description'), |
---|
126 | ('cust_name','student_name'), |
---|
127 | ('txn_ref','order_id'), |
---|
128 | ('Amount','amount'), |
---|
129 | ) |
---|
130 | args = {} |
---|
131 | for arg,field in payment_fields: |
---|
132 | args[arg] = info[field] |
---|
133 | itotal = int(amount)*100 |
---|
134 | wema_amount = 10000 |
---|
135 | provider_amount = 35000 |
---|
136 | interswitch_amount = 15000 |
---|
137 | #uniben_amount = itotal - wema_amount - provider_amount - interswitch_amount |
---|
138 | uniben_amount = itotal - interswitch_amount |
---|
139 | xmldict = {} |
---|
140 | xmldict['detail_ref'] = args['txn_ref'] |
---|
141 | xmldict['department'] = student_record.department |
---|
142 | xmldict['faculty'] = student_record.faculty |
---|
143 | #xmldict['wema_amt'] = "%d" % wema_amount |
---|
144 | #xmldict['provider_amt'] = "%d" % provider_amount |
---|
145 | xmldict['uniben_amt'] = "%d" % uniben_amount |
---|
146 | ##<item_detail item_id="2" item_name="WEMA" item_amt="%(wema_amt)s" bank_id="16" acct_num="48398023902" /> |
---|
147 | ##<item_detail item_id="3" item_name="Portal Provider" item_amt="%(provider_amt)s" bank_id="47" acct_num="0980938209483" /> |
---|
148 | xmltext = """ |
---|
149 | <payment_item_detail> |
---|
150 | <item_details detail_ref="%(detail_ref)s" college="UNIBEN" department="%(department)s" |
---|
151 | faculty="%(faculty)s"> |
---|
152 | <item_detail item_id="1" item_name="UNIBEN" item_amt="%(uniben_amt)s" bank_id="16" acct_num="384950902390" /> |
---|
153 | </item_details> |
---|
154 | </payment_item_detail> |
---|
155 | """ % xmldict |
---|
156 | #total = int(xmldict['uniben_amt'])+int(xmldict['wema_amt'])+int(xmldict['provider_amt']) |
---|
157 | total = int(xmldict['uniben_amt']) |
---|
158 | args['Amount'] = "%d" % (total + 15000) |
---|
159 | args['site_name'] = "uniben.waeup.org" |
---|
160 | args['cust_name_desc'] = "Student Name" |
---|
161 | args['pay_item_id'] = pay_item_id |
---|
162 | args['pay_item_name'] = "UNIBEN Tuition Payments" |
---|
163 | args['payment_params'] = 'switch_college_split' |
---|
164 | #args['xml_data'] = xmltext % info |
---|
165 | args['xml_data'] = '' |
---|
166 | info['args'] = args |
---|
167 | return context.goto_interswitch_form(info=info) |
---|