Ignore:
Timestamp:
20 May 2021, 19:47:27 (4 years ago)
Author:
Henrik Bettermann
Message:

Add missing tests and fix software.

Location:
main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/interswitch
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/interswitch/helpers.py

    r16487 r16488  
    327327    payment.r_code = p_status
    328328    try:
    329         payment.r_desc = "%s - %s - %s" % (
     329        payment.r_desc = "Channel Name: %s - Terminal Id: %s - Location: %s" % (
    330330            doc.getElementsByTagName('ChannelName')[0].firstChild.data,
    331331            doc.getElementsByTagName('TerminalId')[0].firstChild.data,
    332             doc.getElementsByTagName('Location'))[0].firstChild.data
     332            doc.getElementsByTagName('Location')[0].firstChild.data)
    333333    except AttributeError:
    334334        pass
    335335    try:
    336336        amount = doc.getElementsByTagName('Amount')[0].firstChild.data
    337         payment.r_amount_approved = int(amount)
     337        payment.r_amount_approved = float(amount)
    338338    except AttributeError:
    339339        pass
    340340    try:
    341341        payment.r_pay_reference = doc.getElementsByTagName(
    342             'ReferenceNumber').firstChild.data
     342            'ReferenceNumber')[0].firstChild.data
    343343    except AttributeError:
    344344        pass
    345345    if p_status not in ('Pending', 'Completed'):
    346         msg = _('Unknown status: %s' % sr[0])
    347         log = 'invalid callback for payment %s: %s' % (payment.p_id, status)
     346        msg = _('Unknown status: %s' % p_status)
     347        log = 'invalid callback for payment %s: %s' % (payment.p_id, p_status)
    348348        payment.p_state = 'failed'
    349349        notify(grok.ObjectModifiedEvent(payment))
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/interswitch/paydirectbrowser.py

    r16487 r16488  
    122122                return _('Invalid callback from Interswitch')
    123123            rc = doc.getElementsByTagName('ResponseCode')[0].firstChild.data
    124             if rc != '100':
     124            if rc not in ('100', '108'):
    125125                return 'Error response code from Interswitch: %s' % rc
    126126        return
     
    162162            student.writeLogMessage(self, log)
    163163        self.flash(msg, type=flashtype)
     164        self.redirect(self.url(self.context, '@@index'))
    164165        return
    165166
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/interswitch/tests.py

    r16487 r16488  
    236236        payment.p_session = self.student.current_session
    237237        payment.p_item = u'My Certificate'
    238         payment.p_id = u'p1234'
    239238        payment.p_id = 'p' + str(random.randint(10000000000, 90000000000))
    240239        payment.amount_auth = 1000.0
     
    255254
    256255    @external_test_2
    257     def test_paydirect(self):
     256    def test_paydirect_pending(self):
    258257        # Manager can access InterswitchForm
    259258        self.browser.getLink("Pay via Interswitch PAYDirect").click()
     
    302301        print "Sample PDF refnumberslip.pdf written to %s" % path
    303302
     303    @external_test_2
     304    def test_paydirect_completed(self):
     305        payment = createObject('waeup.StudentOnlinePayment')
     306        payment.p_category = u'schoolfee'
     307        payment.p_session = self.student.current_session
     308        payment.p_item = u'My Certificate'
     309        # p6214352306153 has been manuylly set completed by Interswitch
     310        payment.p_id = u'p6214352306153'
     311        payment.amount_auth = 700.0 # 300 will be added
     312        self.student['payments'][payment.p_id] = payment
     313        result_xml = get_SOAP_response_paydirect(
     314            MERCHANT_ID, payment.p_id, PAYDIRECT_HOST, PAYDIRECT_URL, True)
     315        doc=parseString(result_xml)
     316        status=doc.getElementsByTagName('PaymentStatus')[0].firstChild.data
     317        refnumber=doc.getElementsByTagName('ReferenceNumber')[0].firstChild.data
     318        amount=float(doc.getElementsByTagName('Amount')[0].firstChild.data)
     319        self.assertEqual(status, 'Completed')
     320        self.assertEqual(amount, payment.amount_auth + 300)
     321        self.assertEqual(refnumber, '60336214352306153')
     322        # Now we login and check what will happen with the student after payment
     323        self.browser.open(self.payments_path)
     324        self.browser.getLink(payment.p_id).click()
     325        self.browser.getLink("Pay via Interswitch PAYDirect").click()
     326        # 300 has been added
     327        self.assertEqual(payment.amount_auth, 1000)
     328        # Reference number has been saved
     329        self.browser.getControl("Requery").click()
     330        self.assertEqual(
     331            self.student['payments'][payment.p_id].r_pay_reference, '60336214352306153')
     332        # Payment is made
     333        self.assertEqual(
     334            self.student['payments'][payment.p_id].p_state, 'paid')
     335        # Rubbish has been stored too
     336        self.assertTrue(
     337            self.student['payments'][payment.p_id].r_desc.startswith('Channel Name: Bank Branc'))
     338        logfile = os.path.join(
     339            self.app['datacenter'].storage, 'logs', 'students.log')
     340        logcontent = open(logfile).read()
     341        self.assertTrue(
     342            'zope.mgr - kofacustom.nigeria.interswitch.paydirectbrowser.PAYDirectPageStudent '
     343            '- K1000000 - valid callback for schoolfee payment %s: Completed' % payment.p_id in logcontent)
     344        self.assertTrue(
     345            'zope.mgr - K1000000 - First school fee payment made' in logcontent)
     346        self.assertTrue(
     347            'zope.mgr - kofacustom.nigeria.interswitch.paydirectbrowser.PAYDirectPageStudent '
     348            '- K1000000 - successful schoolfee payment: %s' % payment.p_id in logcontent)
     349
     350
     351
     352# logdatei testen
     353
    304354class InterswitchTestsApplicants(ApplicantsFullSetup):
    305355    """Tests for the Interswitch payment gateway.
Note: See TracChangeset for help on using the changeset viewer.