source: WAeUP_SRP/base/skins/waeup_epayment/pay_interswitch_acco.py @ 2859

Last change on this file since 2859 was 2857, checked in by joachim, 17 years ago
  • Property svn:keywords set to Id
File size: 4.6 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 2857 2007-12-04 16:28:13Z joachim $
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')
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)
44    info['student'] = student_record
45else:
46    info = {}
47    info['student'] = student_record
48    info['payment_possible'] = False
49    info['amount'] = '0'
50    info['bank'] = ''
51    info['type_description'] = ''
52    info['pay_bill_to'] = ''
53    fee_dict = context.getSchoolFee(student_record)
54    fulltime = student_record.mode.endswith('_ft')
55    new = student_record.review_state == 'cleared_and_validated'
56    returning = student_record.review_state == 'returning'
57    if not fee_dict or (not new and fulltime) or not (new or returning):
58        return context.interswitch_form(info=info)
59    if new:
60        amount = info['amount'] = fee_dict['new']
61    elif returning:
62        amount = info['amount'] = fee_dict['returning']
63    if fulltime:
64        pay_item_id = "6100"
65        info['type_code'] = student_record.faculty   #type_code is redundant and will be removed soon
66        info['bank'] = ''
67    else:
68        pay_item_id = "6101"
69        info['type_code'] = student_record.course  #type_code is redundant and will be removed soon
70        info['bank'] = ''
71    info['payment_possible'] = True
72    info['type_description'] = fee_dict['description']
73    info['pay_ship_to'] = "University of Benin"
74info['pay_bill_to'] = student_record.name
75info['student_id'] = student_id
76info['student_name'] = student_record.name
77info['student_email'] = student_record.email
78info['date'] = now
79info['order_id'] = "%s%s" % (student_id[1:],timestamp)
80
81if "payments" not in student.objectIds():
82    student.invokeFactory('PaymentsFolder','payments')
83    payments = getattr(student,'payments')
84    d = {}
85    d['Title'] = 'Payments'
86    payments.getContent().edit(mapping=d)
87    wftool.doActionFor(payments,'open')
88else:
89    payments = getattr(student,'payments')
90if request.has_key('epayment'):
91    return context.interswitch_form(info=info)
92
93
94payments.invokeFactory('Payment', payment_id)
95payment = getattr(payments,payment_id)
96wftool.doActionFor(payment,'open')
97d = {}
98d.update(info)
99payment.getContent().edit(mapping=d)
100#wftool.doActionFor(payment,'close')
101#wftool.doActionFor(student,'pay_school_fee')
102info['callback_url'] = "%s/payments/%s/%s?echo=%s" % (student.absolute_url(),
103                                                      payment_id,
104                                                      info['callback_function'],
105                                                      payment_id)
106
107logger.info('%(student_id)s initiated %(description)s payment with order_id %(order_id)s and callback url %(callback_url)s' % info)
108payment_fields = (('product_id','site_id'),
109                  ('site_name','site_name'),
110                  ('site_redirect_url','callback_url'),
111                  ('Currency','currency_id'),
112                  ('cust_id','student_id'),
113                  ('cust_id_desc','type_description'),
114                  ('cust_name','student_name'),
115                  ('txn_ref','order_id'),
116                  ('Amount','amount'),
117                  ('pay_item_id','pay_item_id'),
118                  ('pay_item_name','pay_item_name'),
119                  ('payment_params','payment_params'),
120                  )
121args = {}
122for arg,field in payment_fields:
123    args[arg] = info[field]
124interswitch_amount = int(info['surcharge'])*100
125uni_amount = int(info['amount'])*100
126total_amount = interswitch_amount + uni_amount
127args['Amount'] = "%d" % (total_amount)
128args['cust_name_desc'] = "Student Name"
129args['xml_data'] = ''
130info['args'] = args
131return context.goto_interswitch_form(info=info)
Note: See TracBrowser for help on using the repository browser.