Changeset 9785


Ignore:
Timestamp:
7 Dec 2012, 08:59:30 (12 years ago)
Author:
Henrik Bettermann
Message:

Changes according to r9775.

Use classes defined in kofacustom.nigeria.

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

Legend:

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

    r9750 r9785  
    1919import grok
    2020from zope.component import getUtility
    21 from kofacustom.nigeria.interswitch.helpers import query_interswitch
    22 from waeup.kofa.browser.layout import KofaPage, UtilityView
     21from kofacustom.nigeria.interswitch.browser import (
     22    InterswitchPaymentRequestWebservicePageStudent
     23    )
     24from waeup.kofa.browser.layout import KofaPage
    2325from waeup.kofa.interfaces import RETURNING, CLEARED, IKofaUtils
    2426from waeup.kofa.utils.helpers import to_timezone
    25 from waeup.kofa.students.viewlets import ApprovePaymentActionButton as APABStudent
    2627from waeup.futminna.students.interfaces import ICustomStudentOnlinePayment
    2728from waeup.futminna.interfaces import MessageFactory as _
     
    3435INSTITUTION_NAME = 'FUTMinna'
    3536CURRENCY = '566'
     37GATEWAY_AMT = 300.0
    3638#QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
    3739#QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
     
    4446#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
    4547httplib.HTTPConnection.debuglevel = 0
    46 
    47 class InterswitchActionButtonStudent(APABStudent):
    48     grok.order(1)
    49     grok.context(ICustomStudentOnlinePayment)
    50     grok.require('waeup.payStudent')
    51     icon = 'actionicon_pay.png'
    52     text = _('CollegePAY')
    53     target = 'goto_interswitch'
    54 
    55     @property
    56     def target_url(self):
    57         if self.context.p_state != 'unpaid':
    58             return ''
    59         return self.view.url(self.view.context, self.target)
    60 
    61 class InterswitchRequestWebserviceActionButtonStudent(APABStudent):
    62     grok.order(2)
    63     grok.context(ICustomStudentOnlinePayment)
    64     grok.require('waeup.payStudent')
    65     icon = 'actionicon_call.png'
    66     text = _('Requery CollegePAY')
    67     target = 'request_webservice'
    6848
    6949class InterswitchPageStudent(KofaPage):
     
    11191        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
    11292        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
    113         provider_amt = 1500
     93        provider_amt = 1500.0
    11494        xmldict['provider_amt'] = 100 * provider_amt
    11595
     
    124104        if self.context.p_category == 'schoolfee':
    125105            xmldict['institution_amt'] = 100 * (
    126                 self.context.amount_auth - provider_amt - 300)
     106                self.context.amount_auth - provider_amt - GATEWAY_AMT)
    127107            if self.context.student.current_mode in ('pg_ft'):
    128108                self.pay_item_id = "11703"
     
    183163        elif self.context.p_category == 'clearance':
    184164            xmldict['institution_amt'] = 100 * (
    185                 self.context.amount_auth - 300)
     165                self.context.amount_auth - GATEWAY_AMT)
    186166            xmldict['institution_acct'] = "1750005063"
    187167            xmldict['institution_bank_id'] = '120'
    188168            self.pay_item_id = "11706"
     169            provider_amt = 0.0
    189170
    190171        elif 'maintenance' in self.context.p_category:
    191172            xmldict['institution_amt'] = 100 * (
    192                 self.context.amount_auth - 300)
     173                self.context.amount_auth - GATEWAY_AMT)
    193174            xmldict['institution_acct'] = "2018856637"
    194175            xmldict['institution_bank_id'] = '8'
    195176            self.pay_item_id = "11705"
     177            provider_amt = 0.0
    196178
    197179        # Interswitch amount is not part of the xml data
     
    220202
    221203        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
     204        self.context.provider_amt = provider_amt
     205        self.context.gateway_amt = GATEWAY_AMT
    222206        return
    223207
    224 class InterswitchPaymentRequestWebservicePageStudent(UtilityView, grok.View):
     208class InterswitchPaymentRequestWebservicePageStudent(
     209    InterswitchPaymentRequestWebservicePageStudent):
    225210    """ Request webservice view for the CollegePAY gateway
    226211    """
    227212    grok.context(ICustomStudentOnlinePayment)
    228     grok.name('request_webservice')
    229     grok.require('waeup.payStudent')
    230 
    231     def update(self):
    232         if self.context.p_state == 'paid':
    233             self.flash(_('This ticket has already been paid.'))
    234             return
    235         student = self.context.student
    236         success, msg, log = query_interswitch(
    237             self.context, PRODUCT_ID, HOST, URL)
    238         student.writeLogMessage(self, log)
    239         if not success:
    240             self.flash(msg)
    241             return
    242         success, msg, log = self.context.doAfterStudentPayment()
    243         if log is not None:
    244             student.writeLogMessage(self, log)
    245         self.flash(msg)
    246         return
    247 
    248     def render(self):
    249         self.redirect(self.url(self.context, '@@index'))
    250         return
     213    product_id = PRODUCT_ID
     214    gateway_host = HOST
     215    gateway_url = URL
  • main/waeup.futminna/trunk/src/waeup/futminna/interswitch/tests.py

    r9714 r9785  
    1616## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    1717##
     18import os
    1819from zope.component import getUtility
    1920from zope.catalog.interfaces import ICatalog
     
    2728#   If you enable this, please make sure the external services
    2829#   do exist really and are not bothered by being spammed by a test programme.
    29 EXTERNAL_TESTS = False
     30EXTERNAL_TESTS = True
    3031
    3132def external_test(func):
     
    5758                           self.browser.contents)
    5859        ctrl = self.browser.getControl(name='val_id')
    59         value = ctrl.options[0]
    60         self.browser.getLink(value).click()
     60        self.value = ctrl.options[0]
     61        self.browser.getLink(self.value).click()
    6162        self.assertMatches('...Amount Authorized...',
    6263                           self.browser.contents)
     
    6869    def test_interswitch_form(self):
    6970        # Manager can access InterswitchForm
     71        self.assertEqual(self.student['payments'][self.value].provider_amt, 0.0)
     72        self.assertEqual(self.student['payments'][self.value].gateway_amt, 0.0)
    7073        self.browser.getLink("CollegePAY", index=0).click()
     74        # Split amounts have been set.
     75        self.assertEqual(self.student['payments'][self.value].provider_amt, 1500.0)
     76        self.assertEqual(self.student['payments'][self.value].gateway_amt, 300.0)
    7177        # The total amount to be processed by Interswitch
    7278        # has been reduced by the Interswitch fee of 150 Nairas
     
    99105        # Manager can access InterswitchForm
    100106        self.browser.getLink("CollegePAY", index=0).click()
     107        # Split amounts have been set.
     108        self.assertEqual(self.student['payments'][value].provider_amt, 0.0)
     109        self.assertEqual(self.student['payments'][value].gateway_amt, 300.0)
    101110        # The total amount to be processed by Interswitch
    102111        # has been reduced by the Interswitch fee of 150 Nairas
     
    143152        # Manager can access InterswitchForm
    144153        self.browser.getLink("CollegePAY", index=0).click()
     154        # Split amounts have been set.
     155        self.assertEqual(self.student['payments'][value].provider_amt, 0.0)
     156        self.assertEqual(self.student['payments'][value].gateway_amt, 300.0)
    145157        # The total amount to be processed by Interswitch
    146158        # has been reduced by the Interswitch fee of 150 Nairas
     
    159171    @external_test
    160172    def test_webservice(self):
     173        # First we have open InterswitchPageStudent to set provider_amt
     174        # and gateway_amt
     175        self.browser.open(self.payment_url + '/goto_interswitch')
     176        # Now we can call the webservice
    161177        self.browser.open(self.payment_url + '/request_webservice')
    162178        self.assertMatches('...Unsuccessful callback...',
     
    171187        self.assertEqual(len(results), 1)
    172188        self.assertEqual(results[0].p_state, 'failed')
     189
     190        # Let's replace the p_id with a valid p_id of the Uniben
     191        # live system. This is definitely not an appropriate
     192        # solution for testing, but we have no choice since
     193        # Interswitch doesn't provide any interface
     194        # for testing.
     195        payment = self.student['payments'][self.value]
     196        payment.p_id = 'p3522296094055'
     197        self.browser.open(self.payment_url + '/request_webservice')
     198        self.assertMatches('...Callback amount does not match...',
     199                          self.browser.contents)
     200        # The payment is now in state failed ...
     201        self.assertMatches('...<span>Failed</span>...',
     202                          self.browser.contents)
     203        # Let's replace the amount autorized with the amount of the
     204        # live system payment
     205        payment.amount_auth = payment.r_amount_approved
     206        self.browser.open(self.payment_url + '/request_webservice')
     207        self.assertMatches('...Successful payment...',
     208                          self.browser.contents)
     209        # The payment is now in state paid ...
     210        self.assertMatches('...<span>Paid</span>...',
     211                          self.browser.contents)
     212        # ... and the catalog has been updated
     213        cat = getUtility(ICatalog, name='payments_catalog')
     214        results = list(
     215            cat.searchResults(p_state=('paid', 'paid')))
     216        self.assertEqual(len(results), 1)
     217        self.assertEqual(results[0].p_state, 'paid')
     218        # Approval is logged in students.log ...
     219        logfile = os.path.join(
     220            self.app['datacenter'].storage, 'logs', 'students.log')
     221        logcontent = open(logfile).read()
     222        self.assertTrue(
     223            'zope.mgr - '
     224            'waeup.futminna.interswitch.browser.InterswitchPaymentRequestWebservicePageStudent - '
     225            'M1000000 - successful schoolfee payment: p3522296094055\n'
     226            in logcontent)
     227        # ... and in payments.log
     228        logfile = os.path.join(
     229            self.app['datacenter'].storage, 'logs', 'payments.log')
     230        logcontent = open(logfile).read()
     231        self.assertTrue(
     232            '"zope.mgr",M1000000,p3522296094055,schoolfee,'
     233            '20000.0,00,1500.0,300.0,0.0,,,\n'
     234            in logcontent)
  • main/waeup.futminna/trunk/src/waeup/futminna/students/browser.py

    r9403 r9785  
    3232    """
    3333    grok.context(ICustomStudentOnlinePayment)
    34     form_fields = grok.AutoFields(ICustomStudentOnlinePayment)
     34    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
     35        'provider_amt', 'gateway_amt', 'thirdparty_amt')
    3536    form_fields[
    3637        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
     
    4849    """
    4950    grok.context(ICustomStudentOnlinePayment)
    50     form_fields = grok.AutoFields(ICustomStudentOnlinePayment)
     51    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
     52        'provider_amt', 'gateway_amt', 'thirdparty_amt')
    5153    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
    5254    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
Note: See TracChangeset for help on using the changeset viewer.