Ignore:
Timestamp:
10 Mar 2025, 16:40:53 (11 hours ago)
Author:
Henrik Bettermann
Message:

Implement required combi split payments.

Location:
main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/interswitch
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/interswitch/browser.py

    r17900 r18034  
    1919import hashlib
    2020import grok
     21from waeup.kofa.students.interfaces import IStudentsUtils
     22from zope.component import getUtility
    2123from kofacustom.nigeria.interswitch.browser import (
    2224    module_activated,
     
    5254HTTPS = True
    5355
     56BANK_ACCOUNTS = {
     57    'access':               ('1228744877', '117'),
     58    'parentsconsult':       ('1228747029', '117'),
     59    'health_insurance':     ('1228744884', '117'),
     60    'municipal_returning':  ('0040621193','31'),
     61    'clearance':            ('0040621193','31'),
     62    'develop':              ('0040621193','31'),
     63    'medical_screening':    ('1311220657','117'),
     64    'conv':                 ('0040621193','31'),
     65    'registration_fresh':   ('0040621193','31'),
     66    'science':              ('0040621193','31'),
     67    'id_card':              ('0040621193','31'),
     68    'alumni':               ('1311974981','117'),
     69    'lab_support':          ('0040621193','31'),
     70    'registration_return':  ('0040621193','31'),
     71    'book':                 ('1228744877','117'),
     72    'waecneco':             ('0040621193','31'),
     73    'jambver':              ('0040621193','31'),
     74    'pg_other':             ('0040621193','31'),
     75    'municipal_fresh':      ('0040621193','31'),
     76    'matric':               ('0040621193','31')
     77    }
     78
    5479class CustomInterswitchPageStudent(InterswitchPageStudent):
    5580    """ View which sends a POST request to the Interswitch
     
    6590
    6691    def update(self):
     92        student_utils = getUtility(IStudentsUtils)
    6793        if not module_activated(
    6894            self.context.student.current_session, self.context):
     
    97123            'schoolfee', 'schoolfee40', 'secondinstal'):
    98124            self.pay_item_id = '101'
    99         elif self.context.p_category == 'book':
    100             self.pay_item_id = '103'
    101         elif self.context.p_category == 'parentsconsult':
    102             self.pay_item_id = '104'
    103         elif self.context.p_category in (
    104             'municipal_fresh', 'municipal_returning',
    105             'transcript_local', 'transcript_overseas', 'transcript'):
    106             self.pay_item_id = '105'
    107125        else:
     126            # we use the same item_id for all sundry payments
    108127            self.pay_item_id = '102'
    109128        if self.context.p_category in (
     
    143162
    144163            # Overwrite above selection
    145             if self.context.p_category == 'book':
    146                 xmldict['institution_acct'] = '1228744877'
    147                 xmldict['institution_bank_id'] = '117'
    148             elif self.context.p_category == 'parentsconsult':
    149                 xmldict['institution_acct'] = '1228747029'
    150                 xmldict['institution_bank_id'] = '117'
    151             elif self.context.p_category == 'health_insurance':
    152                 xmldict['institution_acct'] = '1228744884'
    153                 xmldict['institution_bank_id'] = '117'
     164            sundry_acct = BANK_ACCOUNTS.get(self.context.p_category, None)
     165            if sundry_acct is True:
     166                xmldict['institution_acct'] = sundry_acct[0]
     167                xmldict['institution_bank_id'] = sundry_acct[0]
    154168
    155169        if provider_amt == 0:
     
    166180</item_details>
    167181</payment_item_detail>""" % xmldict
     182
     183        # Overwrite xmltext above because we have to split required combi
     184        if self.context.p_category == 'required_combi':
     185            rp = student_utils._collect_required_payment_items(self.context.student)
     186            academic_session = student_utils._getSessionConfiguration(self.context.p_session)
     187            xmltext = """<payment_item_detail>
     188<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
     189<item_detail item_id="1" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />""" % xmldict
     190            item_id = 2
     191            for cat in rp:
     192                fee_name = cat + '_fee'
     193                item_name = cat
     194                item_amt = 100 * getattr(academic_session, fee_name, 0.0)
     195                if item_name.startswith('registration'):
     196                    item_amt -= 100 * provider_amt
     197                bank_id = BANK_ACCOUNTS[cat][1]
     198                acct_num = BANK_ACCOUNTS[cat][0]
     199                xmltext += """
     200<item_detail item_id="%s" item_name="%s" item_amt="%d" bank_id="%s" acct_num="%s" />""" % (item_id, item_name, item_amt, bank_id, acct_num)
     201                item_id += 1
     202            xmltext += """
     203</item_details>
     204</payment_item_detail>""" % xmldict
     205
    168206        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
    169207        self.amount_auth = int(100 * self.context.amount_auth)
  • main/kofacustom.iuokada/trunk/src/kofacustom/iuokada/interswitch/tests.py

    r17900 r18034  
    8989            self.browser.contents)
    9090
     91    def test_interswitch_required_combi(self):
     92        # Student is a fresh non-science student
     93        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     94        self.browser.open(self.payments_path)
     95        IWorkflowState(self.student).setState('cleared')
     96        self.student.nationality = u'NG'
     97        self.browser.open(self.payments_path + '/addop')
     98        self.browser.getControl(name="form.p_category").value = ['schoolfee']
     99        self.browser.getControl(name="form.p_option").value = ['first']
     100        self.browser.getControl("Create payment").click()
     101        self.assertTrue('Make either single payments or make a' in self.browser.contents)
     102        self.browser.getControl(name="form.p_category").value = ['required_combi']
     103        self.browser.getControl("Create payment").click()
     104        self.assertTrue('Student Health Insurance undefined.' in self.browser.contents)
     105        self.app['configuration']['2004'].registration_fresh_fee = 10000.0
     106        self.app['configuration']['2004'].book_fee = 10000.0
     107        self.app['configuration']['2004'].develop_fee = 10000.0
     108        self.app['configuration']['2004'].parentsconsult_fee = 10000.0
     109        self.app['configuration']['2004'].municipal_fresh_fee = 10000.0
     110        self.app['configuration']['2004'].matric_fee = 10000.0
     111        self.app['configuration']['2004'].waecneco_fee = 10000.0
     112        self.app['configuration']['2004'].jambver_fee = 10000.0
     113        self.app['configuration']['2004'].health_insurance_fee = 10000.0
     114        self.app['configuration']['2004'].id_card_fee = 10000.0
     115        self.app['configuration']['2004'].medical_screening_fee = 10000.0
     116        self.browser.getControl(name="form.p_category").value = ['required_combi']
     117        self.browser.getControl("Create payment").click()
     118        self.assertTrue('Payment created' in self.browser.contents)
     119        self.browser.open(self.payments_path)
     120        ctrl = self.browser.getControl(name='val_id')
     121        self.value = ctrl.options[0]
     122        self.browser.getLink(self.value).click()
     123        self.assertTrue(
     124            '<span>110000.0</span>' in self.browser.contents)
     125        self.payment_url = self.browser.url
     126        self.browser.getLink("Pay via Interswitch", index=0).click()
     127        self.assertTrue('<input type="hidden" name="pay_item_id" value="102" />' in
     128                           self.browser.contents)
     129        self.assertEqual(self.student.current_mode, 'ug_ft')
     130        # 250 gateway charge have been added
     131        payment = self.student['payments'][self.value]
     132        self.assertEqual(payment.amount_auth, 110250)
     133        self.assertEqual(payment.net_amt, 110000)
     134        print self.browser.contents
     135        self.assertTrue(
     136            '<input type="hidden" name="amount" value="11025000" />' in
     137            self.browser.contents)
     138        self.assertTrue(
     139            'item_id="6" item_name="registration_fresh" item_amt="500000" bank_id="31" acct_num="0040621193"' in
     140            self.browser.contents)
     141        self.assertTrue(
     142            'item_id="12" item_name="parentsconsult" item_amt="1000000" bank_id="117" acct_num="1228747029"' in
     143            self.browser.contents)
     144
    91145    def test_interswitch_form_ticket_expired(self):
    92146        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
Note: See TracChangeset for help on using the changeset viewer.