Ignore:
Timestamp:
9 Aug 2017, 08:49:45 (7 years ago)
Author:
Henrik Bettermann
Message:

Implement Payment Notification Listener.

Location:
main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/remita
Files:
1 added
1 edited

Legend:

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

    r14779 r14781  
    1919import unittest
    2020import random
     21import json
    2122from datetime import datetime, timedelta, date
    2223from zope.component import createObject, getUtility
     
    212213        self.assertTrue('Callback amount does not match.'
    213214            in self.browser.contents)
    214         self.payment.amount_auth = 1000.0
     215        self.payment.amount_auth = self.amount
    215216        self.browser.getLink("Requery Remita Payment Status").click()
    216217        self.assertTrue('Callback order id does not match.'
     
    224225        self.browser.getLink("Verify Remita Payment Status").click()
    225226        self.assertTrue('Successful callback received' in self.browser.contents)
     227        return
     228
     229class RemitaTestsWebserviceStudent(StudentsFullSetup):
     230    """Tests for the Remita payment gateway.
     231    """
     232    layer = FunctionalLayer
     233
     234    merchantId = '2547916'
     235    serviceTypeId = '4430731'
     236    api_key = '1946'
     237    responseurl = 'http://xxxx'
     238    host = 'www.remitademo.net'
     239
     240    # successful transaction
     241    # (hopefully this transaction remains in the Remita database)
     242    orderId = '3456346346'
     243    rrr = u'280007640804'
     244    amount = 1000.0
     245
     246    @external_test
     247    def test_payment_notification_listener_student(self):
     248        payment = createObject('waeup.StudentOnlinePayment')
     249        payment.p_category = u'schoolfee'
     250        payment.p_session = self.student.current_session
     251        payment.p_item = u'My Certificate'
     252        payment.p_id = self.orderId
     253        self.student['payments']['anykey'] = payment
     254        data = [{'orderRef': self.orderId, 'rrr': self.rrr},]
     255        # Send POST request with wrong payment amount
     256        payment.amount_auth = 2000.0
     257        self.browser.post('http://localhost/app/paymentnotificationlistener',
     258            json.dumps(data), 'application/json; charset=utf-8')
     259        self.assertEqual('0 (1)', self.browser.contents)
     260        # Send POST request with correct payment amount
     261        payment.amount_auth = self.amount
     262        self.browser.post('http://localhost/app/paymentnotificationlistener',
     263            json.dumps(data), 'application/json; charset=utf-8')
     264        self.assertEqual('1 (1)', self.browser.contents)
     265        logfile = os.path.join(
     266            self.app['datacenter'].storage, 'logs', 'students.log')
     267        logcontent = open(logfile).read()
     268        self.assertTrue(
     269            'zope.anybody - kofacustom.nigeria.remita.webservices.PaymentNotificationListenerWebservice'
     270            ' - K1000000 - valid callback for schoolfee payment %s: '
     271            % self.orderId   in logcontent)
     272        self.assertTrue(
     273            'zope.anybody - kofacustom.nigeria.remita.webservices.PaymentNotificationListenerWebservice'
     274            ' - K1000000 - successful schoolfee payment: %s'
     275            % self.orderId in logcontent)
     276        logfile = os.path.join(
     277            self.app['datacenter'].storage, 'logs', 'main.log')
     278        logcontent = open(logfile).read()
     279        self.assertTrue(
     280            'zope.anybody - PaymentNotificationListenerWebservice called: '
     281            '[{"rrr": "%s", "orderRef": "%s"}]'
     282            % (self.rrr, self.orderId) in logcontent)
     283        return
     284
     285class RemitaTestsWebserviceApplicant(ApplicantsFullSetup):
     286    """Tests for the Remita payment gateway.
     287    """
     288    layer = FunctionalLayer
     289
     290    merchantId = '2547916'
     291    serviceTypeId = '4430731'
     292    api_key = '1946'
     293    responseurl = 'http://xxxx'
     294    host = 'www.remitademo.net'
     295
     296    # successful transaction
     297    # (hopefully this transaction remains in the Remita database)
     298    orderId = '3456346346'
     299    rrr = u'280007640804'
     300    amount = 1000.0
     301
     302    @external_test
     303    def test_payment_notification_listener_applicant(self):
     304        self.applicantscontainer.application_fee = self.amount
     305        payment = createObject('waeup.ApplicantOnlinePayment')
     306        payment.p_category = u'application'
     307        payment.p_session = self.applicantscontainer.year
     308        payment.p_item = u'My Certificate'
     309        payment.p_id = self.orderId
     310        payment.amount_auth = self.amount
     311        self.applicant['anykey'] = payment
     312        IWorkflowState(self.applicant).setState('started')
     313        # Send POST request
     314        data = [{'orderRef': self.orderId, 'rrr': self.rrr},]
     315        self.browser.post('http://localhost/app/paymentnotificationlistener',
     316            json.dumps(data), 'application/json; charset=utf-8')
     317        self.assertEqual('1 (1)', self.browser.contents)
     318        logfile = os.path.join(
     319            self.app['datacenter'].storage, 'logs', 'applicants.log')
     320        logcontent = open(logfile).read()
     321        self.assertTrue(
     322            'zope.anybody - kofacustom.nigeria.remita.webservices.PaymentNotificationListenerWebservice'
     323            ' - %s - valid callback for application payment %s: '
     324            % (self.applicant.applicant_id, self.orderId) in logcontent)
     325        self.assertTrue(
     326            'zope.anybody - kofacustom.nigeria.remita.webservices.PaymentNotificationListenerWebservice'
     327            ' - %s - successful payment: %s'
     328            % (self.applicant.applicant_id, self.orderId) in logcontent)
    226329        return
    227330
Note: See TracChangeset for help on using the changeset viewer.