source: WAeUP_Base/branches/joachim-azax-branch/skins/waeup_epayment/pay_interswitch.py @ 2198

Last change on this file since 2198 was 1946, checked in by joachim, 17 years ago

live interswitch url (in custom)

  • Property svn:keywords set to Id
File size: 4.7 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 1946 2007-06-22 14:01:38Z 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/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]
106itotal = int(amount)*100
107wema_amount = 10000
108provider_amount = 35000
109interswitch_amount = 15000
110#uniben_amount = itotal - wema_amount - provider_amount - interswitch_amount
111uniben_amount = itotal - interswitch_amount
112xmldict = {}
113xmldict['detail_ref'] = args['txn_ref']
114xmldict['department'] = sbrain.department
115xmldict['faculty'] = sbrain.faculty
116#xmldict['wema_amt'] = "%d" % wema_amount
117#xmldict['provider_amt'] = "%d" % provider_amount
118xmldict['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" />
121xmltext = """
122<payment_item_detail>
123<item_details detail_ref="%(detail_ref)s" college="UNIBEN" department="%(department)s"
124faculty="%(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'])
130total = int(xmldict['uniben_amt'])
131args['Amount'] = "%d" % (total + 15000)
132args['site_name'] = "uniben.waeup.org"
133args['cust_name_desc'] = "Student Name"
134args['pay_item_id'] = "6100"
135args['pay_item_name'] = "UNIBEN Tuition Payments"
136args['payment_params'] = 'switch_college_split'
137#args['xml_data'] = xmltext % info
138args['xml_data'] = ''
139info['args'] = args
140return context.goto_interswitch_form(info=info)
Note: See TracBrowser for help on using the repository browser.