0
1
Fork 0
hedera-web-mindshore/rest/tpv/transaction.php

57 lines
1.7 KiB
PHP
Raw Normal View History

2016-07-22 20:00:27 +00:00
<?php
/**
* Starts a new TPV transaction and returns the params.
**/
2016-08-23 13:15:19 +00:00
class Transaction extends Vn\Web\JsonRequest
2016-07-22 20:00:27 +00:00
{
2016-09-06 14:25:02 +00:00
const PARAMS = ['amount'];
2016-07-22 20:00:27 +00:00
2016-09-06 14:25:02 +00:00
function run ($db)
{
2016-07-22 20:00:27 +00:00
$amount = (int) $_REQUEST['amount'];
$companyId = empty ($_REQUEST['company']) ? NULL : $_REQUEST['company'];
2016-08-25 10:47:09 +00:00
$row = $db->getRow ('CALL transactionStart (#, #)',
2016-07-22 20:00:27 +00:00
[$amount, $companyId]);
if (!isset ($row))
throw new Exception ('Transaction error');
$transactionId = str_pad ($row['transactionId'], 12, '0', STR_PAD_LEFT);
2016-07-22 20:00:27 +00:00
$urlOk = empty ($_REQUEST['urlOk']) ? '' : sprintf ($_REQUEST['urlOk'], $transactionId);
$urlKo = empty ($_REQUEST['urlKo']) ? '' : sprintf ($_REQUEST['urlKo'], $transactionId);
$merchantUrl = $row['merchantUrl'] ? $row['merchantUrl'] : '';
2016-07-22 20:00:27 +00:00
$params = [
'Ds_Merchant_Amount' => $amount
,'Ds_Merchant_Order' => $transactionId
,'Ds_Merchant_MerchantCode' => $row['merchant']
,'Ds_Merchant_Currency' => $row['currency']
,'Ds_Merchant_TransactionType' => $row['transactionType']
2016-07-22 20:00:27 +00:00
,'Ds_Merchant_Terminal' => $row['terminal']
,'Ds_Merchant_MerchantURL' => $merchantUrl
,'Ds_Merchant_UrlOK' => $urlOk
,'Ds_Merchant_UrlKO' => $urlKo
];
$encodedParams = base64_encode (json_encode ($params));
$key = base64_decode ($row['secretKey']);
2016-07-22 20:00:27 +00:00
$bytes = [0, 0, 0, 0, 0, 0, 0, 0];
$iv = implode (array_map ('chr', $bytes));
$key = mcrypt_encrypt (MCRYPT_3DES, $key, $transactionId, MCRYPT_MODE_CBC, $iv);
$signature = base64_encode (hash_hmac ('sha256', $encodedParams, $key, TRUE));
$url = $row['url'];
2016-08-25 10:47:09 +00:00
return [
2016-07-22 20:00:27 +00:00
'url' => $url
,'params' => $encodedParams
,'signature' => $signature
2016-08-25 10:47:09 +00:00
];
2016-07-22 20:00:27 +00:00
}
}