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