Ignore:
Timestamp:
6 Dec 2012, 08:42:16 (12 years ago)
Author:
Henrik Bettermann
Message:

Store provider_amt and gateway_amt when opening goto_interswitch pages.

Both fileds must be invisible on display pages and pdf slips.

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

Legend:

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

    r9749 r9775  
    1919import grok
    2020from zope.component import getUtility
    21 from kofacustom.nigeria.interswitch.helpers import query_interswitch
     21from kofacustom.nigeria.interswitch.helpers import (
     22    query_interswitch, write_payments_log)
    2223from waeup.kofa.browser.layout import KofaPage, UtilityView
    2324from waeup.kofa.interfaces import IKofaUtils
     
    3637INSTITUTION_NAME = 'Uniben'
    3738CURRENCY = '566'
     39GATEWAY_AMT = 150.0
    3840#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
    3941#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
     
    156158        xmldict['institution_amt'] = '0.0'
    157159        if self.context.p_category == 'schoolfee':
    158             provider_amt = 1500
     160            provider_amt = 1500.0
    159161            if student.current_mode.endswith('_ft'):
    160162                self.pay_item_id = '5700'
     
    181183        elif self.context.p_category == 'clearance':
    182184            self.pay_item_id = '5702'
    183             provider_amt = 1500
     185            provider_amt = 1500.0
    184186            if student.current_mode == 'pg_ft':
    185187                xmldict['institution_acct'] = '5330832799'
     
    196198        elif self.context.p_category == 'gown':
    197199            self.pay_item_id = '5704'
    198             provider_amt = 0
     200            provider_amt = 0.0
    199201            xmldict['institution_bank_id'] = '7'
    200202            xmldict['institution_acct'] = '1016232382'
    201203        elif self.context.p_category.startswith('hostel_maintenance'):
    202204            self.pay_item_id = '5705'
    203             provider_amt = 0
     205            provider_amt = 0.0
    204206            xmldict['institution_bank_id'] = '129'
    205207            xmldict['institution_acct'] = '0014414547'
     
    209211        xmldict['institution_name'] = INSTITUTION_NAME
    210212        xmldict['institution_amt'] = 100 * (
    211             self.context.amount_auth - provider_amt - 150)
     213            self.context.amount_auth - provider_amt - GATEWAY_AMT)
    212214        # Interswitch amount is not part of the xml data
    213215        if provider_amt == 0:
     
    225227</payment_item_detail>""" % xmldict
    226228        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
     229        self.context.provider_amt = provider_amt
     230        self.context.gateway_amt = GATEWAY_AMT
    227231        return
    228232
     
    262266            self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z")
    263267        self.site_redirect_url = self.url(self.context, 'request_webservice')
    264         provider_amt = 400
     268        provider_amt = 400.0
    265269        if self.applicant.applicant_id.startswith('pg'):
    266270            xmldict['institution_acct'] = '0031716030'
     
    277281        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
    278282        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
    279         xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - 150)
     283        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - GATEWAY_AMT)
    280284        xmldict['institution_item_name'] = self.context.p_category
    281285        xmldict['institution_name'] = INSTITUTION_NAME
     
    288292</payment_item_detail>""" % xmldict
    289293        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
     294        self.context.provider_amt = provider_amt
     295        self.context.gateway_amt = GATEWAY_AMT
    290296        return
    291297
     
    368374            self.flash(msg)
    369375            return
     376        write_payments_log(student.student_id, self.context)
    370377        success, msg, log = self.context.doAfterStudentPayment()
    371378        if log is not None:
     
    396403            self.flash(msg)
    397404            return
     405        write_payments_log(applicant.applicant_id, self.context)
    398406        success, msg, log = self.context.doAfterApplicantPayment()
    399407        if log is not None:
  • main/waeup.uniben/trunk/src/waeup/uniben/interswitch/tests.py

    r9731 r9775  
    1616## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    1717##
     18import os
    1819from zope.component import createObject, getUtility
    1920from zope.catalog.interfaces import ICatalog
     
    5859                           self.browser.contents)
    5960        ctrl = self.browser.getControl(name='val_id')
    60         value = ctrl.options[0]
    61         self.browser.getLink(value).click()
     61        self.value = ctrl.options[0]
     62        self.browser.getLink(self.value).click()
    6263        self.assertMatches('...Amount Authorized...',
    6364                           self.browser.contents)
     
    122123        ctrl = self.browser.getControl(name='val_id')
    123124        value = ctrl.options[1]
     125        self.assertEqual(self.student['payments'][value].provider_amt, 0.0)
     126        self.assertEqual(self.student['payments'][value].gateway_amt, 0.0)
    124127        self.browser.getLink(value).click()
    125128        self.browser.getLink("CollegePAY", index=0).click()
     129        # Split amounts have been set.
     130        self.assertEqual(self.student['payments'][value].provider_amt, 1500.0)
     131        self.assertEqual(self.student['payments'][value].gateway_amt, 150.0)
    126132        self.assertMatches('...<input type="hidden" name="pay_item_id" value="5701" />...',
    127133                           self.browser.contents)
     
    148154        # Manager can access InterswitchForm
    149155        self.browser.getLink("CollegePAY", index=0).click()
     156        self.assertEqual(self.student['payments'][value].provider_amt, 1500.0)
     157        self.assertEqual(self.student['payments'][value].gateway_amt, 150.0)
    150158        self.assertMatches('...<input type="hidden" name="pay_item_id" value="5702" />...',
    151159                           self.browser.contents)
     
    176184        # Manager can access InterswitchForm
    177185        self.browser.getLink("CollegePAY", index=0).click()
     186        self.assertEqual(self.student['payments'][value].provider_amt, 0.0)
     187        self.assertEqual(self.student['payments'][value].gateway_amt, 150.0)
    178188        self.assertMatches('...<input type="hidden" name="pay_item_id" value="5704" />...',
    179189                           self.browser.contents)
     
    201211        # Manager can access InterswitchForm
    202212        self.browser.getLink("CollegePAY", index=0).click()
     213        self.assertEqual(self.student['payments'][value].provider_amt, 0.0)
     214        self.assertEqual(self.student['payments'][value].gateway_amt, 150.0)
    203215        self.assertMatches('...<input type="hidden" name="pay_item_id" value="5705" />...',
    204216                           self.browser.contents)
     
    237249    @external_test
    238250    def test_webservice(self):
    239 
     251        # First we have open InterswitchPageStudent to set provider_amt
     252        # and gateway_amt
     253        self.browser.open(self.payment_url + '/goto_interswitch')
     254        # Now we can call the webservice
    240255        self.browser.open(self.payment_url + '/request_webservice')
    241256        self.assertMatches('...Unsuccessful callback...',
     
    250265        self.assertEqual(len(results), 1)
    251266        self.assertEqual(results[0].p_state, 'failed')
     267
     268        # Let's replace the p_id with a valid p_id of the Uniben
     269        # live system. This is definitely not an appropriate
     270        # solution for testing, but we have no choice since
     271        # Interswitch doesn't provide any interface
     272        # for testing.
     273        payment = self.student['payments'][self.value]
     274        payment.p_id = 'p3547789850240'
     275        self.browser.open(self.payment_url + '/request_webservice')
     276        self.assertMatches('...Callback amount does not match...',
     277                          self.browser.contents)
     278        # The payment is now in state failed ...
     279        self.assertMatches('...<span>Failed</span>...',
     280                          self.browser.contents)
     281        # Let's replace the amount autorized with the amount of the
     282        # live system payment
     283        payment.amount_auth = payment.r_amount_approved
     284        self.browser.open(self.payment_url + '/request_webservice')
     285        self.assertMatches('...Successful payment...',
     286                          self.browser.contents)
     287        # The payment is now in state paid ...
     288        self.assertMatches('...<span>Paid</span>...',
     289                          self.browser.contents)
     290        # ... and the catalog has been updated
     291        cat = getUtility(ICatalog, name='payments_catalog')
     292        results = list(
     293            cat.searchResults(p_state=('paid', 'paid')))
     294        self.assertEqual(len(results), 1)
     295        self.assertEqual(results[0].p_state, 'paid')
     296        # Approval is logged in students.log ...
     297        logfile = os.path.join(
     298            self.app['datacenter'].storage, 'logs', 'students.log')
     299        logcontent = open(logfile).read()
     300        self.assertTrue(
     301            'zope.mgr - '
     302            'waeup.uniben.interswitch.browser.InterswitchPaymentRequestWebservicePageStudent - '
     303            'B1000000 - successful schoolfee payment: p3547789850240\n'
     304            in logcontent)
     305        # ... and in payments.log
     306        logfile = os.path.join(
     307            self.app['datacenter'].storage, 'logs', 'payments.log')
     308        logcontent = open(logfile).read()
     309        self.assertTrue(
     310            '"zope.mgr",B1000000,p3547789850240,schoolfee,'
     311            '12000.0,00,1500.0,150.0,0.0,,,\n'
     312            in logcontent)
     313
    252314
    253315class InterswitchTestsApplicants(ApplicantsFullSetup):
  • main/waeup.uniben/trunk/src/waeup/uniben/students/browser.py

    r9688 r9775  
    7070    """
    7171    grok.context(ICustomStudentOnlinePayment)
    72     form_fields = grok.AutoFields(ICustomStudentOnlinePayment)
     72    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
     73        'provider_amt', 'gateway_amt', 'thirdparty_amt')
    7374    form_fields[
    7475        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
     
    106107    """
    107108    grok.context(ICustomStudentOnlinePayment)
    108     form_fields = grok.AutoFields(ICustomStudentOnlinePayment)
     109    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
     110        'provider_amt', 'gateway_amt', 'thirdparty_amt')
    109111    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
    110112    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
Note: See TracChangeset for help on using the changeset viewer.