Skip to content

Commit

Permalink
calculation revisionin md5sum and sign (#21)
Browse files Browse the repository at this point in the history
md5sum and card methods sign calculation update
  • Loading branch information
SzczepaniakG committed May 19, 2021
1 parent 3dd127e commit c920633
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
28 changes: 21 additions & 7 deletions tpayLibs/src/_class_tpay/CardApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function registerSaleMethod(
if ($this->enablePowUrl) {
$params['enable_pow_url'] = 1;
}
$params[CardDictionary::SIGN] = hash($this->cardHashAlg, implode('', $params) . $this->cardVerificationCode);
$params[CardDictionary::SIGN] = hash($this->cardHashAlg, implode('&', $params) .'&'. $this->cardVerificationCode);
$params[CardDictionary::APIPASS] = $this->cardApiPass;
$params = array_merge($params, $this->checkReturnUrls());
if (!is_null($this->moduleName)) {
Expand Down Expand Up @@ -96,9 +96,17 @@ public function presaleMethod($saleDescription) {
if (!empty($this->orderID)) {
$params[CardDictionary::ORDERID] = $this->orderID;
}
$params[CardDictionary::SIGN] = hash($this->cardHashAlg, CardDictionary::PRESALE . $this->clientAuthCode .
$saleDescription . $this->amount . $this->currency . $this->orderID . $this->lang .
$this->cardVerificationCode);
$hashParams = [
CardDictionary::PRESALE,
$this->clientAuthCode,
$saleDescription,
$this->amount,
$this->currency,
$this->orderID,
$this->lang,
$this->cardVerificationCode,
];
$params[CardDictionary::SIGN] = hash($this->cardHashAlg, implode('&', $hashParams));
$params[CardDictionary::APIPASS] = $this->cardApiPass;
Util::log('Pre sale params with hash ',
print_r($params, true) . 'req url ' . $this->cardsApiURL . $this->cardApiKey);
Expand All @@ -125,8 +133,14 @@ public function saleMethod($saleAuthCode) {
CardDictionary::CLIAUTH => $this->clientAuthCode,
CardDictionary::SALEAUTH => $saleAuthCode,
);
$params[CardDictionary::SIGN] = hash($this->cardHashAlg, CardDictionary::SALE .
$this->clientAuthCode . $saleAuthCode . $this->cardVerificationCode);
$hashParams = [
CardDictionary::SALE,
$this->clientAuthCode,
$saleAuthCode,
$this->cardVerificationCode,
];

$params[CardDictionary::SIGN] = hash($this->cardHashAlg, implode('&', $hashParams));
$params[CardDictionary::APIPASS] = $this->cardApiPass;
Util::log('Sale request params', print_r($params, true));

Expand All @@ -145,7 +159,7 @@ public function deregisterClient()
$params[CardDictionary::METHOD] = CardDictionary::DEREGISTER;
$params[CardDictionary::CLIAUTH] = $this->clientAuthCode;
$params[CardDictionary::LANGUAGE] = $this->lang;
$params[CardDictionary::SIGN] = hash($this->cardHashAlg, implode('', $params) . $this->cardVerificationCode);
$params[CardDictionary::SIGN] = hash($this->cardHashAlg, implode('&', $params) .'&'. $this->cardVerificationCode);
$params[CardDictionary::APIPASS] = $this->cardApiPass;

return $this->requests($this->cardsApiURL . $this->cardApiKey, $params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ public function prepareConfig($config, $isApi = false)
$ready = $isApi ? $this->validateConfig(new PaymentTypeBasicApi(), $config) :
$this->validateConfig(new PaymentTypeBasic(), $config);
$crc = isset($ready['crc']) ? $ready['crc'] : '';
$ready['md5sum'] = md5($this->merchantId . $ready['amount'] . $crc . $this->merchantSecret);

$md5Params = [
$this->merchantId,
$ready['amount'],
$crc,
$this->merchantSecret,
];
$ready['md5sum'] = md5(implode('&', $md5Params));
$ready['id'] = $this->merchantId;

return $ready;
Expand Down
2 changes: 1 addition & 1 deletion tpayLibs/src/_class_tpay/Refunds/CardRefunds.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function refund($saleAuthCode, $refundDesc)
}
$params[CardDictionary::CURRENCY] = $this->currency;
$params[CardDictionary::LANGUAGE] = $this->lang;
$params[CardDictionary::SIGN] = hash($this->cardHashAlg, implode('', $params) . $this->cardVerificationCode);
$params[CardDictionary::SIGN] = hash($this->cardHashAlg, implode('&', $params) .'&'. $this->cardVerificationCode);
$params[CardDictionary::APIPASS] = $this->cardApiPass;
Util::log('Card refund', print_r($params, true));
$result = $this->requests($this->cardsApiURL . $this->cardApiKey, $params);
Expand Down

0 comments on commit c920633

Please sign in to comment.