<?php

define ('HMAC_SHA256', 'sha256');
//define ('SECRET_KEY', '63de783eb06d4ea58601f421fdba153fd25d6eaeecc6435291daa42b38538078da57824774b04988b114a2c4133607421a9a168fdcb7487ab7f773396f6e2f235575fb5da9bb49f6bf8c256d962550c91f8733fa0d1f4ce38ed21b12ad04118e82081f2537d7476a9fee508fe198c33e9ce7bcefc24343c8a953d1e46f8b2b52');
define ('SECRET_KEY', '30a90fad3c184f6eba75c49f5cfec10af453ad1af0d547da86178905cdbf26a45db109295ee44edab2e9415bcd7b99abd44f98cc2a8d49eeb7830755e9db9549c5f11e86e2f44aca89598066ec7b631412e18a032f58422089dd5dd9e69f2c7237786b8149514801a9b31334eca9e79cb726673ffd5e41a19e5ef5ce527ee950');


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);
}

?>