Ignore:
Timestamp:
2 Apr 2024, 20:25:29 (6 months ago)
Author:
Henrik Bettermann
Message:

Implement Etranzact Credo platform payments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/etranzact/tests.py

    r16784 r17730  
    3333from kofacustom.nigeria.testing import FunctionalLayer
    3434from kofacustom.nigeria.etranzact.helpers import (
    35     query_history, query_payoutlet, ERROR_PART1, ERROR_PART2)
     35    query_history, query_payoutlet, ERROR_PART1, ERROR_PART2,
     36    )
    3637
    3738#from kofacustom.nigeria.etranzact.helpers import (query_etranzact)
     
    167168        return
    168169
     170
     171
    169172class EtranzactTestsApplicants(ApplicantsFullSetup):
    170173    """Tests for the Etranzact payment gateway.
     
    318321            % self.payment.p_id)
    319322        self.assertEqual(self.browser.contents, ERROR_PART1 + 'PAYEE_ID already used' + ERROR_PART2)
     323
     324# Credo tests
     325
     326from kofacustom.nigeria.etranzact.helpers import (
     327    query_credo_payment, get_JSON_response_initialize)
     328
     329SECRET_API_KEY = "0PRI0500LB11cBSSLcW0DcW1BcWgmf45"
     330API_PUBLIC_KEY = "0PUB0500wuoOe9sdtSOLj5peqHKc8Q9W"
     331EXTERNAL_TESTS_CREDO = True
     332CREDO_HOST = "api.credodemo.com"
     333
     334def external_test_credo(func):
     335    if not EXTERNAL_TESTS_CREDO:
     336        myself = __file__
     337        if myself.endswith('.pyc'):
     338            myself = myself[:-1]
     339        print "WARNING: external Credo tests are skipped!"
     340        print "WARNING: edit %s to enable them." % myself
     341        return
     342    return func
     343
     344class CredoTestsStudents(StudentsFullSetup):
     345
     346    layer = FunctionalLayer
     347
     348    P_ID = 'p7120340727304' # works only if such a payment was made on the test platform
     349
     350    def setUp(self):
     351        super(CredoTestsStudents, self).setUp()
     352        self.app['configuration']['2004'].etranzact_credo_enabled = True
     353        payment = createObject('waeup.StudentOnlinePayment')
     354        payment.p_id = self.P_ID
     355        payment.p_category = 'schoolfee'
     356        payment.amount_auth = 100000.0
     357        self.student['payments'][payment.p_id] = payment
     358        self.payment2 = payment
     359
     360    @external_test_credo
     361    def test_initialize(self):
     362
     363        public_api_key = API_PUBLIC_KEY
     364        callbackUrl = 'aa.aa.aa'
     365        response = get_JSON_response_initialize(self.payment2, CREDO_HOST, callbackUrl, public_api_key)
     366
     367        ## A typical response
     368
     369        #{u'status': 200,
     370        # u'execTime': 5.109764,
     371        # u'message': u'Successfully processed',
     372        # u'data':
     373        #    {u'credoReference': u'vsb200B5oM0521Mb00og',
     374        #     u'reference': u'xyz',
     375        #     u'authorizationUrl': u'https://pay.credodemo.com/vsb200B5oM0521Mb00og'
     376        #     },
     377        # u'error': []
     378        #}
     379
     380        # Payment already exists
     381        self.assertEqual(response, {'error': {u'reference': u'Reference must be unique'}})
     382
     383        #self.assertEqual(response['status'], 200)
     384        #self.assertEqual(response['message'], 'Successfully processed')
     385        #self.assertEqual(response['data']['reference'], self.P_ID)
     386        #self.assertTrue('https://pay.credodemo.com/' in response['data']['authorizationUrl'])
     387        return
     388
     389    @external_test_credo
     390    def test_verify(self):
     391        self.payment2.p_id = 'anything'
     392        success, msg, log = query_credo_payment(self.payment2, CREDO_HOST, SECRET_API_KEY)
     393        self.assertEqual(log, 'Transaction with ref# anything not found')
     394        self.payment2.p_id = self.P_ID # manually paid
     395        success, msg, log = query_credo_payment(self.payment2, CREDO_HOST, SECRET_API_KEY)
     396        self.assertEqual(msg, 'Successful callback received')
     397        self.assertEqual(self.payment2.r_code, '0')
     398        self.assertEqual(self.payment2.r_desc, 'Successfully processed')
     399        self.assertEqual(self.payment2.p_state, 'paid')
     400        return
     401
     402    @external_test_credo
     403    def test_student_credo_views(self):
     404        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     405        self.browser.open(self.payments_path)
     406        self.browser.getLink(self.P_ID).click()
     407        self.browser.getLink("Requery Etranzact Credo").click()
     408        self.assertTrue('<span>Successfully processed</span>' in self.browser.contents)
     409        self.assertEqual(self.payment2.r_desc, 'Successfully processed')
     410        return
     411
     412class CredoTestsApplicants(ApplicantsFullSetup):
     413
     414    layer = FunctionalLayer
     415
     416    P_ID = 'p7120808915674' # works only if such a payment was made on the test platform
     417
     418    def setUp(self):
     419        super(CredoTestsApplicants, self).setUp()
     420        # Add session configuration object
     421        configuration = SessionConfiguration()
     422        configuration.academic_session =  self.applicant.__parent__.year
     423        configuration.etranzact_credo_enabled = True
     424        self.app['configuration'].addSessionConfiguration(configuration)
     425        payment = createObject('waeup.ApplicantOnlinePayment')
     426        payment.p_id = self.P_ID
     427        payment.p_category = 'application'
     428        payment.amount_auth = 5000.0
     429        self.applicant.email = 'xx@xx.xx'
     430        self.applicant[payment.p_id] = payment
     431        self.payment2 = payment
     432
     433    @external_test_credo
     434    def test_initialize(self):
     435
     436        public_api_key = API_PUBLIC_KEY
     437        callbackUrl = 'aa.aa.aa'
     438        response = get_JSON_response_initialize(self.payment2, CREDO_HOST, callbackUrl, public_api_key)
     439
     440        # Payment already exists
     441        self.assertEqual(response, {'error': {u'reference': u'Reference must be unique'}})
     442
     443        #self.assertEqual(response['status'], 200)
     444        #self.assertEqual(response['message'], 'Successfully processed')
     445        #self.assertEqual(response['data']['reference'], self.P_ID)
     446        #self.assertTrue('https://pay.credodemo.com/' in response['data']['authorizationUrl'])
     447        return
     448
     449    @external_test_credo
     450    def test_verify(self):
     451        self.payment2.p_id = 'anything'
     452        success, msg, log = query_credo_payment(self.payment2, CREDO_HOST, SECRET_API_KEY)
     453        self.assertEqual(log, 'Transaction with ref# anything not found')
     454        self.payment2.p_id = self.P_ID # manually paid
     455        success, msg, log = query_credo_payment(self.payment2, CREDO_HOST, SECRET_API_KEY)
     456        self.assertEqual(msg, 'Successful callback received')
     457        self.assertEqual(self.payment2.r_code, '0')
     458        self.assertEqual(self.payment2.r_desc, 'Successfully processed')
     459        self.assertEqual(self.payment2.p_state, 'paid')
     460        return
     461
     462    @external_test_credo
     463    def test_applicant_credo_views(self):
     464        IWorkflowState(self.applicant).setState('started')
     465        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     466        self.browser.open(self.view_path)
     467        self.browser.getLink(self.P_ID).click()
     468        self.browser.getLink("Requery Etranzact Credo").click()
     469        self.assertTrue('<span>Successfully processed</span>' in self.browser.contents)
     470        self.assertEqual(self.payment2.r_desc, 'Successfully processed')
     471        self.assertEqual(self.applicant.state, 'paid')
     472        return
Note: See TracChangeset for help on using the changeset viewer.