Ignore:
Timestamp:
31 Mar 2007, 15:32:16 (18 years ago)
Author:
joachim
Message:

working version please check

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/skins/waeup_utilities/readOnlinePaymentsFromLog.py

    r1666 r1667  
    1010# $Id$
    1111"""
    12 list Students for ClearanceOfficers
     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
    1320"""
     21import logging
     22logger = logging.getLogger('Skins.readOnlinePaymentsFromLog')
    1423
    1524request = context.REQUEST
     
    1726response = request.RESPONSE
    1827setheader = request.RESPONSE.setHeader
     28import DateTime
    1929
    2030def rwrite(s):
     
    3242aq_students = context.students_catalog.evalAdvancedQuery
    3343students_folder = context.portal_url.getPortalObject().campus.students
    34 tas = context.waeup_tool.getCallbacksFromLog('epaymentsuccessful_z2log2')
     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')
    3554for ta in tas:
     55    count += 1
    3656    student_id = ta['student_id']
    3757    payment_id = ta['payment_id']
    3858    qs_dict = ta['qs_dict']
    39     rwrite(qs_dict)
    4059    if not students_folder.hasObject(student_id):
    4160        rwrite("no student %s" % student_id)
     
    5069        continue
    5170    payment_obj = getattr(payments,payment_id)
    52     review_state = wftool.getInfoFor(student_obj,'review_state',None)
    53     #from pdb import set_trace
    54     if review_state == 'schoolfee_paid':
    55         rwrite("student %s has already state %s" % (student_id,review_state))
    56         continue
    57     review_state = wftool.getInfoFor(payment_obj,'review_state',None)
    58     #from pdb import set_trace
    59     if review_state != 'open':
    60         rwrite("payment %s for student %s has state %s" % (payment_id,student_id,review_state))
    61         continue
    62     resp_codes = (("x_RespDesc","resp_desc"),
    63       ("x_RespPayRef","resp_pay_reference"),
    64       ("x_RespCode","resp_code"),
    65       ("x_CardNum","resp_card_num"),
    66       ("x_ApprAmt","resp_approved_amount"),
    67       )
    68     pd = {}
     71    payment_doc = payment_obj.getContent()
     72    pdoc = {}
     73    for rc,key in resp_codes:
     74        pdoc[key] = getattr(payment_doc,key)
     75    readin = {}
    6976    for rc,pdk in resp_codes:
    70         pd[pdk] = request.get(rc)
    71     rwrite(pd)
    72     #payment_obj.getContent().edit(mapping=pd)
    73     continue
     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 TracChangeset for help on using the changeset viewer.