Ignore:
Timestamp:
18 Dec 2022, 09:24:18 (2 years ago)
Author:
Henrik Bettermann
Message:

Use Mac validation.

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

    r17221 r17231  
    382382# Web checkout helper functions
    383383
    384 def get_JSON_webcheckout_response(merchant_code, transref, host, url, https, amount):
     384def get_JSON_webcheckout_response(merchant_code, transref, host, url,
     385                                  https, amount, mac=None):
     386    amount = int(100 * amount)
     387    hashargs = transref + merchant_code + str(amount) + mac
     388    hashvalue = hashlib.sha512(hashargs).hexdigest()
    385389    headers={
    386390        'Content-Type':'text/xml; charset=utf-8',
     391        'Hash':hashvalue,
    387392    }
    388393    if https:
     
    390395    else:
    391396        h = httplib.HTTPConnection(host)
    392     amount = int(100 * amount)
    393397    args = {'merchantcode': merchant_code,
    394398            'transactionreference': transref,
     
    401405    response = h.getresponse()
    402406    if response.status!=200:
    403         return {'error': 'Connection error (%s, %s)' % (response.status, response.reason)}
     407        return {'error': 'Connection error (%s, %s)' % (
     408            response.status, response.reason)}
    404409    jsonout = response.read()
    405410    parsed_json = json.loads(jsonout)
    406411    return parsed_json
    407412
    408 def confirm_transaction(payment, merchant_code, host, url, https=True):
     413def confirm_transaction(payment, merchant_code, host, url, https, mac):
    409414    jr = get_JSON_webcheckout_response(merchant_code, payment.p_id, host, url,
    410                            https, payment.amount_auth)
     415                           https, payment.amount_auth, mac)
    411416    error = jr.get('error')
    412417    if error:
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/interswitch/tests.py

    r17221 r17231  
    419419    # https://webpay.interswitchng.com/collections/api/v1/gettransaction.json?merchantcode=MX76823&transactionreference=p6709347986663&amount=100
    420420
     421    mac = "uS6U18pC6GFKCpJoZH6J6jlOmR81FSrHkjBRpMaaydNQtywuG0hdB02J56MCqLV8rmzeAkhiaQR2nNcX3EPJePl5ppidImeKSzdunhddQh61UGpZPiS2CxMdAem8ueA1"
     422
    421423    @external_test_3
    422424    def test_confirm_transaction(self):
     
    427429        payment = StudentOnlinePayment()
    428430        payment.p_id ='p4465649308559'
     431        payment.amount_auth = 100000.0
    429432        success, msg, log = confirm_transaction(
    430             payment, merchant_code, host, url, https)
     433            payment, merchant_code, host, url, https, self.mac)
    431434        self.assertFalse(success)
    432435        self.assertTrue('Unsuccessful callback:' in msg)
     
    436439        payment.amount_auth = 1.0
    437440        success, msg, log = confirm_transaction(
    438             payment, merchant_code, host, url, https)
     441            payment, merchant_code, host, url, https, self.mac)
    439442        self.assertTrue('Amount Inconsistency' in log)
    440443        payment.amount_auth = 100.0
    441444        success, msg, log = confirm_transaction(
    442             payment, merchant_code, host, url, https)
     445            payment, merchant_code, host, url, https, self.mac)
    443446        self.assertEqual('Successful callback received', msg)
    444447        self.assertTrue(success)
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/interswitch/webcheckoutbrowser.py

    r17227 r17231  
    267267    https = True
    268268    split_accounts = None
     269    mac = None
    269270
    270271
     
    282283            self.gateway_host,
    283284            self.gateway_url,
    284             self.https)
     285            self.https,
     286            self.mac)
    285287        applicant.writeLogMessage(self, log)
    286288        if not success:
     
    309311    gateway_url = None
    310312    https = True
     313    mac = None
    311314
    312315    def update(self):
     
    323326            self.gateway_host,
    324327            self.gateway_url,
    325             self.https)
     328            self.https,
     329            self.mac)
    326330        student.writeLogMessage(self, log)
    327331        if not success:
Note: See TracChangeset for help on using the changeset viewer.