Do autoryzacji płatności wykorzystywana jest sygnatura, którą wyliczamy w następujący sposób:

  1. Sortujemy alfabetycznie, rosnąco, po kluczach parametry zamówienia.
  2. Łączymy parametry w następujący sposób: parametr1=wartosc1&parametr2=wartosc2...parametrN=wartoscN. Wynik zapisujemy do zmiennej (zwanej dalej body).
  3. Wyliczamy sygnaturę metodą hashowania sha224, sha256, sha384 lub sha512 np. sha256(body + serviceKey. Wynik hashowania zapisujemy do zmiennej (zwanej dalej signature).
  4. 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;