1 | ## Script (Python) "check_transactions" |
---|
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: check_transactions.py 1871 2007-06-08 18:57:59Z henrik $ |
---|
11 | """ |
---|
12 | payment callback |
---|
13 | """ |
---|
14 | import logging |
---|
15 | logger = logging.getLogger('Skins.check_transactions') |
---|
16 | from AccessControl import Unauthorized |
---|
17 | import DateTime |
---|
18 | if context.portal_membership.isAnonymousUser(): |
---|
19 | return None |
---|
20 | |
---|
21 | request = context.REQUEST |
---|
22 | response = request.RESPONSE |
---|
23 | students = context.portal_url.getPortalObject().campus.students |
---|
24 | wftool = context.portal_workflow |
---|
25 | mtool = context.portal_membership |
---|
26 | member = mtool.getAuthenticatedMember() |
---|
27 | member_id = str(member) |
---|
28 | student_id = context.getStudentId() |
---|
29 | online_transactions = context.online_payments_import |
---|
30 | def rwrite(s): |
---|
31 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
32 | response.write("%s<br>\n" % s) |
---|
33 | correct = 0 |
---|
34 | count = 0 |
---|
35 | approved = 0 |
---|
36 | for ot_brain in online_transactions(): |
---|
37 | student_id = ot_brain.student_id |
---|
38 | if not students.hasObject(student_id): |
---|
39 | rwrite("%s not found" % student_id) |
---|
40 | continue |
---|
41 | student_obj = getattr(students,student_id) |
---|
42 | if not student_obj.hasObject('payments'): |
---|
43 | rwrite("%s payments-folder not found" % student_id) |
---|
44 | continue |
---|
45 | payments_folder = getattr(student_obj,'payments') |
---|
46 | payment_id = "p%s" % ot_brain.order_id[6:] |
---|
47 | if not payments_folder.hasObject(payment_id): |
---|
48 | rwrite("%s payment %s not found" % (student_id,payment_id)) |
---|
49 | continue |
---|
50 | payment_obj = getattr(payments_folder,payment_id) |
---|
51 | payment_doc = payment_obj.getContent() |
---|
52 | response_code = ot_brain.response_code |
---|
53 | count +=1 |
---|
54 | if payment_doc.resp_code != response_code: |
---|
55 | rwrite('"%d","%d","%s","%s","%s","%s"' % ( |
---|
56 | count,correct, |
---|
57 | student_id, |
---|
58 | payment_id, |
---|
59 | response_code, |
---|
60 | payment_doc.resp_code |
---|
61 | )) |
---|
62 | elif payment_doc.resp_code == response_code: |
---|
63 | correct +=1 |
---|
64 | rwrite('"%d","%d","%s","%s","%s","%s"' % ( |
---|
65 | count,correct, |
---|
66 | student_id, |
---|
67 | payment_id, |
---|
68 | response_code, |
---|
69 | payment_doc.resp_code |
---|
70 | )) |
---|
71 | if payment_doc.resp_code == "" and response_code == "00": |
---|
72 | pd = {} |
---|
73 | review_state = wftool.getInfoFor(payment_obj,'review_state',None) |
---|
74 | if review_state != "opened": |
---|
75 | logger.info('payment object of %s closed' % (student_id)) |
---|
76 | continue |
---|
77 | review_state = context.getStudentReviewState() |
---|
78 | if review_state != "cleared_and_validated": |
---|
79 | logger.info('%s review_state = %s' % (student_id,review_state)) |
---|
80 | continue |
---|
81 | pd['resp_code'] = 'IP' |
---|
82 | pd['resp_desc'] = 'Payment approved by import, %s' % (DateTime.DateTime()) |
---|
83 | payment_doc.edit(mapping=pd) |
---|
84 | if payment_doc.type_description.startswith('School Fee'): |
---|
85 | wftool.doActionFor(student_obj,'pay_school_fee') |
---|
86 | logger.info('%s approves epayment for %s by import' % (member,student_id)) |
---|
87 | wftool.doActionFor(payment_obj,'close') |
---|
88 | approved += 1 |
---|
89 | if approved > 50: |
---|
90 | context.waeup_tool.doCommit() |
---|
91 | logger.info('%s transactions commited' % (approved)) |
---|
92 | approved = 0 |
---|