Do autoryzacji płatności wykorzystywana jest sygnatura, którą wyliczamy w następujący sposób:
- Sortujemy alfabetycznie, rosnąco, po kluczach parametry zamówienia.
- Łączymy parametry w następujący sposób:
parametr1=wartosc1¶metr2=wartosc2...parametrN=wartoscN. Wynik zapisujemy do zmiennej (zwanej dalejbody). - Wyliczamy sygnaturę metodą hashowania
sha224,sha256,sha384lubsha512np.sha256(body + serviceKey. Wynik hashowania zapisujemy do zmiennej (zwanej dalejsignature). - Do wyliczonej sygnatury dopisujemy po średniku użytą metodę hashowania:
signature + ';sha256'.
Przykład wyliczenia sygnatury
/**
* @param array $orderData
* @param string $serviceKey
* @param string $hashMethod
*
* @return string
*/
function createSignature($orderData, $serviceKey, $hashMethod)
{
$data = prepareData($orderData);
return hash($hashMethod, $data . $serviceKey);
}
/**
* @param array $data
* @param string $prefix
*
* @return string
*/
function prepareData(
$data,
$prefix = ''
) {
ksort($data);
$hashData = [];
foreach($data as $key => $value) {
if($prefix) {
$key = $prefix . '[' . $key . ']';
}
if(is_array($value)) {
$hashData[] = prepareData($value, $key);
} else {
$hashData[] = $key . '=' . $value;
}
}
return implode('&', $hashData);
}
$hashMethod = 'sha256';
$serviceKey = 'eAyhFLuHgwl5hu-32GM8QVlCVMWRU0dGjH1c';
$fields = [
'merchantId' => '6yt3gjtm9p1odfgx8491',
'serviceId' => '63f574ed-d90d-4abe-9cs1-39117584a7b',
'amount' => '300',
'currency' => 'PLN',
'orderId' => '123',
'orderDescription' => 'Example transaction',
'customerFirstName' => 'John',
'customerLastName' => 'Doe',
'customerEmail' => 'johndoe@domain.com',
'customerPhone' => '501501501',
'urlSuccess' => 'https://your-shop.com/success',
'urlFailure' => 'https://your-shop.com/failure',
'urlReturn' => 'https://your-shop.com/return',
];
$result = createSignature($fields, $serviceKey, $hashMethod) . ';' . $hashMethod;