[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 1653 2007-03-28 02:35:25Z uli $ |
---|
| 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() |
---|
[1625] | 29 | online_transactions = context.online_payments_import |
---|
[1620] | 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 |
---|
[1624] | 35 | approved = 0 |
---|
[1620] | 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 |
---|
[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 |
---|