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

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

payment conditions fixed

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