Ignore:
Timestamp:
12 May 2012, 08:43:51 (13 years ago)
Author:
Henrik Bettermann
Message:

Make waeup.uniben in line with base package. Fortunately we can now use the payment methods used in the base package and do no longer need the actions_after functions in w.u.students.utils and w.u.applicants.utils.

Interswitch and etranzact modules have not been tested with live gateways. The query functions and approval methods may fail.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.uniben/trunk/src/waeup/uniben/etranzact/browser.py

    r8267 r8430  
    2222import grok
    2323from waeup.kofa.browser.layout import KofaPage, UtilityView
    24 from waeup.kofa.applicants.viewlets import RequestCallbackActionButton as RCABApplicant
    25 from waeup.kofa.students.viewlets import RequestCallbackActionButton as RCABStudent
     24from waeup.kofa.students.viewlets import ApprovePaymentActionButton as APABStudent
     25from waeup.kofa.applicants.viewlets import ApprovePaymentActionButton as APABApplicant
    2626from waeup.uniben.interfaces import MessageFactory as _
    27 from waeup.uniben.students.utils import actions_after_student_payment
    28 from waeup.uniben.applicants.utils import actions_after_applicant_payment
    2927from waeup.uniben.students.interfaces import ICustomStudentOnlinePayment
    3028from waeup.uniben.applicants.interfaces import ICustomApplicantOnlinePayment
     
    3533QUERY_URL =   'http://demo.etranzact.com:8080/WebConnect/queryPayoutletTransaction.jsp'
    3634
    37 def query_etranzact(confirmation_number, user, payment, view):
    38     ob_class = view.__implemented__.__name__
     35def query_etranzact(confirmation_number, payment):
     36   
    3937    postdict = {}
    4038    postdict['TERMINAL_ID'] = TERMINAL_ID
     
    4543        f = urllib.urlopen(url=QUERY_URL, data=data)
    4644        success = f.read()
    47         user.loggerInfo(ob_class, 'callback received: %s' % success)
    4845        if 'COL1' not in success:
    49             view.flash(_('Invalid or unsuccessful callback: ${a}',
    50                 mapping = {'a': success}))
    51             user.loggerInfo(ob_class, 'invalid callback: %s' % payment.p_id)
     46            msg = _('Invalid or unsuccessful callback: ${a}',
     47                mapping = {'a': success})
     48            log = 'invalid callback for payment %s: %s' % (payment.p_id, success)
    5249            payment.p_state = 'failed'
    53             return False
     50            return False, msg, log
    5451        success = success.replace('%20',' ').split('&')
    5552        # We expect at least two parameters
    5653        if len(success) < 2:
    57             view.flash(_('Invalid callback: ${a}',
    58                 mapping = {'a': success}))
    59             user.loggerInfo(ob_class, 'invalid callback: %s' % payment.p_id)
     54            msg = _('Invalid callback: ${a}', mapping = {'a': success})
     55            log = 'invalid callback for payment %s: %s' % (payment.p_id, success)
    6056            payment.p_state = 'failed'
    61             return False
     57            return False, msg, log
    6258        try:
    6359            success_dict = dict([tuple(i.split('=')) for i in success])
    6460        except ValueError:
    65             view.flash(_('Invalid callback: ${a}',
    66                 mapping = {'a': success}))
    67             user.loggerInfo(ob_class, 'invalid callback: %s' % payment.p_id)
     61            msg = _('Invalid callback: ${a}', mapping = {'a': success})
     62            log = 'invalid callback for payment %s: %s' % (payment.p_id, success)
    6863            payment.p_state = 'failed'
    69             return False
     64            return False, msg, log
    7065    except IOError:
    71         view.flash(_('eTranzact IOError'))
    72         return False
     66        msg = _('eTranzact IOError')
     67        log = 'eTranzact IOError'
     68        return False, msg, log
    7369    payment.r_code = u'ET'
    7470    payment.r_desc = u'%s' % success_dict.get('TRANS_DESCR')
     
    7773    payment.r_pay_reference = u'%s' % success_dict.get('RECEIPT_NO')
    7874    if payment.r_amount_approved != payment.amount_auth:
    79         view.flash(_('Wrong amount'))
    80         user.loggerInfo(ob_class, 'successful callback but wrong amount: %s'
    81             % payment.p_id)
     75        msg = _('Wrong amount')
     76        log = 'wrong callback for payment %s: %s' % (payment.p_id, success)
    8277        payment.p_state = 'failed'
    83         return False
     78        return False, msg, log
    8479    tcode = payment.p_id
    8580    tcode = tcode[len(tcode)-8:len(tcode)]
     
    8782    col1 = col1[len(col1)-8:len(col1)]
    8883    if tcode != col1:
    89         view.flash(_('Wrong transaction code'))
    90         write_log_message(
    91             view,'successful callback but wrong transaction code: %s'
    92             % payment.p_id)
    93         user.loggerInfo(ob_class, 'successful callback wrong transaction code: %s'
    94             % payment.p_id)
     84        msg = _('Wrong transaction code')
     85        log = 'wrong callback for payment %s: %s' % (payment.p_id, success)
    9586        payment.p_state = 'failed'
    96         return False
    97     user.loggerInfo(ob_class, 'successful callback: %s' % payment.p_id)
     87        return False, msg, log
     88    log = 'valid callback for payment %s: %s' % (payment.p_id, success)
     89    msg = _('Successful callback received')
    9890    payment.p_state = 'paid'
    9991    payment.payment_date = datetime.now()
    100     return True
     92    return True, msg, log
    10193
    102 class EtranzactEnterPinActionButtonApplicant(RCABApplicant):
     94class EtranzactEnterPinActionButtonApplicant(APABApplicant):
    10395    grok.context(ICustomApplicantOnlinePayment)
     96    grok.require('waeup.payApplicant')
    10497    grok.order(3)
    10598    icon = 'actionicon_call.png'
     
    107100    target = 'enterpin'
    108101
    109 class EtranzactEnterPinActionButtonStudent(RCABStudent):
     102class EtranzactEnterPinActionButtonStudent(APABStudent):
    110103    grok.context(ICustomStudentOnlinePayment)
     104    grok.require('waeup.payStudent')
    111105    grok.order(3)
    112106    icon = 'actionicon_call.png'
     
    140134
    141135    def update(self, confirmation_number=None):
     136        ob_class = self.__implemented__.__name__
    142137        if self.context.p_state == 'paid':
    143138            self.flash(_('This ticket has already been paid.'))
    144139            return
    145140        student = self.context.getStudent()
    146         if query_etranzact(confirmation_number, student, self.context, self):
    147             actions_after_student_payment(student, self.context, self)
     141        success, msg, log = query_etranzact(confirmation_number,self.context)
     142        student.loggerInfo(ob_class, log)
     143        if not success:
     144            self.flash(msg)
     145            return
     146        success, msg, log = self.context.doAfterStudentPayment()
     147        if log is not None:
     148            student.loggerInfo(ob_class, log)
     149        self.flash(msg)
    148150        return
    149151
     
    160162
    161163    def update(self, confirmation_number=None):
     164        ob_class = self.__implemented__.__name__
    162165        if self.context.p_state == 'paid':
    163166            self.flash(_('This ticket has already been paid.'))
    164167            return
    165168        applicant = self.context.__parent__
    166         if query_etranzact(confirmation_number, applicant, self.context, self):
    167             actions_after_applicant_payment(applicant, self)
     169        success, msg, log = query_etranzact(confirmation_number,self.context)
     170        applicant.loggerInfo(ob_class, log)
     171        if not success:
     172            self.flash(msg)
     173            return
     174        success, msg, log = self.context.doAfterApplicantPayment()
     175        if log is not None:
     176            applicant.loggerInfo(ob_class, log)
     177        self.flash(msg)
    168178        return
    169179
Note: See TracChangeset for help on using the changeset viewer.