source: WAeUP_SRP/trunk/skins/waeup_epayment/pay_interswitch.py @ 1917

Last change on this file since 1917 was 1892, checked in by joachim, 17 years ago

mostly interswitch integration

  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
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 1892 2007-06-13 15:57:09Z joachim $
11"""
12pay online
13"""
14from urllib import urlencode
15import logging
16logger = logging.getLogger('Skins.pay_interswitch')
17import DateTime
18
19if context.portal_membership.isAnonymousUser():
20    return None
21
22try:
23    from Products.zdb import set_trace
24except:
25    def set_trace():
26        pass
27request = context.REQUEST
28wftool = context.portal_workflow
29students = context.portal_url.getPortalObject().campus.students
30
31
32student_id = context.getStudentId()
33student = getattr(students,student_id)
34
35sbrain = context.students_catalog(id=student_id)[0]
36amount,description = context.getSchoolFee(sbrain.faculty)
37info = {}
38info['site_id'] = '61'
39info['currency_id'] = '566'
40info['amount'] = amount
41info['type_code'] = sbrain.faculty
42info['type_description'] = description
43info['pay_bill_to'] = sbrain.name
44info['pay_ship_to'] = "University of Benin"
45info['student_id'] = student_id
46info['student_name'] = sbrain.name
47info['student_email'] = sbrain.email
48now = DateTime.DateTime()
49info['date'] = now
50order_id = info['order_id'] = "%d" % int(now.timeTime()*1000)
51info['order_id'] = "%s%s" % (student_id[1:],order_id)
52p_id = "p%s" % order_id
53
54#from Products.zdb import set_trace;set_trace()
55if student_id is None:
56    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
57
58if 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/test_paydirect/webpay/pay.aspx"
61else:
62    #pass
63    #return None
64    info['action'] = "%s/payments/%s/simulate_callback" % (student.absolute_url(),p_id)
65
66
67if "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')
74else:
75    payments = getattr(student,'payments')
76if request.has_key('epayment'):
77    return context.interswitch_form(info=info)
78
79
80payments.invokeFactory('Payment', p_id)
81payment = getattr(payments,p_id)
82wftool.doActionFor(payment,'open')
83d = {}
84d.update(info)
85#from Products.zdb import set_trace;set_trace()
86payment.getContent().edit(mapping=d)
87#wftool.doActionFor(payment,'close')
88#wftool.doActionFor(student,'pay_school_fee')
89info['callback_url'] = "%s/payments/%s/interswitch_cb?echo=%s" % (student.absolute_url(),
90                                                                  p_id,
91                                                                  p_id)
92
93logger.info('%(student_id)s initiated online school fee payment with order_id %(order_id)s and callback url %(callback_url)s' % info)
94payment_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                  )
103args = {}
104for arg,field in payment_fields:
105    args[arg] = info[field]
106xmldict = {}
107xmldict['detail_ref'] = args['txn_ref']
108xmldict['department'] = sbrain.department
109xmldict['faculty'] = sbrain.faculty
110xmldict['uniben_amt'] = "%s00" % amount
111xmldict['wema_amt'] = "10000"
112xmldict['provider_amt'] = "35000"
113xmltext = """
114<payment_item_detail>
115<item_details detail_ref="%(detail_ref)s" college="UNIBEN" department="%(department)s"
116faculty="%(faculty)s">
117<item_detail item_id="1" item_name="UNIBEN" item_amt="%(uniben_amt)s" bank_id="16" acct_num="384950902390" /> 
118<item_detail item_id="2" item_name="WEMA" item_amt="%(wema_amt)s" bank_id="16" acct_num="48398023902" />
119<item_detail item_id="3" item_name="Portal Provider" item_amt="%(provider_amt)s" bank_id="47" acct_num="0980938209483" />
120</item_details>
121</payment_item_detail>
122""" % xmldict
123total = int(xmldict['uniben_amt'])+int(xmldict['wema_amt'])+int(xmldict['provider_amt'])
124args['Amount'] = "%d" % (total + 15000)
125args['site_name'] = "uniben.waeup.org"
126args['cust_name_desc'] = "Student Name"
127args['pay_item_id'] = "6100"
128args['pay_item_name'] = "UNIBEN Tuition Payments"
129args['payment_params'] = 'college_split'
130args['xml_data'] = xmltext % info
131info['args'] = args
132return context.goto_interswitch_form(info=info)
133url = info['action'] + "?" + urlencode(args)
134request.RESPONSE.redirect(url)
Note: See TracBrowser for help on using the repository browser.