source: WAeUP_SRP/branches/joachim-event-branch/skins/waeup_epayment/check_transactions.py @ 11086

Last change on this file since 11086 was 1669, checked in by joachim, 18 years ago

merged up to 1664

  • Property svn:keywords set to Id
File size: 3.6 KB
RevLine 
[1620]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 1669 2007-04-04 06:31:52Z joachim $
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)
28student_id = context.getStudentId()
[1625]29online_transactions = context.online_payments_import
[1620]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
[1624]35approved = 0
[1620]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
[1624]50    payment_obj = getattr(payments_folder,payment_id)
51    payment_doc = payment_obj.getContent()
[1620]52    response_code = ot_brain.response_code
53    count +=1
54    if payment_doc.resp_code != response_code:
[1622]55        rwrite('"%d","%d","%s","%s","%s","%s"' % (
[1624]56                                                  count,correct,
57                                                  student_id,
58                                                  payment_id,
59                                                  response_code,
60                                                  payment_doc.resp_code
61                                                  ))
[1620]62    elif payment_doc.resp_code == response_code:
63        correct +=1
[1622]64        rwrite('"%d","%d","%s","%s","%s","%s"' % (
[1624]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 = wftool.getInfoFor(student_obj,'review_state',None)
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
Note: See TracBrowser for help on using the repository browser.