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 | """
|
---|
12 | pay online
|
---|
13 | """
|
---|
14 | from urllib import urlencode
|
---|
15 | import logging
|
---|
16 | logger = logging.getLogger('Skins.pay_etranzact')
|
---|
17 | import DateTime
|
---|
18 |
|
---|
19 | if context.portal_membership.isAnonymousUser():
|
---|
20 | return None
|
---|
21 |
|
---|
22 | try:
|
---|
23 | from Products.zdb import set_trace
|
---|
24 | except:
|
---|
25 | def set_trace():
|
---|
26 | pass
|
---|
27 | request = context.REQUEST
|
---|
28 | wftool = context.portal_workflow
|
---|
29 | students = context.portal_url.getPortalObject().campus.students
|
---|
30 |
|
---|
31 |
|
---|
32 | student_id = context.getStudentId()
|
---|
33 | student = getattr(students,student_id)
|
---|
34 |
|
---|
35 | student_record = context.students_catalog.getRecordByKey(student_id)
|
---|
36 | #amount,description = context.getSchoolFee(student_record.faculty,student_record.session,student_record.course)
|
---|
37 | info = {}
|
---|
38 | info['action'] = 'pay_etranzact'
|
---|
39 | info['student'] = student_record
|
---|
40 | info['payment_possible'] = False
|
---|
41 | info['amount'] = '0'
|
---|
42 | info['bank'] = ''
|
---|
43 | info['type_description'] = ''
|
---|
44 | info['pay_bill_to'] = ''
|
---|
45 | fee_dict = context.getSchoolFee(student_record)
|
---|
46 | #fulltime = student_record.mode.endswith('_ft')
|
---|
47 | new = student_record.review_state == 'cleared_and_validated'
|
---|
48 | returning = student_record.review_state == 'returning'
|
---|
49 | if not fee_dict or not (new or returning):
|
---|
50 | return context.etranzact_form(info=info)
|
---|
51 | if new:
|
---|
52 | amount = info['amount'] = fee_dict['new']
|
---|
53 | elif returning:
|
---|
54 | amount = info['amount'] = fee_dict['returning']
|
---|
55 |
|
---|
56 | if new and int(student_record.session) < 11:
|
---|
57 | amount_int = int(amount)
|
---|
58 | amount_int += 5000
|
---|
59 | amount = info['amount'] = '%d' % (amount_int)
|
---|
60 | if returning and int(student_record.session) < 10:
|
---|
61 | amount_int = int(amount)
|
---|
62 | amount_int += 5000
|
---|
63 | amount = info['amount'] = '%d' % (amount_int)
|
---|
64 |
|
---|
65 | info['surcharge'] = '0' # Uniben doesn't show the surcharge on the slip
|
---|
66 | info['payment_possible'] = True
|
---|
67 | info['type_description'] = fee_dict['description']
|
---|
68 | info['pay_bill_to'] = student_record.name
|
---|
69 | info['pay_ship_to'] = "University of Benin"
|
---|
70 | info['student_id'] = student_id
|
---|
71 | info['student_name'] = student_record.name
|
---|
72 | info['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 !!!!!!
|
---|
74 | info['session_id'] = fee_dict['next_session_id']
|
---|
75 | info['type'] = 'etranzact'
|
---|
76 | info['status'] = 'started'
|
---|
77 | info['item'] = student_record.course
|
---|
78 | info['category'] = 'schoolfee'
|
---|
79 | now = DateTime.DateTime()
|
---|
80 | info['date'] = now
|
---|
81 | timestamp = "%d" % int(now.timeTime()*1000)
|
---|
82 | info['order_id'] = "%s%s" % (student_id[1:],timestamp)
|
---|
83 | p_id = "p%s" % timestamp
|
---|
84 |
|
---|
85 | if student_id is None:
|
---|
86 | return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
|
---|
87 |
|
---|
88 | if "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')
|
---|
95 | else:
|
---|
96 | payments = getattr(student,'payments')
|
---|
97 | if request.has_key('epayment'):
|
---|
98 | return context.etranzact_form(info=info)
|
---|
99 |
|
---|
100 | payments.invokeFactory('Payment', p_id)
|
---|
101 | payment = getattr(payments,p_id)
|
---|
102 | wftool.doActionFor(payment,'open')
|
---|
103 | d = {}
|
---|
104 | d.update(info)
|
---|
105 | payment.getContent().edit(mapping=d)
|
---|
106 | logger.info('%(student_id)s initiated eTranzact school fee payment with order_id %(order_id)s' % info)
|
---|
107 |
|
---|
108 | return context.payments_view() |
---|