Skip to content

Commit

Permalink
php71 support hmac-sha512
Browse files Browse the repository at this point in the history
  • Loading branch information
DoubleTime committed Jan 27, 2025
1 parent ca67aa0 commit 701d7ac
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ protected function guardParameters()
);
}

protected function createSignatureFromString($fullStringToHash)
protected function createSignatureFromString($fullStringToHash, $merchantKey)
{
return hash('sha256', $fullStringToHash);
return hash_hmac('sha512', $fullStringToHash, $merchantKey);
}

// private function hex2bin($hexSource)
Expand Down
2 changes: 1 addition & 1 deletion src/Message/CompletePurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ protected function signature($merchantKey, $merchantCode, $paymentId, $refNo, $a

$paramsInArray = [$merchantKey, $merchantCode, $paymentId, $refNo, $amount, $currency, $status];

return $this->createSignatureFromString(implode('', $paramsInArray));
return $this->createSignatureFromString(implode('', $paramsInArray), $merchantKey);
}
}
5 changes: 2 additions & 3 deletions src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function getData()
'UserContact' => $this->getCard()->getNumber(),
'Remark' => '',
'Lang' => '',
'SignatureType' => 'SHA256',
'SignatureType' => 'HMAC-SHA512',
'Signature' => $this->signature(
$this->getMerchantKey(),
$this->getMerchantCode(),
Expand All @@ -44,7 +44,6 @@ private function signature($merchantKey, $merchantCode, $refNo, $amount, $curren

$paramsInArray = [$merchantKey, $merchantCode, $refNo, $amount, $currency];

return $this->createSignatureFromString(implode('', $paramsInArray));
return $this->createSignatureFromString(implode('', $paramsInArray), $merchantKey);
}

}

0 comments on commit 701d7ac

Please sign in to comment.