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/interswitch/browser.py

    r8424 r8430  
    3232from waeup.uniben.students.interfaces import ICustomStudentOnlinePayment
    3333from waeup.uniben.applicants.interfaces import ICustomApplicantOnlinePayment
    34 from waeup.uniben.students.utils import actions_after_student_payment
    35 from waeup.uniben.applicants.utils import actions_after_applicant_payment
    3634from waeup.uniben.interfaces import MessageFactory as _
    3735
     
    9189    return response
    9290
    93 def query_interswitch(user, payment, view):
    94     ob_class = view.__implemented__.__name__
     91def query_interswitch(payment):
    9592    sr = get_SOAP_response(PRODUCT_ID, payment.p_id)
    96     user.loggerInfo(ob_class, 'callback received: %s' % sr)
    9793    wlist = sr.split(':')
    9894    if len(wlist) != 7:
    99         view.flash(_('Invalid callback: ${a}',
    100             mapping = {'a': wlist}))
    101         user.loggerInfo(ob_class,'invalid callback: %s' % payment.p_id)
    102         return False
     95        msg = _('Invalid callback: ${a}', mapping = {'a': sr})
     96        log = 'invalid callback for payment %s: %s' % (payment.p_id, sr)
     97        return False, msg, log
    10398    payment.r_code = wlist[0]
    10499    payment.r_desc = wlist[1]
     
    107102    payment.r_pay_reference = wlist[5]
    108103    if payment.r_code != '00':
    109         view.flash(_('Unsuccessful callback: ${a}', mapping = {'a': wlist[1]}))
    110         user.loggerInfo(ob_class,'unsuccessful callback: %s' % payment.p_id)
     104        msg = _('Unsuccessful callback: ${a}', mapping = {'a': sr})
     105        log = 'usuccessful callback for payment %s: %s' % (payment.p_id, sr)
    111106        payment.p_state = 'failed'
    112         return False
     107        return False, msg, log
    113108    if payment.r_amount_approved != payment.amount_auth:
    114         view.flash(_('Wrong amount'))
    115         user.loggerInfo(ob_class,'successful callback but wrong amount: %s'
    116             % payment.p_id)
     109        msg = _('Callback amount does not match.')
     110        log = 'wrong callback for payment %s: %s' % (payment.p_id, sr)
    117111        payment.p_state = 'failed'
    118         return False
     112        return False, msg, log
    119113    if wlist[4] != payment.p_id:
    120         view.flash(_('Wrong transaction id'))
    121         user.loggerInfo(ob_class,'successful callback but wrong transaction id: %s'
    122             % payment.p_id)
     114        msg = _('Callback transaction id does not match.')
     115        log = 'wrong callback for payment %s: %s' % (payment.p_id, sr)
    123116        payment.p_state = 'failed'
    124         return False
    125     user.loggerInfo(ob_class,'successful callback: %s' % payment.p_id)
     117        return False, msg, log
    126118    payment.p_state = 'paid'
    127119    payment.payment_date = datetime.now()
    128     return True
     120    msg = _('Successful callback received')
     121    log = 'valid callback for payment %s: %s' % (payment.p_id, sr)
     122    return True, msg, log
    129123
    130124class InterswitchActionButtonStudent(APABStudent):
    131125    grok.order(1)
    132126    grok.context(ICustomStudentOnlinePayment)
     127    grok.require('waeup.payStudent')
    133128    icon = 'actionicon_pay.png'
    134129    text = _('CollegePAY')
     
    144139    grok.order(1)
    145140    grok.context(ICustomApplicantOnlinePayment)
     141    grok.require('waeup.payApplicant')
    146142    icon = 'actionicon_pay.png'
    147143    text = _('CollegePAY')
     
    175171    grok.order(2)
    176172    grok.context(ICustomStudentOnlinePayment)
     173    grok.require('waeup.payStudent')
    177174    icon = 'actionicon_call.png'
    178175    text = _('Requery CollegePAY')
     
    182179    grok.order(2)
    183180    grok.context(ICustomApplicantOnlinePayment)
     181    grok.require('waeup.payApplicant')
    184182    icon = 'actionicon_call.png'
    185183    text = _('Requery CollegePAY')
     
    404402
    405403    def update(self):
     404        ob_class = self.__implemented__.__name__
    406405        if self.context.p_state == 'paid':
    407406            self.flash(_('This ticket has already been paid.'))
    408407            return
    409408        student = self.context.getStudent()
    410         if query_interswitch(student, self.context, self):
    411             actions_after_student_payment(student, self.context, self)
     409        success, msg, log = query_interswitch(self.context)
     410        student.loggerInfo(ob_class, log)
     411        if not success:
     412            self.flash(msg)
     413            return
     414        success, msg, log = self.context.doAfterStudentPayment()
     415        if log is not None:
     416            student.loggerInfo(ob_class, log)
     417        self.flash(msg)
    412418        return
    413419
     
    424430
    425431    def update(self):
     432        ob_class = self.__implemented__.__name__
    426433        if self.context.p_state == 'paid':
    427434            self.flash(_('This ticket has already been paid.'))
    428435            return
    429436        applicant = self.context.__parent__
    430         if query_interswitch(applicant, self.context, self):
    431             actions_after_applicant_payment(applicant, self)
     437        success, msg, log = query_interswitch(self.context)
     438        applicant.loggerInfo(ob_class, log)
     439        if not success:
     440            self.flash(msg)
     441            return
     442        success, msg, log = self.context.doAfterApplicantPayment()
     443        if log is not None:
     444            applicant.loggerInfo(ob_class, log)
     445        self.flash(msg)
    432446        return
    433447
Note: See TracChangeset for help on using the changeset viewer.