source: WAeUP_SRP/trunk/skins/waeup_epayment/check_transactions.py @ 8315

Last change on this file since 8315 was 1950, checked in by Henrik Bettermann, 18 years ago

check_transactions.py fixed

payments_view.pt adapted to the needs of IE

  • Property svn:keywords set to Id
File size: 4.2 KB
Line 
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 1950 2007-06-23 06:23:51Z henrik $
11"""
12payment callback
13"""
14import logging
15logger = logging.getLogger('Skins.check_transactions')
16from AccessControl import Unauthorized
17import DateTime
18if context.portal_membership.isAnonymousUser():
19    return None
20
21request = context.REQUEST
22response = request.RESPONSE
23students = context.portal_url.getPortalObject().campus.students
24wftool = context.portal_workflow
25mtool = context.portal_membership
26member = mtool.getAuthenticatedMember()
27member_id = str(member)
28#student_id = context.getStudentId()
29online_transactions = context.online_payments_import
30def rwrite(s):
31    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
32    response.write("%s<br>\n" % s)
33correct = 0
34count = 0
35approved = 0
36for 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    if response_code == "00":
73        pd = {}
74        review_state = context.getStudentReviewState(student_id)
75        if review_state != "cleared_and_validated":
76            #logger.info('%s review_state = %s' % (student_id,review_state))
77            continue
78        review_state = wftool.getInfoFor(payment_obj,'review_state',None)
79        if payment_doc.resp_code == "":
80            if review_state != "opened":
81                logger.info("Payment object of %s is closed and won't be reopend" % (student_id))
82                continue
83            logger.info('%s approves epayment for %s by import' % (member,student_id))
84        else:
85            if review_state == "closed":
86                logger.info('%s approves epayment for %s by import, old resp_code: %s' % (member,student_id,payment_doc.resp_code))
87                wftool.doActionFor(payment_obj,'open')
88            # cannot happen but anyway ...
89            else:
90                logger.info('%s approves epayment for %s by import. Payment object was opened, old resp_code: %s' % (member,student_id,payment_doc.resp_code))
91        pd['resp_code'] = 'IP'
92        pd['resp_desc'] = 'Payment approved by import, %s' % (DateTime.DateTime())
93        payment_doc.edit(mapping=pd)
94        if payment_doc.type_description.startswith('School Fee'):
95            wftool.doActionFor(student_obj,'pay_school_fee')
96        wftool.doActionFor(payment_obj,'close')
97        approved += 1
98        if approved > 50:
99            context.waeup_tool.doCommit()
100            logger.info('%s transactions commited' % (approved))
101            approved = 0
Note: See TracBrowser for help on using the repository browser.