Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

Converting the sign key from hex to byte format. #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions PaymentDatatrans.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public function processPostSale()
}

// Validate HMAC sign
if ($this->Input->post('sign2') != hash_hmac('md5', $this->datatrans_id.$this->Input->post('amount').$this->Input->post('currency').$this->Input->post('uppTransactionId'), $this->datatrans_sign))
{
if ($this->Input->post('sign2') != hash_hmac('md5', $this->datatrans_id.$this->Input->post('amount').$this->Input->post('currency').$this->Input->post('uppTransactionId'), $this->convertHexStringToByteString($this->datatrans_sign)))
{
$this->log('Invalid HMAC signature for Order ID ' . $this->Input->post('refno'), __METHOD__, TL_ERROR);
return false;
}
Expand Down Expand Up @@ -173,7 +173,7 @@ public function checkoutForm()
);

// Security signature (see Security Level 2)
$arrParams['sign'] = hash_hmac('md5', $arrParams['merchantId'].$arrParams['amount'].$arrParams['currency'].$arrParams['refno'], $this->datatrans_sign);
$arrParams['sign'] = hash_hmac('md5', $arrParams['merchantId'].$arrParams['amount'].$arrParams['currency'].$arrParams['refno'], $this->convertHexStringToByteString($this->datatrans_sign));

$objTemplate = new FrontendTemplate('iso_payment_datatrans');
$objTemplate->id = $this->id;
Expand All @@ -185,7 +185,17 @@ public function checkoutForm()

return $objTemplate->parse();
}


/**
* Converts the sign key from the hex format you get from the Datatrans interface to the byte format that is needed to actually hash transaction requests
* @param $hexString String The sign key from the datatrans interface
* @return string The byte-formatted sign key needed as the key to hash the request parameters
*/
private function convertHexStringToByteString($hexString) {
$result = "";
for($i=0;$i<strlen($hexString);$i += 2) $result .= chr(hexdec($hexString[$i].$hexString[$i+1]));
return $result;
}

/**
* Validate array of post parameter agains required values
Expand Down
4 changes: 4 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ After this please log in your datatrans admin panel and insert the correct url's

For more security please activate the sign parameter security. Only with this your payment
process is 100% secured. You can generate the sign parameter in the datatrans admin panel.

Note:
If you use the sign parameter, it is automatically converted to byte format for you.
Just copy it from the DataTrans control panel and isotope-datatrans converts it for you.
2 changes: 1 addition & 1 deletion languages/de/tl_iso_payment_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
* Fields
*/
$GLOBALS['TL_LANG']['tl_iso_payment_modules']['datatrans_id'] = array('Merchant-ID', 'Bitte geben Sie ihre Datatrans Merchant-ID ein.');
$GLOBALS['TL_LANG']['tl_iso_payment_modules']['datatrans_sign'] = array('HMAC-Schlüssel', 'Bitte geben Sie den HMAC-Schlüssel aus Ihrem Datatrans Control Panel ein.');
$GLOBALS['TL_LANG']['tl_iso_payment_modules']['datatrans_sign'] = array('HMAC-Schlüssel', 'Bitte geben Sie den HMAC-Schlüssel aus Ihrem Datatrans Control Panel ein (wie dort angezeigt, er wird automatisch konvertiert).');

2 changes: 1 addition & 1 deletion languages/en/tl_iso_payment_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
* Fields
*/
$GLOBALS['TL_LANG']['tl_iso_payment_modules']['datatrans_id'] = array('Merchant-ID', 'Please enter your merchant ID.');
$GLOBALS['TL_LANG']['tl_iso_payment_modules']['datatrans_sign'] = array('HMAC Key', 'Please enter your HMAC key from the Datatrans control panel.');
$GLOBALS['TL_LANG']['tl_iso_payment_modules']['datatrans_sign'] = array('HMAC Key', 'Please enter your HMAC key from the Datatrans control panel (as seen there in hex format, it is automatically converted).');