source: WAeUP_SRP/trunk/skins/waeup_uniben/pay_etranzact.py @ 8318

Last change on this file since 8318 was 8318, checked in by Henrik Bettermann, 12 years ago

Uups, returning students and new students must be treated differently when adding late payment fees.

  • Property svn:keywords set to Id
File size: 3.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_etranzact.py 8318 2012-04-30 15:18:10Z henrik $
11"""
12pay online
13"""
14from urllib import urlencode
15import logging
16logger = logging.getLogger('Skins.pay_etranzact')
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
35student_record = context.students_catalog.getRecordByKey(student_id)
36#amount,description = context.getSchoolFee(student_record.faculty,student_record.session,student_record.course)
37info = {}
38info['action'] = 'pay_etranzact'
39info['student'] = student_record
40info['payment_possible'] = False
41info['amount'] = '0'
42info['bank'] = ''
43info['type_description'] = ''
44info['pay_bill_to'] = ''
45fee_dict = context.getSchoolFee(student_record)
46#fulltime = student_record.mode.endswith('_ft')
47new = student_record.review_state == 'cleared_and_validated'
48returning = student_record.review_state == 'returning'
49if not fee_dict or not (new or returning):
50    return context.etranzact_form(info=info)
51if new:
52    amount = info['amount'] = fee_dict['new']
53elif returning:
54    amount = info['amount'] = fee_dict['returning']
55
56if new and int(student_record.session) < 11:
57    amount_int = int(amount)
58    amount_int += 5000
59    amount = info['amount'] = '%d' % (amount_int)
60if returning and int(student_record.session) < 10:
61    amount_int = int(amount)
62    amount_int += 5000
63    amount = info['amount'] = '%d' % (amount_int)
64
65info['surcharge'] = '0'  # Uniben doesn't show the surcharge on the slip
66info['payment_possible'] = True
67info['type_description'] = fee_dict['description']
68info['pay_bill_to'] = student_record.name
69info['pay_ship_to'] = "University of Benin"
70info['student_id'] = student_id
71info['student_name'] = student_record.name
72info['student_email'] = student_record.email
73#info['session_id'] = student_record.session   # this holds only for new students und must be replaced when also previous session students will pay online !!!!!!
74info['session_id'] = fee_dict['next_session_id']
75info['type'] = 'etranzact'
76info['status'] = 'started'
77info['item'] = student_record.course
78info['category'] = 'schoolfee'
79now = DateTime.DateTime()
80info['date'] = now
81timestamp = "%d" % int(now.timeTime()*1000)
82info['order_id'] = "%s%s" % (student_id[1:],timestamp)
83p_id = "p%s" % timestamp
84
85if student_id is None:
86    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
87
88if "payments" not in student.objectIds():
89    student.invokeFactory('PaymentsFolder','payments')
90    payments = getattr(student,'payments')
91    d = {}
92    d['Title'] = 'Payments'
93    payments.getContent().edit(mapping=d)
94    wftool.doActionFor(payments,'open')
95else:
96    payments = getattr(student,'payments')
97if request.has_key('epayment'):
98    return context.etranzact_form(info=info)
99
100payments.invokeFactory('Payment', p_id)
101payment = getattr(payments,p_id)
102wftool.doActionFor(payment,'open')
103d = {}
104d.update(info)
105payment.getContent().edit(mapping=d)
106logger.info('%(student_id)s initiated eTranzact school fee payment with order_id %(order_id)s' % info)
107
108return context.payments_view()
Note: See TracBrowser for help on using the repository browser.