Changeset 8430 for main


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.

Location:
main/waeup.uniben/trunk/src/waeup/uniben
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.uniben/trunk/src/waeup/uniben/applicants/interfaces.py

    r8378 r8430  
    269269
    270270    """
     271
     272    def doAfterApplicantPayment():
     273        """Process applicant after payment was made.
     274
     275        """
     276
     277    def approveApplicantPayment():
     278        """Approve payment and process applicant.
     279
     280        """
  • main/waeup.uniben/trunk/src/waeup/uniben/applicants/utils.py

    r8247 r8430  
    2525from waeup.uniben.interfaces import MessageFactory as _
    2626
    27 
    28 def actions_after_applicant_payment(applicant, view):
    29     wf_info = IWorkflowInfo(applicant)
    30     try:
    31         wf_info.fireTransition('pay')
    32     except InvalidTransitionError:
    33         view.flash('Error: %s' % sys.exc_info()[1])
    34         return
    3527
    3628class ApplicantsUtils(ApplicantsUtils):
  • 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
  • main/waeup.uniben/trunk/src/waeup/uniben/etranzact/tests.py

    r8271 r8430  
    109109        configuration.application_fee = 1000.0
    110110        self.app['configuration'].addSessionConfiguration(configuration)
     111        self.browser.open(self.manage_path)
    111112        self.browser.getControl("Add online").click()
    112113        self.assertMatches('...ticket created...',
    113114                           self.browser.contents)
    114         ctrl = self.browser.getControl(name='val_id')
    115         value = ctrl.options[0]
    116         self.browser.getLink(value).click()
    117115        self.assertMatches('...Amount Authorized...',
    118116                           self.browser.contents)
  • 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
  • main/waeup.uniben/trunk/src/waeup/uniben/payments/interfaces.py

    r8263 r8430  
    4040        )
    4141
     42    r_code = schema.TextLine(
     43        title = _(u'Response Code'),
     44        default = None,
     45        required = False,
     46        readonly = False,
     47        )
     48
    4249    r_desc = schema.TextLine(
    4350        title = _(u'Response Description'),
     
    4754        )
    4855
     56    # Only defined in custom package
     57
    4958    r_pay_reference = schema.TextLine(
    5059        title = _(u'Response Payment Reference'),
    51         default = None,
    52         required = False,
    53         readonly = False,
    54         )
    55 
    56     r_code = schema.TextLine(
    57         title = _(u'Response Code'),
    5860        default = None,
    5961        required = False,
  • main/waeup.uniben/trunk/src/waeup/uniben/students/interfaces.py

    r8416 r8430  
    372372        readonly = True,
    373373        )
     374
     375    def doAfterStudentPayment():
     376        """Process student after payment was made.
     377
     378        """
     379
     380    def approveStudentPayment():
     381        """Approve payment and process student.
     382
     383        """
     384
    374385ICustomStudentOnlinePayment['p_level'].order = ICustomStudentOnlinePayment[
    375386    'p_session'].order
  • main/waeup.uniben/trunk/src/waeup/uniben/students/utils.py

    r8421 r8430  
    3333        return fee
    3434    return 0.0
    35 
    36 def actions_after_student_payment(student, payment, view):
    37     if payment.p_category == 'clearance':
    38         # Create CLR access code
    39         pin, error = create_accesscode('CLR',0,student.student_id)
    40         if error:
    41             view.flash(_('Valid callback received. ${a}',
    42                 mapping = {'a':error}))
    43             return
    44         payment.ac = pin
    45     elif payment.p_category == 'schoolfee':
    46         # Create SFE access code
    47         pin, error = create_accesscode('SFE',0,student.student_id)
    48         if error:
    49             view.flash(_('Valid callback received. ${a}',
    50                 mapping = {'a':error}))
    51             return
    52         payment.ac = pin
    53     elif payment.p_category == 'bed_allocation':
    54         # Create HOS access code
    55         pin, error = create_accesscode('HOS',0,student.student_id)
    56         if error:
    57             view.flash(_('Valid callback received. ${a}',
    58                 mapping = {'a':error}))
    59             return
    60         payment.ac = pin
    61     view.flash(_('Valid callback received.'))
    62     return
    6335
    6436class CustomStudentsUtils(StudentsUtils):
Note: See TracChangeset for help on using the changeset viewer.