source: WAeUP_SRP/base/skins/waeup_epayment/pay_interswitch.py @ 2656

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

initialize payments_catalog.xml

  • Property svn:keywords set to Id
File size: 5.6 KB
RevLine 
[1885]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 2619 2007-11-10 17:39:36Z 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]
[2151]36#amount,description = context.getSchoolFee(sbrain.faculty,sbrain.session,sbrain.course)
[1885]37info = {}
[2151]38info['student'] = sbrain
39info['payment_possible'] = False
[2171]40info['amount'] = '0'
41info['bank'] = ''
42info['type_description'] = ''
43info['pay_bill_to'] = ''
[2151]44fee_dict = context.getSchoolFee(sbrain)
[2153]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):
[2151]50    return context.interswitch_form(info=info)
[1885]51info['site_id'] = '61'
52info['currency_id'] = '566'
[2153]53if new:
[2151]54    amount = info['amount'] = fee_dict['new']
[2153]55elif returning:
56    amount = info['amount'] = fee_dict['returning']
57if fulltime:
[2151]58    pay_item_id = "6100"
[2619]59    info['type_code'] = sbrain.faculty   #type_code is redundant and will be removed soon
[2172]60    info['bank'] = ''
[2151]61else:
62    pay_item_id = "6101"
[2619]63    info['type_code'] = sbrain.course  #type_code is redundant and will be removed soon
[2172]64    info['bank'] = ''
[2153]65info['payment_possible'] = True
[2151]66info['type_description'] = fee_dict['description']
[1885]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
[2619]74timestamp = "%d" % int(now.timeTime()*1000)
75info['order_id'] = "%s%s" % (student_id[1:],timestamp)
76p_id = "p%s" % timestamp
[1885]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:
[1946]83    info['action'] = "https://webpay.interswitchng.com/paydirect/webpay/pay.aspx"
[1885]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]
[1937]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
[1885]135xmldict = {}
[1992]136xmldict['detail_ref'] = args['txn_ref']
137xmldict['department'] = sbrain.department
[1885]138xmldict['faculty'] = sbrain.faculty
[1937]139#xmldict['wema_amt'] = "%d" % wema_amount
[1992]140#xmldict['provider_amt'] = "%d" % provider_amount
[1937]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" />
[1885]144xmltext = """
145<payment_item_detail>
[1992]146<item_details detail_ref="%(detail_ref)s" college="UNIBEN" department="%(department)s"
[1885]147faculty="%(faculty)s">
[1992]148<item_detail item_id="1" item_name="UNIBEN" item_amt="%(uniben_amt)s" bank_id="16" acct_num="384950902390" />
[1885]149</item_details>
150</payment_item_detail>
151""" % xmldict
[1937]152#total = int(xmldict['uniben_amt'])+int(xmldict['wema_amt'])+int(xmldict['provider_amt'])
153total = int(xmldict['uniben_amt'])
[1892]154args['Amount'] = "%d" % (total + 15000)
[1885]155args['site_name'] = "uniben.waeup.org"
156args['cust_name_desc'] = "Student Name"
[2151]157args['pay_item_id'] = pay_item_id
[1885]158args['pay_item_name'] = "UNIBEN Tuition Payments"
[1944]159args['payment_params'] = 'switch_college_split'
160#args['xml_data'] = xmltext % info
161args['xml_data'] = ''
[1885]162info['args'] = args
163return context.goto_interswitch_form(info=info)
Note: See TracBrowser for help on using the repository browser.