-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5120cb4
commit 34ad9ba
Showing
26 changed files
with
2,124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/.idea/ | ||
/.settings/ | ||
/vendor/ | ||
/tests/build/ | ||
.project | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
filter: | ||
paths: ["src/*"] | ||
tools: | ||
external_code_coverage: true | ||
php_code_coverage: true | ||
php_sim: true | ||
php_mess_detector: true | ||
php_pdepend: true | ||
php_analyzer: true | ||
php_cpd: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
language: php | ||
php: | ||
- 5.5 | ||
- 5.6 | ||
- hhvm | ||
- 7 | ||
script: | ||
- phpunit -c tests/phpunit.xml --coverage-clover=coverage.clover | ||
before_script: | ||
- composer install | ||
after_script: | ||
- wget https://scrutinizer-ci.com/ocular.phar | ||
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name" : "genkgo/camt", | ||
"require" : { | ||
"php" : ">=5.5", | ||
"jschaedl/iban": "~1.1.0", | ||
"mathiasverraes/money": "~1.2.1" | ||
}, | ||
"require-dev" : { | ||
"phpunit/phpunit" : "~4.0", | ||
"phpunit/phpunit-mock-objects" : "2.3.0" | ||
}, | ||
"autoload" : { | ||
"psr-4" : { | ||
"Genkgo\\Camt\\" : [ | ||
"src", | ||
"tests" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
namespace Genkgo\Camt\Camt053; | ||
|
||
use Genkgo\Camt\Iban; | ||
|
||
/** | ||
* Class Account | ||
* @package Genkgo\Camt\Camt053 | ||
*/ | ||
class Account { | ||
|
||
|
||
/** | ||
* @var Iban | ||
*/ | ||
private $iban; | ||
|
||
public function __construct(Iban $iban) | ||
{ | ||
$this->iban = $iban; | ||
} | ||
|
||
/** | ||
* @return Iban | ||
*/ | ||
public function getIban() | ||
{ | ||
return $this->iban; | ||
} | ||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
namespace Genkgo\Camt\Camt053; | ||
|
||
use DateTimeImmutable; | ||
use Money\Money; | ||
|
||
/** | ||
* Class Balance | ||
* @package Genkgo\Camt\Camt053 | ||
*/ | ||
class Balance { | ||
|
||
/** | ||
* | ||
*/ | ||
const TYPE_OPENING = 'start'; | ||
/** | ||
* | ||
*/ | ||
const TYPE_CLOSING = 'closing'; | ||
|
||
/** | ||
* @var Money | ||
*/ | ||
private $amount; | ||
/** | ||
* @var string | ||
*/ | ||
private $type; | ||
|
||
/** | ||
* @var DateTimeImmutable | ||
*/ | ||
private $date; | ||
|
||
/** | ||
* @param Money $amount | ||
* @param $type | ||
*/ | ||
private function __construct ($type, Money $amount, DateTimeImmutable $date) { | ||
$this->type = $type; | ||
$this->amount = $amount; | ||
$this->date = $date; | ||
} | ||
|
||
/** | ||
* @return Money | ||
*/ | ||
public function getAmount() | ||
{ | ||
return $this->amount; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getType() | ||
{ | ||
return $this->type; | ||
} | ||
|
||
/** | ||
* @param Money $amount | ||
* @return static | ||
*/ | ||
public static function opening(Money $amount, DateTimeImmutable $date) { | ||
return new static (self::TYPE_OPENING, $amount, $date); | ||
} | ||
|
||
/** | ||
* @param Money $amount | ||
* @return static | ||
*/ | ||
public static function closing (Money $amount, DateTimeImmutable $date) { | ||
return new static (self::TYPE_CLOSING, $amount, $date); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
namespace Genkgo\Camt\Camt053; | ||
|
||
class Entry { | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
namespace Genkgo\Camt\Camt053; | ||
|
||
/** | ||
* Class GroupHeader | ||
* @package Genkgo\Camt\Camt053 | ||
*/ | ||
class GroupHeader { | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $messageId; | ||
/** | ||
* @var \DateTimeImmutable | ||
*/ | ||
private $createdOn; | ||
|
||
/** | ||
* @param $messageId | ||
* @param \DateTimeImmutable $createdOn | ||
*/ | ||
public function __construct($messageId, \DateTimeImmutable $createdOn) | ||
{ | ||
$this->messageId = $messageId; | ||
$this->createdOn = $createdOn; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getMessageId() | ||
{ | ||
return $this->messageId; | ||
} | ||
|
||
/** | ||
* @return \DateTimeImmutable | ||
*/ | ||
public function getCreatedOn() | ||
{ | ||
return $this->createdOn; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<?php | ||
namespace Genkgo\Camt\Camt053; | ||
|
||
use DateTimeImmutable; | ||
use DOMDocument; | ||
use Genkgo\Camt\Exception\InvalidMessageException; | ||
use Genkgo\Camt\Iban; | ||
use Money\Currency; | ||
use Money\Money; | ||
|
||
/** | ||
* Class Message | ||
* @package Genkgo\Camt\Camt053 | ||
*/ | ||
class Message { | ||
|
||
/** | ||
* @var \SimpleXMLElement[] | ||
*/ | ||
private $document; | ||
/** | ||
* @var | ||
*/ | ||
private $groupHeader; | ||
/** | ||
* @var | ||
*/ | ||
private $statements; | ||
|
||
/** | ||
* @param DOMDocument $document | ||
* @throws InvalidMessageException | ||
*/ | ||
public function __construct(DOMDocument $document) { | ||
$this->validate($document); | ||
$this->document = simplexml_import_dom($document); | ||
} | ||
|
||
/** | ||
* @return GroupHeader | ||
*/ | ||
public function getGroupHeader() { | ||
if ($this->groupHeader === null) { | ||
$groupHeaderXml = $this->document->BkToCstmrStmt->GrpHdr; | ||
|
||
$this->groupHeader = new GroupHeader( | ||
(string) $groupHeaderXml->MsgId, | ||
new DateTimeImmutable((string) $groupHeaderXml->CreDtTm) | ||
); | ||
} | ||
|
||
return $this->groupHeader; | ||
} | ||
|
||
/** | ||
* @return Statement[] | ||
*/ | ||
public function getStatements() { | ||
if ($this->statements === null) { | ||
$this->statements = []; | ||
|
||
$statementsXml = $this->document->BkToCstmrStmt->Stmt; | ||
foreach ($statementsXml as $statementXml) { | ||
$statement = new Statement( | ||
$statementXml->Id, | ||
new DateTimeImmutable((string) $statementXml->CreDtTm), | ||
new Account(new Iban((string) $statementXml->Acct->Id->IBAN)) | ||
); | ||
|
||
$this->addBalancesToStatement($statementXml, $statement); | ||
|
||
$this->statements[] = $statement; | ||
} | ||
|
||
} | ||
|
||
return $this->statements; | ||
} | ||
|
||
/** | ||
* @param DOMDocument $document | ||
* @throws InvalidMessageException | ||
*/ | ||
private function validate (DOMDocument $document) { | ||
libxml_use_internal_errors(true); | ||
$valid = $document->schemaValidate(dirname(dirname(__DIR__)).'/assets/camt.053.001.02.xsd', LIBXML_SCHEMA_CREATE); | ||
$errors = libxml_get_errors(); | ||
libxml_clear_errors(); | ||
|
||
if (!$valid) { | ||
throw new InvalidMessageException("Provided XML is not valid according to the XSD"); | ||
} | ||
} | ||
|
||
/** | ||
* @param $statementXml | ||
* @param $statement | ||
*/ | ||
private function addBalancesToStatement($statementXml, $statement) | ||
{ | ||
$balancesXml = $statementXml->Bal; | ||
foreach ($balancesXml as $balanceXml) { | ||
$amount = (string)$balanceXml->Amt; | ||
$currency = (string)$balanceXml->Amt['Ccy']; | ||
$date = (string)$balanceXml->Dt->Dt; | ||
|
||
if ($balanceXml->Tp->CdOrPrtry->Cd === 'OPBD') { | ||
$balance = Balance::opening( | ||
new Money( | ||
Money::stringToUnits($amount), | ||
new Currency($currency) | ||
), | ||
new DateTimeImmutable($date) | ||
); | ||
} else { | ||
$balance = Balance::closing( | ||
new Money( | ||
Money::stringToUnits($amount), | ||
new Currency($currency) | ||
), | ||
new DateTimeImmutable($date) | ||
); | ||
} | ||
|
||
$statement->addBalance($balance); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
namespace Genkgo\Camt\Camt053; | ||
|
||
use DOMDocument; | ||
use Genkgo\Camt\MessageFormatInterface; | ||
|
||
class MessageFormat implements MessageFormatInterface { | ||
|
||
public function getXmlNs() | ||
{ | ||
return 'urn:iso:std:iso:20022:tech:xsd:camt.053.001.02'; | ||
} | ||
|
||
public function getMsgId() | ||
{ | ||
return 'camt.053.001.02'; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'BankToCustomerStatementV02'; | ||
} | ||
|
||
public function getMessage(DOMDocument $document) | ||
{ | ||
return new Message($document); | ||
} | ||
|
||
} |
Oops, something went wrong.