Changeset 11868


Ignore:
Timestamp:
22 Oct 2014, 04:03:57 (10 years ago)
Author:
Henrik Bettermann
Message:

Add Interswitch school fee components for testing.

Location:
main/waeup.aaue/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.aaue/trunk/CHANGES.txt

    r11755 r11868  
    441.2dev (unreleased)
    55===================
     6
     7* Add and configure Interswitch module.
    68
    79* Customize payment_slip_download_warning. Application payment tickets can be
  • main/waeup.aaue/trunk/src/waeup/aaue/etranzact/browser.py

    r11846 r11868  
    357357# respectively. But then all interswitch.browser modules have to be extended.
    358358
    359 class InterswitchActionButtonStudent(InterswitchActionButtonStudent):
    360 
    361     @property
    362     def target_url(self):
    363         return ''
    364 
    365 class InterswitchRequestWebserviceActionButtonStudent(
    366     InterswitchRequestWebserviceActionButtonStudent):
    367 
    368     @property
    369     def target_url(self):
    370         return ''
    371 
    372 #class InterswitchActionButtonApplicant(InterswitchActionButtonApplicant):
     359#class InterswitchActionButtonStudent(InterswitchActionButtonStudent):
    373360
    374361#    @property
     
    376363#        return ''
    377364
    378 #class InterswitchRequestWebserviceActionButtonApplicant(
    379 #    InterswitchRequestWebserviceActionButtonApplicant):
     365#class InterswitchRequestWebserviceActionButtonStudent(
     366#    InterswitchRequestWebserviceActionButtonStudent):
    380367
    381368#    @property
    382369#    def target_url(self):
    383370#        return ''
     371
     372#class InterswitchActionButtonApplicant(InterswitchActionButtonApplicant):
     373
     374#    @property
     375#    def target_url(self):
     376#        return ''
     377
     378#class InterswitchRequestWebserviceActionButtonApplicant(
     379#    InterswitchRequestWebserviceActionButtonApplicant):
     380
     381#    @property
     382#    def target_url(self):
     383#        return ''
  • main/waeup.aaue/trunk/src/waeup/aaue/interswitch/browser.py

    r11866 r11868  
    6565    mac = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3'
    6666
    67     def interswitch_img_url(self):
    68         return interswitch_img_url(self)
    69 
    7067    def update(self):
    7168
     
    105102        return
    106103
     104class CustomInterswitchPageStudent(InterswitchPageStudent):
     105    """ View which sends a POST request to the Interswitch
     106    CollegePAY payment gateway.
     107    """
     108    grok.context(ICustomStudentOnlinePayment)
     109    action = POST_ACTION
     110    site_name = SITE_NAME
     111    currency = CURRENCY
     112    product_id = PRODUCT_ID
     113    pay_item_id = '101'
     114    mac = 'CEF793CBBE838AA0CBB29B74D571113B4EA6586D3BA77E7CFA0B95E278364EFC4526ED7BD255A366CDDE11F1F607F0F844B09D93B16F7CFE87563B2272007AB3'
     115
     116    def update(self):
     117        error = self.init_update()
     118        if error:
     119            self.flash(error, type='danger')
     120            self.redirect(self.url(self.context, '@@index'))
     121            return
     122        student = self.student
     123        xmldict = self.xmldict
     124        # Provider data
     125        xmldict['detail_ref'] = self.context.p_id
     126        xmldict['provider_acct'] = PROVIDER_ACCT
     127        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
     128        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
     129        # Institution data
     130        xmldict['institution_acct'] = '00000000'
     131        xmldict['institution_bank_id'] = '00'
     132        xmldict['institution_amt'] = '0.0'
     133        provider_amt = 0.0
     134        xmldict['provider_amt'] = 100 * provider_amt
     135        xmldict['institution_item_name'] = self.category
     136        xmldict['institution_name'] = INSTITUTION_NAME
     137        xmldict['institution_amt'] = 100 * (
     138            self.context.amount_auth - provider_amt - GATEWAY_AMT)
     139        # Interswitch amount is not part of the xml data
     140        if provider_amt == 0:
     141            xmltext = """<payment_item_detail>
     142<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
     143<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" />
     144</item_details>
     145</payment_item_detail>""" % xmldict
     146        else:
     147            xmltext = """<payment_item_detail>
     148<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
     149<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" />
     150<item_detail item_id="2" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
     151</item_details>
     152</payment_item_detail>""" % xmldict
     153        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
     154        self.context.provider_amt = provider_amt
     155        self.context.gateway_amt = GATEWAY_AMT
     156
     157        hashargs = (
     158            self.context.p_id +
     159            PRODUCT_ID +
     160            self.pay_item_id +
     161            str(int(self.amount_auth)) +
     162            self.site_redirect_url +
     163            self.mac)
     164        self.hashvalue = hashlib.sha512(hashargs).hexdigest()
     165
     166        return
     167
    107168
    108169class CustomInterswitchPaymentRequestWebservicePageApplicant(
     
    114175    gateway_host = HOST
    115176    gateway_url = URL
     177
     178class CustomInterswitchPaymentRequestWebservicePageStudent(
     179    InterswitchPaymentRequestWebservicePageStudent):
     180    """ Request webservice view for the CollegePAY gateway
     181    """
     182    grok.context(ICustomStudentOnlinePayment)
     183    product_id = PRODUCT_ID
     184    gateway_host = HOST
     185    gateway_url = URL
  • main/waeup.aaue/trunk/src/waeup/aaue/interswitch/tests.py

    r11846 r11868  
    9696        self.assertMatches('...<span>Failed</span>...',
    9797                          self.browser.contents)
     98
     99class InterswitchTestsStudents(StudentsFullSetup):
     100    """Tests for the Interswitch payment gateway.
     101    """
     102
     103    layer = FunctionalLayer
     104
     105    def setUp(self):
     106        super(InterswitchTestsStudents, self).setUp()
     107
     108    def test_interswitch_form(self):
     109        self.app['configuration']['2004'].school_fee_1 = 6666.0
     110        # Manager can access InterswitchForm
     111        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     112        self.browser.open(self.payments_path)
     113        IWorkflowState(self.student).setState('cleared')
     114        self.student.nationality = u'NG'
     115        self.browser.open(self.payments_path + '/addop')
     116        self.browser.getControl(name="form.p_category").value = ['schoolfee']
     117        self.browser.getControl("Create ticket").click()
     118        self.assertMatches('...ticket created...',
     119                           self.browser.contents)
     120        ctrl = self.browser.getControl(name='val_id')
     121        self.value = ctrl.options[0]
     122        self.browser.getLink(self.value).click()
     123        self.assertMatches('...Amount Authorized...',
     124                           self.browser.contents)
     125        self.assertMatches(
     126            '...<span>6666.0</span>...',
     127            self.browser.contents)
     128        self.payment_url = self.browser.url
     129        self.browser.getLink("CollegePAY", index=0).click()
     130        # The total amount to be processed by Interswitch
     131        # has been reduced by the Interswitch fee of 150 Nairas
     132        self.assertMatches('...<input type="hidden" name="pay_item_id" value="101" />...',
     133                           self.browser.contents)
     134        self.assertMatches('...Total Amount Authorized:...',
     135                           self.browser.contents)
     136        self.assertEqual(self.student.current_mode, 'ug_ft')
     137        self.assertMatches(
     138            '...<input type="hidden" name="amount" value="666600" />...',
     139            self.browser.contents)
     140        self.assertMatches(
     141            '...item_name="School Fee" item_amt="641600" bank_id="00" acct_num="00000000"...',
     142            self.browser.contents)
     143
     144    @external_test
     145    def test_webservice(self):
     146        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     147        self.browser.open(self.payments_path)
     148        IWorkflowState(self.student).setState('cleared')
     149        self.student.nationality = u'NG'
     150        self.browser.open(self.payments_path + '/addop')
     151        self.browser.getControl(name="form.p_category").value = ['schoolfee']
     152        self.browser.getControl("Create ticket").click()
     153        self.assertMatches('...ticket created...',
     154                           self.browser.contents)
     155        ctrl = self.browser.getControl(name='val_id')
     156        self.value = ctrl.options[0]
     157        self.browser.getLink(self.value).click()
     158        self.payment_url = self.browser.url
     159        # First we have open InterswitchPageStudent to set provider_amt
     160        # and gateway_amt
     161        self.browser.open(self.payment_url + '/goto_interswitch')
     162        # Now we can call the webservice
     163        self.browser.open(self.payment_url + '/request_webservice')
     164        self.assertMatches('...Unsuccessful callback...',
     165                          self.browser.contents)
     166        # The payment is now in state failed ...
     167        self.assertMatches('...<span>Failed</span>...',
     168                          self.browser.contents)
     169        # ... and the catalog has been updated
     170        cat = getUtility(ICatalog, name='payments_catalog')
     171        results = list(
     172            cat.searchResults(p_state=('failed', 'failed')))
     173        self.assertEqual(len(results), 1)
     174        self.assertEqual(results[0].p_state, 'failed')
     175
     176        # Let's replace the p_id with a valid p_id of the Uniben
     177        # live system. This is definitely not an appropriate
     178        # solution for testing, but we have no choice since
     179        # Interswitch doesn't provide any interface
     180        # for testing.
     181        payment = self.student['payments'][self.value]
     182        payment.p_id = 'p3547789850240'
     183        self.browser.open(self.payment_url + '/request_webservice')
     184        self.assertMatches('...Callback amount does not match...',
     185                          self.browser.contents)
     186        # The payment is now in state failed ...
     187        self.assertMatches('...<span>Failed</span>...',
     188                          self.browser.contents)
     189        # Let's replace the amount autorized with the amount of the
     190        # live system payment
     191        payment.amount_auth = payment.r_amount_approved
     192        self.browser.open(self.payment_url + '/request_webservice')
     193        self.assertMatches('...Successful payment...',
     194                          self.browser.contents)
     195        # The payment is now in state paid ...
     196        self.assertMatches('...<span>Paid</span>...',
     197                          self.browser.contents)
     198        # ... and the catalog has been updated
     199        cat = getUtility(ICatalog, name='payments_catalog')
     200        results = list(
     201            cat.searchResults(p_state=('paid', 'paid')))
     202        self.assertEqual(len(results), 1)
     203        self.assertEqual(results[0].p_state, 'paid')
     204        # Approval is logged in students.log ...
     205        logfile = os.path.join(
     206            self.app['datacenter'].storage, 'logs', 'students.log')
     207        logcontent = open(logfile).read()
     208        self.assertTrue(
     209            'zope.mgr - '
     210            'waeup.aaue.interswitch.browser.CustomInterswitchPaymentRequestWebservicePageStudent - '
     211            'X1000000 - successful schoolfee payment: p3547789850240\n'
     212            in logcontent)
     213        # ... and in payments.log
     214        logfile = os.path.join(
     215            self.app['datacenter'].storage, 'logs', 'payments.log')
     216        logcontent = open(logfile).read()
     217        self.assertTrue(
     218            '"zope.mgr",X1000000,p3547789850240,schoolfee,'
     219            '12000.0,00,0.0,150.0,0.0,,,\n'
     220            in logcontent)
Note: See TracChangeset for help on using the changeset viewer.