"1012",
"VK_VERSION" => "008",
"VK_SND_ID" => "uid100052",
"VK_STAMP" => "5",
"VK_AMOUNT" => "3129.84",
"VK_CURR" => "EUR",
"VK_MSG" => "My cool payment",
"VK_RETURN" => "http://localhost:50878/banks/thorbanks_response/",
"VK_CANCEL" => "http://localhost:50878/banks/thorbanks_response/",
"VK_DATETIME" => "2023-09-27T11:52:19+0000",
"VK_LANG" => "EST",
"VK_ENCODING" => "UTF-8"
);
// STEP 3. Generate data to be signed
// ==================================
// Data to be signed is in the form of XXXYYYYY where XXX is 3 char
// zero padded length of the value and YYY the value itself
// NB! Swedbank expects symbol count, not byte count with UTF-8,
// so use `mb_strlen` instead of `strlen` to detect the length of a string
$data = str_pad (mb_strlen($fields["VK_SERVICE"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_SERVICE"] . /* 1012 */
str_pad (mb_strlen($fields["VK_VERSION"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_VERSION"] . /* 008 */
str_pad (mb_strlen($fields["VK_SND_ID"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_SND_ID"] . /* uid100052 */
str_pad (mb_strlen($fields["VK_STAMP"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_STAMP"] . /* 5 */
str_pad (mb_strlen($fields["VK_AMOUNT"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_AMOUNT"] . /* 3129.84 */
str_pad (mb_strlen($fields["VK_CURR"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_CURR"] . /* EUR */
str_pad (mb_strlen($fields["VK_REF"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_REF"] . /* */
str_pad (mb_strlen($fields["VK_MSG"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_MSG"] . /* My cool payment */
str_pad (mb_strlen($fields["VK_RETURN"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_RETURN"] . /* http://localhost:50878/banks/thorbanks_response/ */
str_pad (mb_strlen($fields["VK_CANCEL"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_CANCEL"] . /* http://localhost:50878/banks/thorbanks_response/ */
str_pad (mb_strlen($fields["VK_DATETIME"], "UTF-8"), 3, "0", STR_PAD_LEFT) . $fields["VK_DATETIME"]; /* 2023-09-27T11:52:19+0000 */
/* $data = "0041012003008009uid10005200150073129.84003EUR000015My cool payment048http://localhost:50878/banks/thorbanks_response/048http://localhost:50878/banks/thorbanks_response/0242023-09-27T11:52:19+0000"; */
// STEP 4. Sign the data with RSA-SHA1 to generate MAC code
// ========================================================
openssl_sign ($data, $signature, $private_key, OPENSSL_ALGO_SHA1);
/* iv+Dmqa7sNHUd3VW7Xdk9jRd48HfFxpF/7k9O5b1oeXatdhsPUkz4x5Nevc242seBcTg86tlvXyvnoRZi1foJcLvRi9FRzRXUu3xF7ObCGMw29Dv1R4pCkqt5WbZTFoRmmA2ALENEPnzwODIZ4PQkjidgsF8ZgDYVfEINwCw9rnmY/KyT6erwaJA+S3wRHjoU1X1eEE7ErVI3RowZYa6EnRQl5SgvgyuB1mr3RzyE+QdnaN7DGVOC5+8GTC/Hxq4lPYP4l1CmBx2EuX5K0ccHqShqZyuhtKWGBpsJb2P1Xdh1ovIY5QLH1eVgtxwmJ/AdSLstZ9t7PBTFDBhdxTJDg== */
$fields["VK_MAC"] = base64_encode($signature);
// STEP 5. Generate POST form with payment data that will be sent to the bank
// ==========================================================================
?>
Makse teostamise näidisrakendus "Swedbank"