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