source: WAeUP_SRP/trunk_not_used/skins/waeup_epayment/pay_interswitch.py @ 2792

Last change on this file since 2792 was 2172, checked in by Henrik Bettermann, 17 years ago

remove bank information

  • Property svn:keywords set to Id
File size: 5.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 2172 2007-08-31 07:14:27Z henrik $
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]
36#amount,description = context.getSchoolFee(sbrain.faculty,sbrain.session,sbrain.course)
37info = {}
38info['student'] = sbrain
39info['payment_possible'] = False
40info['amount'] = '0'
41info['bank'] = ''
42info['type_description'] = ''
43info['pay_bill_to'] = ''
44fee_dict = context.getSchoolFee(sbrain)
45fulltime = sbrain.mode.endswith('_ft')
46#new =  sbrain.entry_session == context.getSessionId()[-2:]
47new = sbrain.review_state == 'cleared_and_validated'
48returning = sbrain.review_state == 'returning'
49if not fee_dict or (not new and fulltime) or not (new or returning):
50    return context.interswitch_form(info=info)
51info['site_id'] = '61'
52info['currency_id'] = '566'
53if new:
54    amount = info['amount'] = fee_dict['new']
55elif returning:
56    amount = info['amount'] = fee_dict['returning']
57if fulltime:
58    pay_item_id = "6100"
59    info['type_code'] = sbrain.faculty
60    info['bank'] = ''
61else:
62    pay_item_id = "6101"
63    info['type_code'] = sbrain.course
64    info['bank'] = ''
65info['payment_possible'] = True
66info['type_description'] = fee_dict['description']
67info['pay_bill_to'] = sbrain.name
68info['pay_ship_to'] = "University of Benin"
69info['student_id'] = student_id
70info['student_name'] = sbrain.name
71info['student_email'] = sbrain.email
72now = DateTime.DateTime()
73info['date'] = now
74order_id = info['order_id'] = "%d" % int(now.timeTime()*1000)
75info['order_id'] = "%s%s" % (student_id[1:],order_id)
76p_id = "p%s" % order_id
77
78if student_id is None:
79    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
80
81if 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"
84else:
85    #pass
86    #return None
87    info['action'] = "%s/payments/%s/simulate_callback" % (student.absolute_url(),p_id)
88
89
90if "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')
97else:
98    payments = getattr(student,'payments')
99if request.has_key('epayment'):
100    return context.interswitch_form(info=info)
101
102
103payments.invokeFactory('Payment', p_id)
104payment = getattr(payments,p_id)
105wftool.doActionFor(payment,'open')
106d = {}
107d.update(info)
108#from Products.zdb import set_trace;set_trace()
109payment.getContent().edit(mapping=d)
110#wftool.doActionFor(payment,'close')
111#wftool.doActionFor(student,'pay_school_fee')
112info['callback_url'] = "%s/payments/%s/interswitch_cb?echo=%s" % (student.absolute_url(),
113                                                                  p_id,
114                                                                  p_id)
115
116logger.info('%(student_id)s initiated online school fee payment with order_id %(order_id)s and callback url %(callback_url)s' % info)
117payment_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                  )
126args = {}
127for arg,field in payment_fields:
128    args[arg] = info[field]
129itotal = int(amount)*100
130wema_amount = 10000
131provider_amount = 35000
132interswitch_amount = 15000
133#uniben_amount = itotal - wema_amount - provider_amount - interswitch_amount
134uniben_amount = itotal - interswitch_amount
135xmldict = {}
136xmldict['detail_ref'] = args['txn_ref']
137xmldict['department'] = sbrain.department
138xmldict['faculty'] = sbrain.faculty
139#xmldict['wema_amt'] = "%d" % wema_amount
140#xmldict['provider_amt'] = "%d" % provider_amount
141xmldict['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" />
144xmltext = """
145<payment_item_detail>
146<item_details detail_ref="%(detail_ref)s" college="UNIBEN" department="%(department)s"
147faculty="%(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'])
153total = int(xmldict['uniben_amt'])
154args['Amount'] = "%d" % (total + 15000)
155args['site_name'] = "uniben.waeup.org"
156args['cust_name_desc'] = "Student Name"
157args['pay_item_id'] = pay_item_id
158args['pay_item_name'] = "UNIBEN Tuition Payments"
159args['payment_params'] = 'switch_college_split'
160#args['xml_data'] = xmltext % info
161args['xml_data'] = ''
162info['args'] = args
163return context.goto_interswitch_form(info=info)
Note: See TracBrowser for help on using the repository browser.