Skip to content
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/.idea
.idea
/.buildpath
/.project
/.settings
vendor
9 changes: 8 additions & 1 deletion src/BitWeb/BankLink/BankLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace BitWeb\BankLink;

use BitWeb\BankLink\Swedbank\SwedBank;
/**
* Main BankLink class that represents actions for bank links
*
Expand Down Expand Up @@ -605,11 +606,17 @@ private function getMacSource()
if (null === $value) {
throw new Exception('"' . $order . '" has to be setted');
}
$data .= str_pad(strlen($value), 3, '0', STR_PAD_LEFT) . $value;
$length = $this->getValueStringLength($value);
$data .= str_pad($length, 3, '0', STR_PAD_LEFT) . $value;
}
return $data;
}

protected function getValueStringLength($value)
{
return strlen($value);
}

/**
* Load values from request. And sets into parameters
* @param array $data Where to load values. Default is $_REQUEST
Expand Down
6 changes: 3 additions & 3 deletions src/BitWeb/BankLink/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ abstract class Constants
* Saaja konto number
*/
const ACC = 'VK_ACC';
const ACC_LENGTH = 16;
const ACC_LENGTH = 20;

/**
* Maksekorralduse viitenumber
Expand All @@ -74,13 +74,13 @@ abstract class Constants
* Saaja konto number
*/
const REC_ACC = 'VK_REC_ACC';
const REC_ACC_LENGTH = 16;
const REC_ACC_LENGTH = 20;

/**
* Maksja konto number
*/
const SND_ACC = 'VK_SND_ACC';
const SND_ACC_LENGTH = 16;
const SND_ACC_LENGTH = 20;

/**
* Maksekorralduse kuupäev
Expand Down
5 changes: 1 addition & 4 deletions src/BitWeb/BankLink/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ public function getField()

public function getFormattedValue()
{
if (strstr($this->value, 'õ') || strstr($this->value, 'Ü')) {
return (string)trim(substr($this->value, 0, $this->length - 1));
}
return (string)trim(substr($this->value, 0, $this->length));
return (string)trim(mb_substr($this->value, 0, $this->length));
}

public function getValue()
Expand Down
2 changes: 2 additions & 0 deletions src/BitWeb/BankLink/Swedbank/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ abstract class Constants extends BankLink\Constants
const SND_NAME_LENGTH = 40;
const RETURN_URL_LENGTH = 60;
const BANK_ID = 'HP';
const ENCODING = 'VK_ENCODING';
const ENCODING_LENGTH = 10;
}
11 changes: 11 additions & 0 deletions src/BitWeb/BankLink/Swedbank/SwedBank.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@ final class SwedBank extends BankLink
* @var string
*/
protected $bankId = Constants::BANK_ID;

/**
* @var string
*/
private $encoding = 'UTF-8';

/* (non-PHPdoc)
* @see BankLink/BankLink#setSpecificParameters()
*/
protected function setSpecificParameters()
{
$this->addParameter(Constants::MAC, Constants::MAC_LENGTH);
$this->addParameter(Constants::ENCODING, Constants::ENCODING_LENGTH, $this->encoding);
}

/**
Expand Down Expand Up @@ -100,6 +106,7 @@ protected function create1101()
$this->addMacParameter(Constants::T_DATE, Constants::T_DATE_LENGTH);
$this->addParameter(Constants::LANG, Constants::LANG_LENGTH, $this->langauge);
$this->addParameter(Constants::AUTO, Constants::AUTO_LENGTH);
$this->addParameter(Constants::ENCODING, Constants::ENCODING_LENGTH, $this->encoding);
}

/**
Expand Down Expand Up @@ -149,4 +156,8 @@ protected function create4001()
$this->addMacParameter(Constants::TIME, Constants::TIME_LENGTH);
}

protected function getValueStringLength($value)
{
return mb_strlen($value, 'UTF-8');
}
}