Hello,

I'm working on some code to authorize and settle directly with Vital. Some of the inspiration and code samples have come from the Perl module Business::OnlinePayment::VirtualNet.

Things are working good approximately 99% of the time. However, my communication is getting Nak'd on settlement before getting to Vital. When I reassign my batches, it comes down to one transaction that is causing the problem. I believe the problem is either in my LRC (longitudinal redundancy check) calculation or my conversion of the string to even parity.

I'm hoping there is someone out there that knows more about LRC and even parity than I do that can look over the below functions to see if they are calculating the LRC and even parity correctly. In the last 3 that have gotten Nak'd, it appears the commonality between the transactions is that my LRC value is a 'nul' character (0000000 binary) on the detail record. So I'm either thinking that I'm not converting the nul character to even parity correctly or my LRC is slightly off and it shouldn't be a nul character.

If there may be functions in PHP that I'm overlooking that could do this easier for me, please let me know as well. Thanks to anyone you might lend some advice.

Here are my functions:

/************* LRC ************************/
/*** taken from Perl module String::LRC ***/

function lrc($buffer)
{
        $len = 0;
        if (isset($buffer) && !empty($buffer)){
                $len = strlen($buffer);
        }
        $check = substr($buffer, 0, 1);
        for ($i = 1; $i < $len ; $i++) {
                $check ^= substr($buffer, $i, 1);
        }
        return $check;
}

/************* Set Even Parity *******************/
function setEvenParity($str)
{
        $chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);
        foreach ($chars as $key => $val){
                $chars[$key] = evenParityChar($val);
        }
        return implode("", $chars);
}
        

function evenParityChar($char)
{
        $bin = sprintf("%07b",ord($char));
        $check = substr($bin, 0, 1);
        for ($i = 1; $i < strlen($bin); $i++){
                $check ^= substr($bin, $i, 1);
        }
        $dec = pack('C', bindec($check . $bin));
        return $dec;
}

Thanks,
Dominic

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to