source: WAeUP_SRP/trunk/skins/waeup_epayment/pay_interswitch_acco.py @ 17950

Last change on this file since 17950 was 5592, checked in by Henrik Bettermann, 14 years ago

Avoid traceback if form is called through URL.

  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1## Script (Python) "pay_interswitch_acco"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=paytype=None
8##title=
9##
10# $Id: pay_interswitch_acco.py 5592 2010-11-23 07:14:25Z henrik $
11"""
12pay online
13"""
14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
19from urllib import urlencode
20import logging
21logger = logging.getLogger('Skins.pay_interswitch_acco')
22import DateTime
23
24if context.portal_membership.isAnonymousUser():
25    return None
26
27request = context.REQUEST
28wftool = context.portal_workflow
29students = context.portal_url.getPortalObject().campus.students
30
31student_id = context.getStudentId()
32if student_id is None:
33    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
34student = getattr(students,student_id)
35
36student_record = context.students_catalog.getRecordByKey(student_id)
37#amount,description = context.getSchoolFee(student_record.faculty,student_record.session,student_record.course)
38now = DateTime.DateTime()
39timestamp = "%d" % int(now.timeTime()*1000)
40payment_id = "p%s" % timestamp
41hostel = paytype == "HOM"
42if hostel:
43    info = context.getInterswitchParams(paytype,student,payment_id,student_record)
44    info['student'] = student_record
45else:
46    return None
47
48info['pay_bill_to'] = student_record.name
49info['student_id'] = student_id
50info['student_name'] = student_record.name
51info['session_id'] = student_record.session
52info['student_email'] = student_record.email
53info['date'] = now
54info['order_id'] = "%s%s" % (student_id[1:],timestamp)
55
56if "payments" not in student.objectIds():
57    student.invokeFactory('PaymentsFolder','payments')
58    payments = getattr(student,'payments')
59    d = {}
60    d['Title'] = 'Payments'
61    payments.getContent().edit(mapping=d)
62    wftool.doActionFor(payments,'open')
63else:
64    payments = getattr(student,'payments')
65if request.has_key('epayment'):
66    return context.interswitch_form(info=info)
67
68
69payments.invokeFactory('Payment', payment_id)
70payment = getattr(payments,payment_id)
71wftool.doActionFor(payment,'open')
72d = {}
73d.update(info)
74payment.getContent().edit(mapping=d)
75#wftool.doActionFor(payment,'close')
76#wftool.doActionFor(student,'pay_school_fee')
77info['callback_url'] = "%s/payments/%s/%s?echo=%s" % (student.absolute_url(),
78                                                      payment_id,
79                                                      info['callback_function'],
80                                                      payment_id)
81
82logger.info('%(student_id)s initiated %(type_description)s payment with order_id %(order_id)s and callback url %(callback_url)s' % info)
83payment_fields = (('product_id','site_id'),
84                  ('site_name','site_name'),
85                  ('site_redirect_url','callback_url'),
86                  ('Currency','currency_id'),
87                  ('cust_id','student_id'),
88                  ('cust_id_desc','type_description'),
89                  ('cust_name','student_name'),
90                  ('txn_ref','order_id'),
91                  ('Amount','amount'),
92                  ('pay_item_id','pay_item_id'),
93                  ('pay_item_name','pay_item_name'),
94                  ('payment_params','payment_params'),
95                  )
96args = {}
97for arg,field in payment_fields:
98    args[arg] = info[field]
99interswitch_amount = int(info['surcharge'])*100
100uni_amount = int(info['amount'])*100
101total_amount = interswitch_amount + uni_amount
102args['Amount'] = "%d" % (total_amount)
103args['cust_name_desc'] = "Student Name"
104args['xml_data'] = info['xml_data'] =''
105info['args'] = args
106return context.goto_interswitch_form(info=info)
Note: See TracBrowser for help on using the repository browser.