[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 1950 2007-06-23 06:23:51Z 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) |
---|
[1943] | 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 | )) |
---|
[1947] | 71 | #if payment_doc.resp_code == "" and response_code == "00": |
---|
| 72 | if response_code == "00": |
---|
[1624] | 73 | pd = {} |
---|
[1949] | 74 | review_state = context.getStudentReviewState(student_id) |
---|
| 75 | if review_state != "cleared_and_validated": |
---|
[1950] | 76 | #logger.info('%s review_state = %s' % (student_id,review_state)) |
---|
| 77 | continue |
---|
[1624] | 78 | review_state = wftool.getInfoFor(payment_obj,'review_state',None) |
---|
[1947] | 79 | if payment_doc.resp_code == "": |
---|
| 80 | if review_state != "opened": |
---|
[1949] | 81 | logger.info("Payment object of %s is closed and won't be reopend" % (student_id)) |
---|
[1947] | 82 | continue |
---|
[1950] | 83 | logger.info('%s approves epayment for %s by import' % (member,student_id)) |
---|
[1947] | 84 | else: |
---|
| 85 | if review_state == "closed": |
---|
[1950] | 86 | logger.info('%s approves epayment for %s by import, old resp_code: %s' % (member,student_id,payment_doc.resp_code)) |
---|
[1947] | 87 | wftool.doActionFor(payment_obj,'open') |
---|
[1950] | 88 | # cannot happen but anyway ... |
---|
[1949] | 89 | else: |
---|
[1950] | 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)) |
---|
[1624] | 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 |
---|