Ignore:
Timestamp:
13 Dec 2022, 21:15:18 (2 years ago)
Author:
Henrik Bettermann
Message:

Set WebCheckout? parameters.
Adjust tests.

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

Legend:

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

    r17194 r17223  
    2525    InterswitchPaymentVerifyWebservicePageApplicant,
    2626    InterswitchPaymentVerifyWebservicePageStudent,
    27     InterswitchPageStudent, InterswitchPageApplicant,
     27    InterswitchPageStudent,
     28    InterswitchPageApplicant,)
     29from kofacustom.nigeria.interswitch.webcheckoutbrowser import (
     30    WebCheckoutPageStudent,
     31    WebCheckoutPageApplicant,
     32    WebCheckoutConfirmTransactionStudent,
     33    WebCheckoutConfirmTransactionApplicant,
    2834    )
    2935from kofacustom.lpng.students.interfaces import ICustomStudentOnlinePayment
     
    229235    gateway_url = URL
    230236    mac = MAC
     237
     238
     239# WebCheckout customizations
     240
     241class CustomWebCheckoutPageStudent(WebCheckoutPageStudent):
     242    """ View which sends a POST request to the Interswitch
     243    WebCheckout payment gateway.
     244    """
     245    action = 'https://newwebpay.interswitchng.com/collections/w/pay'
     246    currency = '566'
     247    pay_item_id = 'Default_Payable_MX76823'
     248    merchant_code = 'MX76823'
     249    gateway_amt = GATEWAY_AMT
     250
     251class CustomWebCheckoutPageApplicant(WebCheckoutPageApplicant):
     252    """ View which sends a POST request to the Interswitch
     253    WebCheckout payment gateway.
     254    """
     255
     256    action = 'https://newwebpay.interswitchng.com/collections/w/pay'
     257    currency = '566'
     258    pay_item_id = 'Default_Payable_MX76823'
     259    merchant_code = 'MX76823'
     260    gateway_amt = GATEWAY_AMT
     261
     262class CustomWebCheckoutConfirmTransactionStudent(WebCheckoutConfirmTransactionStudent):
     263    """ Request webservice view for the WebCheckout gateway
     264    """
     265    merchant_code = 'MX76823'
     266    gateway_host = 'webpay.interswitchng.com'
     267    gateway_url = '/collections/api/v1/gettransaction.json'
     268    https = True
     269
     270class CustomWebCheckoutConfirmTransactionApplicant(WebCheckoutConfirmTransactionApplicant):
     271    """ Request webservice view for the WebCheckout gateway
     272    """
     273    merchant_code = 'MX76823'
     274    gateway_host = 'webpay.interswitchng.com'
     275    gateway_url = '/collections/api/v1/gettransaction.json'
     276    https = True
     277
     278
  • main/kofacustom.lpng/trunk/src/kofacustom/lpng/interswitch/tests.py

    r17023 r17223  
    2222from hurry.workflow.interfaces import IWorkflowState
    2323from waeup.kofa.students.tests.test_browser import StudentsFullSetup
     24from waeup.kofa.students.payments import StudentOnlinePayment
    2425from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
    2526from waeup.kofa.configuration import SessionConfiguration
     27from kofacustom.nigeria.interswitch.helpers import confirm_transaction
    2628from kofacustom.lpng.testing import FunctionalLayer
    2729
     
    3537        myself = __file__
    3638        if myself.endswith('.pyc'):
    37             myself = myself[:-2]
     39            myself = myself[:-1]
    3840        print "WARNING: external tests are skipped!"
    3941        print "WARNING: edit %s to enable them." % myself
    4042        return
    4143    return func
    42 
    43 
    44 class InterswitchTestsStudents(StudentsFullSetup):
    45     """Tests for the Interswitch payment gateway.
    46     """
    47 
    48     layer = FunctionalLayer
    49 
    50     def setUp(self):
    51         super(InterswitchTestsStudents, self).setUp()
    52         self.app['configuration']['2004'].interswitch_enabled = True
    53 
    54     def test_interswitch_form(self):
    55         # Manager can access InterswitchForm
    56         self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    57         self.browser.open(self.payments_path)
    58         IWorkflowState(self.student).setState('cleared')
    59         self.student.nationality = u'NG'
    60         self.browser.open(self.payments_path + '/addop')
    61         self.browser.getControl(name="form.p_category").value = ['schoolfee']
    62         self.browser.getControl("Create ticket").click()
    63         self.assertMatches('...ticket created...',
    64                            self.browser.contents)
    65         self.browser.open(self.payments_path)
    66         ctrl = self.browser.getControl(name='val_id')
    67         self.value = ctrl.options[0]
    68         self.browser.getLink(self.value).click()
    69         self.assertMatches('...Amount Authorized...',
    70                            self.browser.contents)
    71         self.assertTrue(
    72             '<span>40000.0</span>' in self.browser.contents)
    73         self.payment_url = self.browser.url
    74         self.browser.getLink("Pay via Interswitch", index=0).click()
    75         self.assertTrue('<input type="hidden" name="pay_item_id" value="0000" />' in
    76                            self.browser.contents)
    77         self.assertEqual(self.student.current_mode, 'ug_ft')
    78         self.assertTrue(
    79             '<input type="hidden" name="amount" value="4015000" />' in
    80             self.browser.contents)
    81         self.assertTrue(
    82             'item_name="Annual Membership Fee" item_amt="4000000" bank_id="00" acct_num="00000000"' in
    83             self.browser.contents)
    84 
    85     def test_interswitch_form_ticket_expired(self):
    86         self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    87         acc_payment = createObject('waeup.StudentOnlinePayment')
    88         acc_payment.p_state = 'unpaid'
    89         acc_payment.p_category = 'clearance'
    90         acc_payment.p_id = 'xyz'
    91         acc_payment.pay_item_id = '123'
    92         acc_payment.amount_auth = 1000.0
    93         self.student['payments']['xyz'] = acc_payment
    94         self.browser.open(self.payments_path + '/xyz')
    95         self.browser.getLink("Pay via Interswitch", index=0).click()
    96         self.assertMatches('...<input type="hidden" name="pay_item_id" value="0000" />...',
    97                            self.browser.contents)
    98         self.assertMatches('...Total Amount Authorized:...',
    99                            self.browser.contents)
    100         self.assertEqual(self.student.current_mode, 'ug_ft')
    101         self.assertMatches(
    102             '...<input type="hidden" name="amount" value="115000" />...',
    103             self.browser.contents)
    104         delta = timedelta(days=8)
    105         acc_payment.creation_date -= delta
    106         self.browser.open(self.payments_path + '/xyz')
    107         self.browser.getLink("Pay via Interswitch", index=0).click()
    108         self.assertMatches(
    109             '...This payment ticket is too old. Please create a new ticket...',
    110             self.browser.contents)
    111         delta = timedelta(days=2)
    112         acc_payment.creation_date += delta
    113         self.browser.open(self.payments_path + '/xyz')
    114         self.browser.getLink("Pay via Interswitch", index=0).click()
    115         self.assertMatches('...Total Amount Authorized:...',
    116                            self.browser.contents)
    117 
    118     @external_test
    119     def test_webservice(self):
    120         self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    121         self.browser.open(self.payments_path)
    122         IWorkflowState(self.student).setState('cleared')
    123         self.student.nationality = u'NG'
    124         self.browser.open(self.payments_path + '/addop')
    125         self.browser.getControl(name="form.p_category").value = ['schoolfee']
    126         self.browser.getControl("Create ticket").click()
    127         self.assertMatches('...ticket created...',
    128                            self.browser.contents)
    129         ctrl = self.browser.getControl(name='val_id')
    130         self.value = ctrl.options[0]
    131         self.browser.getLink(self.value).click()
    132         self.payment_url = self.browser.url
    133         # First we have open InterswitchPageStudent to set provider_amt
    134         # and gateway_amt
    135         self.browser.open(self.payment_url + '/goto_interswitch')
    136         # Now we can call the webservice
    137         self.browser.open(self.payment_url + '/request_webservice')
    138         self.assertMatches('...Unsuccessful callback...',
    139                           self.browser.contents)
    140         # The payment is now in state failed ...
    141         self.assertMatches('...<span>Failed</span>...',
    142                           self.browser.contents)
    143         # ... and the catalog has been updated
    144         cat = getUtility(ICatalog, name='payments_catalog')
    145         results = list(
    146             cat.searchResults(p_state=('failed', 'failed')))
    147         self.assertEqual(len(results), 1)
    148         self.assertEqual(results[0].p_state, 'failed')
    149 
    150         # Let's replace the p_id with a valid p_id of the Uniben
    151         # live system. This is definitely not an appropriate
    152         # solution for testing, but we have no choice since
    153         # Interswitch doesn't provide any interface
    154         # for testing.
    155         payment = self.student['payments'][self.value]
    156         payment.p_id = 'p3547789850240'
    157         self.browser.open(self.payment_url + '/request_webservice')
    158         self.assertMatches('...Callback amount does not match...',
    159                           self.browser.contents)
    160         # The payment is now in state failed ...
    161         self.assertMatches('...<span>Failed</span>...',
    162                           self.browser.contents)
    163         # Let's replace the amount autorized with the amount of the
    164         # live system payment
    165         payment.amount_auth = payment.r_amount_approved
    166         self.browser.open(self.payment_url + '/request_webservice')
    167         self.assertMatches('...Successful payment...',
    168                           self.browser.contents)
    169         # The payment is now in state paid ...
    170         self.assertMatches('...<span>Paid</span>...',
    171                           self.browser.contents)
    172         # ... and the catalog has been updated
    173         cat = getUtility(ICatalog, name='payments_catalog')
    174         results = list(
    175             cat.searchResults(p_state=('paid', 'paid')))
    176         self.assertEqual(len(results), 1)
    177         self.assertEqual(results[0].p_state, 'paid')
    178         # Approval is logged in students.log ...
    179         logfile = os.path.join(
    180             self.app['datacenter'].storage, 'logs', 'students.log')
    181         logcontent = open(logfile).read()
    182         self.assertTrue(
    183             'zope.mgr - '
    184             'kofacustom.lpng.interswitch.browser.CustomInterswitchPaymentRequestWebservicePageStudent - '
    185             'X1000000 - successful schoolfee payment: p3547789850240\n'
    186             in logcontent)
    187         # ... and in payments.log
    188         logfile = os.path.join(
    189             self.app['datacenter'].storage, 'logs', 'payments.log')
    190         logcontent = open(logfile).read()
    191         self.assertTrue(
    192             '"zope.mgr",X1000000,p3547789850240,schoolfee,'
    193             '12000.0,00,0.0,150.0,0.0,,,\n'
    194             in logcontent)
    19544
    19645
     
    21867        self.browser.getControl(name="form.email").value = 'xx@yy.zz'
    21968        self.applicantscontainer.application_fee = 1000.0
    220         self.browser.getControl(name="form.nationality").value = ['NG']
    22169        self.browser.getControl(name="transition").value = ['start']
    22270        self.browser.getControl("Save").click()
    223         self.browser.getControl("Pay membership").click()
     71
     72
     73    def test_webcheckout_form(self):
     74        self.browser.getControl("Make").click()
     75        self.browser.getControl(name="form.balance_amount").value = '500'
     76        self.browser.getControl(name="form.p_category").value = ['donation']
     77        self.browser.getControl("Create").click()
     78
    22479        self.assertMatches('...ticket created...',
    22580                           self.browser.contents)
    226         #ctrl = self.browser.getControl(name='val_id')
    227         #value = ctrl.options[0]
    228         #self.browser.getLink(value).click()
     81
    22982        self.assertMatches('...Amount Authorized...',
    23083                           self.browser.contents)
    23184        self.assertMatches(
    232             '...<span>1000.0</span>...',
     85            '...<span>500.0</span>...',
    23386            self.browser.contents)
    23487        self.payment_url = self.browser.url
    235 
    236 
    237     def disabled_test_interswitch_form(self):
    23888        # Manager can access InterswitchForm
    23989        self.browser.getLink("Pay via Interswitch", index=0).click()
     
    251101            self.browser.contents)
    252102
     103
     104# WebCheckout tests
     105
     106    # https://webpay.interswitchng.com/collections/api/v1/gettransaction.json?merchantcode=MX76823&transactionreference=p6709347986663&amount=100
     107
    253108    @external_test
    254     def test_webservice(self):
     109    def test_confirm_transaction(self):
     110        host = 'webpay.interswitchng.com'
     111        url = '/collections/api/v1/gettransaction.json'
     112        https = True
     113        merchant_code = 'MX76823'
     114        payment = StudentOnlinePayment()
     115        payment.p_id ='p4465649308559'
     116        success, msg, log = confirm_transaction(
     117            payment, merchant_code, host, url, https)
     118        self.assertFalse(success)
     119        self.assertTrue('Unsuccessful callback:' in msg)
     120        self.assertTrue('Transaction not Found' in log)
    255121
    256         self.browser.open(self.payment_url + '/request_webservice')
    257         self.assertMatches('...Unsuccessful callback...',
    258                           self.browser.contents)
    259         # The payment is now in state failed
    260         self.assertMatches('...<span>Failed</span>...',
    261                           self.browser.contents)
     122        payment.p_id ='p6709347986663'
     123        payment.amount_auth = 1.0
     124        success, msg, log = confirm_transaction(
     125            payment, merchant_code, host, url, https)
     126        self.assertTrue('Amount Inconsistency' in log)
     127        payment.amount_auth = 100.0
     128        success, msg, log = confirm_transaction(
     129            payment, merchant_code, host, url, https)
     130        self.assertEqual('Successful callback received', msg)
     131        self.assertTrue(success)
     132        self.assertTrue(
     133            "{u'SplitAccounts': [], "
     134            "u'RemittanceAmount': 0, "
     135            "u'MerchantReference': u'p6709347986663', "
     136            "u'PaymentReference': u'FBN|WEB|MX76823|13-12-2022|935097929|608001', "
     137            "u'TransactionDate': u'2022-12-13T01:34:21', "
     138            "u'RetrievalReferenceNumber': u'814212374638', "
     139            "u'ResponseDescription': u'Approved by Financial Institution', "
     140            "u'Amount': 10000, "
     141            "u'CardNumber': u'', "
     142            "u'ResponseCode': u'00', "
     143            "u'BankCode': u'011'}" in log)
Note: See TracChangeset for help on using the changeset viewer.