<?php
$secret = 'MySecretFromSiruMobile';
$fields = [
'variant' => 'variant1',
'merchantId' => '123123',
'purchaseCountry' => 'FI',
'basePrice' => '12.34',
'taxClass' => 3,
'serviceGroup' => 3,
'customerFirstname' => '',
'customerLastname' => null,
'customerNumber' => '050 123 4567',
];
$fields = array_filter($fields); // Drop empty fields
echo 'UNSORTED<br>';
$signature = hash_hmac("sha512", implode(';', $fields), $secret);
ksort($fields); // Sort by field name
foreach ($fields as $key => $val) {
echo "$key = $val<br>";
}
echo '<br>';
echo 'SORTED<br>';
foreach ($fields as $key => $val) {
echo "$key = $val<br>";
}
echo '<br>';
$signature = hash_hmac("sha512", implode(';', $fields), $secret);
echo $signature;
?>
preferences:
48.97 ms | 402 KiB | 5 Q