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