Changeset 9780 for main/waeup.fceokene


Ignore:
Timestamp:
6 Dec 2012, 17:52:21 (12 years ago)
Author:
Henrik Bettermann
Message:

Changes according to r9775.

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

Legend:

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

    r9752 r9780  
    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 = 'FCEOkene'
    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'
     
    129131        self.site_redirect_url = self.url(self.context, 'request_webservice')
    130132        # Provider data
     133        provider_amt = 1600.0
    131134        xmldict['detail_ref'] = self.context.p_id
    132135        xmldict['provider_acct'] = PROVIDER_ACCT
    133136        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
    134137        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
    135         xmldict['provider_amt'] = 100 * 1600
     138        xmldict['provider_amt'] = 100 * provider_amt
    136139        # Institution data
     140        fceokene_split_amt = 1400.0
    137141        xmldict['fceokene_acct'] = "0000000000000"
    138142        xmldict['institution_bank_id'] = '0'
     
    154158                xmldict['institution_acct'] = "6216801025"
    155159                xmldict['institution_bank_id'] = '117'
    156             xmldict['fceokene_split'] = 100 * 1400
     160            xmldict['fceokene_split'] = 100 * fceokene_split_amt
    157161            xmldict['institution_amt'] = 100 * (
    158                 self.context.amount_auth - 1600 - 150 - 1400)
     162                self.context.amount_auth - provider_amt -
     163                GATEWAY_AMT - fceokene_split_amt)
    159164        elif 'maintenance' in self.context.p_category:
     165            fceokene_split_amt = 0.0
     166            provider_amt = 0.0
    160167            self.pay_item_id = '8300'
    161168            xmldict['institution_amt'] = 100 * (
    162                 self.context.amount_auth - 150)
     169                self.context.amount_auth - GATEWAY_AMT)
    163170            xmldict['institution_acct'] = "1012044132"
    164171            xmldict['institution_bank_id'] = '117'
     
    169176<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
    170177<item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
    171 <item_detail item_id="2" item_name="FCEOkene Split" item_amt="%(fceokene_split)s" bank_id="117" acct_num="6216801058" />
     178<item_detail item_id="2" item_name="FCEOkene Split" item_amt="%(fceokene_split)d" bank_id="117" acct_num="6216801058" />
    172179<item_detail item_id="3" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
    173180</item_details>
     
    182189
    183190        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
     191        self.context.provider_amt = provider_amt
     192        self.context.gateway_amt = GATEWAY_AMT
     193        self.context.thirdparty_amt = fceokene_split_amt
    184194        return
    185195
     
    221231        xmldict['detail_ref'] = self.context.p_id
    222232        # Provider data
    223         xmldict['provider_amt'] = 100 * 500
     233        provider_amt = 500.0
     234        xmldict['provider_amt'] = 100 * provider_amt
    224235        xmldict['provider_acct'] = PROVIDER_ACCT
    225236        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
    226237        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
    227238        # Institution data
    228         xmldict['institution_amt'] = 100 * (self.context.amount_auth - 500 - 150)
     239        xmldict['institution_amt'] = 100 * (self.context.amount_auth -
     240            provider_amt - GATEWAY_AMT)
    229241        xmldict['institution_acct'] = '1012445289'
    230242        xmldict['institution_bank_id'] = '117'
     
    239251</payment_item_detail>""" % xmldict
    240252        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
     253        self.context.provider_amt = provider_amt
     254        self.context.gateway_amt = GATEWAY_AMT
    241255        return
    242256
     
    258272        student.writeLogMessage(self, log)
    259273        if not success:
    260             msg = self.request['QUERY_STRING'].replace('%20',' ')
    261             self.flash(_('Response from Interswitch: ') + msg)
    262             return
     274            self.flash(msg)
     275            return
     276        write_payments_log(student.student_id, self.context)
    263277        success, msg, log = self.context.doAfterStudentPayment()
    264278        if log is not None:
     
    289303            self.flash(msg)
    290304            return
     305        write_payments_log(applicant.applicant_id, self.context)
    291306        success, msg, log = self.context.doAfterApplicantPayment()
    292307        if log is not None:
  • main/waeup.fceokene/trunk/src/waeup/fceokene/interswitch/tests.py

    r9711 r9780  
    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)
     
    8081    def test_interswitch_form(self):
    8182
     83        self.assertEqual(self.student['payments'][self.value].provider_amt, 0.0)
     84        self.assertEqual(self.student['payments'][self.value].gateway_amt, 0.0)
     85        self.assertEqual(self.student['payments'][self.value].thirdparty_amt, 0.0)
    8286        # Manager can access InterswitchForm for the created school fee ticket
    8387        self.browser.getLink("CollegePAY", index=0).click()
     88        # Split amounts have been set
     89        self.assertEqual(self.student['payments'][self.value].provider_amt, 1600.0)
     90        self.assertEqual(self.student['payments'][self.value].gateway_amt, 150.0)
     91        self.assertEqual(self.student['payments'][self.value].thirdparty_amt, 1400.0)
    8492        self.assertMatches('...Total Amount Authorized:...',
    8593                           self.browser.contents)
     
    133141            self.browser.contents)
    134142        self.payment_url = self.browser.url
     143        self.assertEqual(self.student['payments'][value].provider_amt, 0.0)
     144        self.assertEqual(self.student['payments'][value].gateway_amt, 0.0)
     145        self.assertEqual(self.student['payments'][value].thirdparty_amt, 0.0)
    135146        # Manager can access InterswitchForm
    136147        self.browser.getLink("CollegePAY", index=0).click()
     148        # Split amounts have been set
     149        self.assertEqual(self.student['payments'][value].provider_amt, 0.0)
     150        self.assertEqual(self.student['payments'][value].gateway_amt, 150.0)
     151        self.assertEqual(self.student['payments'][value].thirdparty_amt, 0.0)
    137152        # The total amount to be processed by Interswitch
    138153        # has been reduced by the Interswitch fee of 150 Nairas
     
    171186    @external_test
    172187    def test_webservice(self):
     188        # First we have open InterswitchPageStudent to set provider_amt
     189        # and gateway_amt
     190        self.browser.open(self.payment_url + '/goto_interswitch')
     191        # Now we can call the webservice
    173192        self.browser.open(self.payment_url + '/request_webservice')
    174193        #self.assertMatches('...Unsuccessful callback...',
    175194        #                  self.browser.contents)
    176         self.assertMatches('...Response from Interswitch...',
     195        self.assertMatches('...Unsuccessful callback...',
    177196                          self.browser.contents)
    178197        # The payment is now in state failed ...
     
    185204        self.assertEqual(len(results), 1)
    186205        self.assertEqual(results[0].p_state, 'failed')
     206
     207        # Let's replace the p_id with a valid p_id of the Uniben
     208        # live system. This is definitely not an appropriate
     209        # solution for testing, but we have no choice since
     210        # Interswitch doesn't provide any interface
     211        # for testing.
     212        payment = self.student['payments'][self.value]
     213        payment.p_id = 'p3536651296379'
     214        self.browser.open(self.payment_url + '/request_webservice')
     215        self.assertMatches('...Callback amount does not match...',
     216                          self.browser.contents)
     217        # The payment is now in state failed ...
     218        self.assertMatches('...<span>Failed</span>...',
     219                          self.browser.contents)
     220        # Let's replace the amount autorized with the amount of the
     221        # live system payment
     222        payment.amount_auth = payment.r_amount_approved
     223        self.browser.open(self.payment_url + '/request_webservice')
     224        self.assertMatches('...Successful payment...',
     225                          self.browser.contents)
     226        # The payment is now in state paid ...
     227        self.assertMatches('...<span>Paid</span>...',
     228                          self.browser.contents)
     229        # ... and the catalog has been updated
     230        cat = getUtility(ICatalog, name='payments_catalog')
     231        results = list(
     232            cat.searchResults(p_state=('paid', 'paid')))
     233        self.assertEqual(len(results), 1)
     234        self.assertEqual(results[0].p_state, 'paid')
     235        # Approval is logged in students.log ...
     236        logfile = os.path.join(
     237            self.app['datacenter'].storage, 'logs', 'students.log')
     238        logcontent = open(logfile).read()
     239        self.assertTrue(
     240            'zope.mgr - '
     241            'waeup.fceokene.interswitch.browser.InterswitchPaymentRequestWebservicePageStudent - '
     242            'K1000000 - successful schoolfee payment: p3536651296379\n'
     243            in logcontent)
     244        # ... and in payments.log
     245        logfile = os.path.join(
     246            self.app['datacenter'].storage, 'logs', 'payments.log')
     247        logcontent = open(logfile).read()
     248        self.assertTrue(
     249            '"zope.mgr",K1000000,p3536651296379,schoolfee,'
     250            '3150.0,00,1600.0,150.0,1400.0,,,\n'
     251            in logcontent)
    187252
    188253class InterswitchTestsApplicants(ApplicantsFullSetup):
     
    205270        self.assertMatches('...ticket created...',
    206271                           self.browser.contents)
    207         #ctrl = self.browser.getControl(name='val_id')
    208         #value = ctrl.options[0]
    209         #self.browser.getLink(value).click()
    210272        self.assertMatches('...Amount Authorized...',
    211273                           self.browser.contents)
     
    214276            self.browser.contents)
    215277        self.payment_url = self.browser.url
     278        self.browser.open(self.manage_path)
     279        ctrl = self.browser.getControl(name='val_id')
     280        self.value = ctrl.options[0]
    216281
    217282
     
    219284
    220285        # Manager can access InterswitchForm
     286        self.browser.open(self.payment_url)
    221287        self.browser.getLink("CollegePAY", index=0).click()
    222288        self.assertMatches('...Total Amount Authorized:...',
     
    228294    @external_test
    229295    def test_webservice(self):
    230 
     296        # First we have open InterswitchPageStudent to set provider_amt
     297        # and gateway_amt
     298        self.browser.open(self.payment_url + '/goto_interswitch')
     299        # Now we can call the webservice
    231300        self.browser.open(self.payment_url + '/request_webservice')
    232301        self.assertMatches('...Unsuccessful callback...',
    233302                          self.browser.contents)
    234         # The payment is now in state failed
     303        # The payment is now in state failed ...
    235304        self.assertMatches('...<span>Failed</span>...',
    236305                          self.browser.contents)
     306        # ... and the catalog has been updated
     307        cat = getUtility(ICatalog, name='payments_catalog')
     308        results = list(
     309            cat.searchResults(p_state=('failed', 'failed')))
     310        self.assertEqual(len(results), 1)
     311        self.assertEqual(results[0].p_state, 'failed')
     312
     313        # Let's replace the p_id with a valid p_id of the Uniben
     314        # live system. This is definitely not an appropriate
     315        # solution for testing, but we have no choice since
     316        # Interswitch doesn't provide any interface
     317        # for testing.
     318        payment = self.applicant[self.value]
     319        payment.p_id = 'p3536651296379'
     320        self.browser.open(self.payment_url + '/request_webservice')
     321        self.assertMatches('...Callback amount does not match...',
     322                          self.browser.contents)
     323        # The payment is now in state failed ...
     324        self.assertMatches('...<span>Failed</span>...',
     325                          self.browser.contents)
     326        # Let's replace the amount autorized with the amount of the
     327        # live system payment
     328        payment.amount_auth = payment.r_amount_approved
     329        self.browser.open(self.payment_url + '/request_webservice')
     330        self.assertMatches('...Successful payment...',
     331                          self.browser.contents)
     332        # The payment is now in state paid ...
     333        self.assertMatches('...<span>Paid</span>...',
     334                          self.browser.contents)
     335        # ... and the catalog has been updated
     336        cat = getUtility(ICatalog, name='payments_catalog')
     337        results = list(
     338            cat.searchResults(p_state=('paid', 'paid')))
     339        self.assertEqual(len(results), 1)
     340        self.assertEqual(results[0].p_state, 'paid')
     341        # Approval is logged in students.log ...
     342        logfile = os.path.join(
     343            self.app['datacenter'].storage, 'logs', 'applicants.log')
     344        logcontent = open(logfile).read()
     345        self.assertTrue(
     346            'zope.mgr - '
     347            'waeup.fceokene.interswitch.browser.InterswitchPaymentRequestWebservicePageApplicant - '
     348            '%s - successful payment: p3536651296379\n'
     349            % self.applicant.applicant_id in logcontent)
     350        # ... and in payments.log
     351        logfile = os.path.join(
     352            self.app['datacenter'].storage, 'logs', 'payments.log')
     353        logcontent = open(logfile).read()
     354        self.assertTrue(
     355            '"zope.mgr",%s,p3536651296379,application,'
     356            '3150.0,00,500.0,150.0,0.0,,,\n' % self.applicant.applicant_id
     357            in logcontent)
  • main/waeup.fceokene/trunk/src/waeup/fceokene/students/browser.py

    r9406 r9780  
    3636    """
    3737    grok.context(ICustomStudentOnlinePayment)
    38     form_fields = grok.AutoFields(ICustomStudentOnlinePayment)
     38    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
     39        'provider_amt', 'gateway_amt', 'thirdparty_amt')
    3940    form_fields[
    4041        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
     
    5253    """
    5354    grok.context(ICustomStudentOnlinePayment)
    54     form_fields = grok.AutoFields(ICustomStudentOnlinePayment)
     55    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
     56        'provider_amt', 'gateway_amt', 'thirdparty_amt')
    5557    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
    5658    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
Note: See TracChangeset for help on using the changeset viewer.