source: WAeUP_SRP/branches/joachim-event-branch/skins/waeup_utilities/readOnlinePaymentsFromLog.py @ 15284

Last change on this file since 15284 was 1673, checked in by joachim, 18 years ago

merge up to 1672

  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1## Script (Python) "search_pins"
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: readOnlinePaymentsFromLog.py 1673 2007-04-09 16:01:51Z joachim $
11"""
12read the successfull epayments from an extract of Z2.log
13this extract must be created with
14
15cat /zope/instances/uniben1/log/Z2.log.1 | grep epayment_cb | grep RespCode=00
16> /zope/instances/uniben1/import/successfullepaymentsDDMMYY.log
17
18in /zope/instances/uniben1/import/ are already all files from 25.3.07
19
20"""
21import logging
22logger = logging.getLogger('Skins.readOnlinePaymentsFromLog')
23
24request = context.REQUEST
25session = request.SESSION
26response = request.RESPONSE
27setheader = request.RESPONSE.setHeader
28import DateTime
29
30def rwrite(s):
31    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
32    response.write('%s<br>\r\n' % s)
33
34wftool = context.portal_workflow
35mtool = context.portal_membership
36member = mtool.getAuthenticatedMember()
37roles = member.getRolesInContext(context)
38retcat = context.returning_import
39rcat = context.results_import
40scat = context.students_catalog
41from Products.AdvancedQuery import Eq, Between, Le,In
42aq_students = context.students_catalog.evalAdvancedQuery
43students_folder = context.portal_url.getPortalObject().campus.students
44resp_codes = (("x_RespDesc","resp_desc"),
45      ("x_RespPayRef","resp_pay_reference"),
46      ("x_RespCode","resp_code"),
47      ("x_CardNum","resp_card_num"),
48      ("x_ApprAmt","resp_approved_amount"),
49      )
50count = 0
51correct = 0
52approved = 0
53tas = context.waeup_tool.getCallbacksFromLog('successfullepayments260307.log')
54for ta in tas:
55    count += 1
56    student_id = ta['student_id']
57    payment_id = ta['payment_id']
58    qs_dict = ta['qs_dict']
59    if not students_folder.hasObject(student_id):
60        rwrite("no student %s" % student_id)
61        continue
62    student_obj = getattr(students_folder,student_id)
63    if not student_obj.hasObject('payments'):
64        rwrite("no payments for student %s" % student_id)
65        continue
66    payments = getattr(student_obj,'payments')
67    if not payments.hasObject(payment_id):
68        rwrite("no payment %s for student %s" % (payment_id,student_id))
69        continue
70    payment_obj = getattr(payments,payment_id)
71    payment_doc = payment_obj.getContent()
72    pdoc = {}
73    for rc,key in resp_codes:
74        pdoc[key] = getattr(payment_doc,key)
75    readin = {}
76    for rc,pdk in resp_codes:
77        readin[pdk] = qs_dict.get(rc)[0]
78    response_code = readin['resp_code']
79    if payment_doc.resp_code != response_code:
80        rwrite('"%d","%d","%s","%s","%s","%s"' % (
81                                                  count,correct,
82                                                  student_id,
83                                                  payment_id,
84                                                  response_code,
85                                                  payment_doc.resp_code
86                                                  ))
87    elif payment_doc.resp_code == response_code:
88        correct +=1
89        rwrite('"%d","%d","%s","%s","%s","%s"' % (
90                                                  count,correct,
91                                                  student_id,
92                                                  payment_id,
93                                                  response_code,
94                                                  payment_doc.resp_code
95                                                  ))
96    if payment_doc.resp_code == "" and response_code == "00":
97        pd = {}
98        review_state = wftool.getInfoFor(payment_obj,'review_state',None)
99        if review_state != "opened":
100            logger.info('payment object of %s closed' % (student_id))
101            continue
102        review_state = wftool.getInfoFor(student_obj,'review_state',None)
103        if review_state != "cleared_and_validated":
104            logger.info('%s review_state = %s' % (student_id,review_state))
105            continue
106        pd['resp_code'] = 'IP'
107        pd['resp_desc'] = 'Payment approved by import, %s' % (DateTime.DateTime())
108        payment_doc.edit(mapping=pd)
109        if payment_doc.type_description.startswith('School Fee'):
110            wftool.doActionFor(student_obj,'pay_school_fee')
111        logger.info('%s approves epayment for %s by import' % (member,student_id))
112        wftool.doActionFor(payment_obj,'close')
113        approved += 1
114        if approved > 50:
115            context.waeup_tool.doCommit()
116            logger.info('%s transactions commited' % (approved))
117            approved = 0
Note: See TracBrowser for help on using the repository browser.