Search code examples
phphashjoomlapayment-gatewaysha256

eGHL Payment: Hash value mismatched. if passing multiple parameter in url with '&'


I am implementing eGHL payment method with PHP. I have a found a weird error on their api or may be in PHP.

I am generating a hash using hash().

<?php   $callback = 'http://localhost/test/eghl.php?query=abce123';

        $orderid = '2512718999';
        $amount = '81.50';
        $currency = 'MYR';
        $merchant = 'IDNOXXXXX';
        $password = 'PASSXXXXX';
        $ip = '127.0.0.1';
        $timeout = '600';

        $string = $password . $merchant . $orderid . $callback . $amount . $currency . $ip . $timeout;

        $hash = hash('sha256', $string);
?>

then put these values into form

<form action="https://test2pay.ghl.com/IPGSG/Payment.aspx" method="post" name="adminForm" enctype="multipart/form-data">


            <p>
                <strong>eGHL Payments </strong>
            </p>

            <input name="TransactionType" value="SALE" type="hidden"> 
            <input name="PymtMethod" value="ANY" type="hidden"> 
            <input name="ServiceID" value="<?php echo $merchant; ?>" type="hidden"> 
            <input name="PaymentID" value="<?php echo $orderid; ?>" type="hidden">
            <input name="OrderNumber" value="<?php echo $orderid; ?>" type="hidden">
            <input name="PaymentDesc" value="Demo - #<?php echo $orderid; ?>" type="hidden"> 
            <input name="MerchantReturnURL" value="<?php echo $callback; ?>" type="hidden">
            <input name="Amount" value="<?php echo $amount; ?>" type="hidden"> 
            <input name="CurrencyCode" value="<?php echo $currency; ?>" type="hidden"> 
            <input name="CustIP" value="<?php echo $ip; ?>" type="hidden"> 
            <input name="CustName" value="Suraj Mishra" type="hidden"> 
            <input name="CustEmail" value="demo@example.com" type="hidden"> 
            <input name="CustPhone" value="9876543210" type="hidden"> 
            <input name="PageTimeout" value="<?php echo $timeout; ?>" type="hidden"> 
            <input name="HashValue" value="<?php echo $hash; ?>" type="hidden"> 
            <input class="k2store_checkout_button btn btn-primary" value="Click Here to Complete Order" type="submit">
            <input name="order_id" value="1512718995" type="hidden">
            <input name="orderpayment_id" value="53" type="hidden">
            <input name="orderpayment_type" value="payment_eghl" type="hidden">
            <input name="task" value="confirmPayment" type="hidden">
          <!-- I am making a plugin for k2Store in joomla so i need to use view & task parameters too or do you know any better way ? !-->
        </form>

Everything till fine yet but the error comes when i add some more parameters in $callback url

http://localhost/test/eghl.php?query=abce123&another=value123

Then eGHL getting this error response Hash value mismatched.

Array
(
    [query] => abce123
    [test] => value
    [TransactionType] => SALE
    [PymtMethod] => CC
    [ServiceID] => IDNOXXXXX
    [PaymentID] => 2512718999
    [OrderNumber] => 2512718999
    [Amount] => 81.50
    [CurrencyCode] => MYR
    [TxnID] => 
    [TxnStatus] => 1
    [Param6] => 
    [Param7] => 
    [TxnMessage] => Hash value mismatched.
    [HashValue] => 1fff3118058ee7c87d70cd0b43b0f8a018ffa1c88bcf0951c08ff6606219e775
    [HashValue2] => 7516c7fd788d36a6bae8a10b57b647c6f79e30f3f10dc387b6dd4c4650a11341
)

I have tried urlencode but not helpful in this case I need it because I have to build my callback url in following format required for work with k2Store Plugin _postpayment dispatcher.

http://localhost/joomla/index.php?option=com_k2store&view=checkout&task=confirmPayment&orderpayment_type=payment_eghl

if i removed & from $callback its give me successful response like this

[Amount] => 81.50
[CurrencyCode] => MYR
[HashValue] => 7c9a56fee7f7f5c16af4f3b5075e4d836e9ae1a1d9dacb96aea5349222be5f7d
[HashValue2] => 333eb4135c2b94330feca670c0c0815f038e4da3ed571e2daf7f462b4ba44d02
[TxnID] => sit00000000002512728991
[IssuingBank] => HostSim
[TxnStatus] => 0
[AuthCode] => sit000
[BankRefNo] => sit00000000002512728991
[TokenType] => OCP
[Token] => xTyQRgpPE2bZtv96KeBQtw==
[RespTime] => 2017-12-08 20:39:49
[TxnMessage] => Transaction Successful

Any help would be appreciated and most welcome


Solution

  • You need to replace & with ; in your URL