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 | """ |
---|
12 | read the successfull epayments from an extract of Z2.log |
---|
13 | this extract must be created with |
---|
14 | |
---|
15 | cat /zope/instances/uniben1/log/Z2.log.1 | grep epayment_cb | grep RespCode=00 |
---|
16 | > /zope/instances/uniben1/import/successfullepaymentsDDMMYY.log |
---|
17 | |
---|
18 | in /zope/instances/uniben1/import/ are already all files from 25.3.07 |
---|
19 | |
---|
20 | """ |
---|
21 | import logging |
---|
22 | logger = logging.getLogger('Skins.readOnlinePaymentsFromLog') |
---|
23 | |
---|
24 | request = context.REQUEST |
---|
25 | session = request.SESSION |
---|
26 | response = request.RESPONSE |
---|
27 | setheader = request.RESPONSE.setHeader |
---|
28 | import DateTime |
---|
29 | |
---|
30 | def rwrite(s): |
---|
31 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
32 | response.write('%s<br>\r\n' % s) |
---|
33 | |
---|
34 | wftool = context.portal_workflow |
---|
35 | mtool = context.portal_membership |
---|
36 | member = mtool.getAuthenticatedMember() |
---|
37 | roles = member.getRolesInContext(context) |
---|
38 | retcat = context.returning_import |
---|
39 | rcat = context.results_import |
---|
40 | scat = context.students_catalog |
---|
41 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
42 | aq_students = context.students_catalog.evalAdvancedQuery |
---|
43 | students_folder = context.portal_url.getPortalObject().campus.students |
---|
44 | resp_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 | ) |
---|
50 | count = 0 |
---|
51 | correct = 0 |
---|
52 | approved = 0 |
---|
53 | tas = context.waeup_tool.getCallbacksFromLog('successfullepayments260307.log') |
---|
54 | for 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 |
---|