<?php
define ('HMAC_SHA256', 'sha256');
define ('SECRET_KEY', 'cafe7ee2cc4c414bb5ea9c1246315917f2b2894df0fa40bf8f655132dc80afcb4d544e7f678e48198c31949eb75513454db4e966f0f2431a83e54a71b9a8c7ac4ef525817a0348b4ac4d0d7c56d278b8b826ef00ba5246beb98d9f58d296ef7e8ac816568b0f44859384e67a51d426f9f94ccd5d4ec14b18ba74472e3adb6021');
function sign ($params) {
  return signData(buildDataToSign($params), SECRET_KEY);
}
function signData($data, $secretKey) {
    return base64_encode(hash_hmac('sha256', $data, $secretKey, true));
}
function buildDataToSign($params) {
        $signedFieldNames = explode(",",$params["signed_field_names"]);
        foreach ($signedFieldNames as $field) {
           $dataToSign[] = $field . "=" . $params[$field];
        }
        return commaSeparate($dataToSign);
}
function commaSeparate ($dataToSign) {
    return implode(",",$dataToSign);
}
?>
