Skip to content
This repository has been archived by the owner on Jan 28, 2019. It is now read-only.

Commit

Permalink
v0.2 RC (#9)
Browse files Browse the repository at this point in the history
* Saving progress

* Saving progress

* Update ignore

* Saving

* Update composer and ignore

* Update docblock

* Removed .idea

* Saving

* Saving packer progress

* Added docker container

* More core work

* Abstracted field validation

* Packer and validation progress

* Unpacker progress

* Packer progress

* Packer progress

* CI integration and validation progress

* Update CI

* Added CI badge

* Packer progress

* Test Progress

* Update readme

* CI integration

* Fix namespace

* Coveralls integration

* CI fix

* CI fix

* Coveralls fix

* Coveralls fix

* Coveralls fix

* Fix phpunit coverage

* Fix build logs and add restart to container

* Added license

* Added MessageTypeIndicator class

* Removed unneeded @lengthindicator from schema and refactored message unpacking

* Coverage progress

* Fixed variable length padding

* Coverage, cleanup and docs

* Update docs

* Update docs

* Remove cache from git

* Made cache write if not exist

* Update docs

* Update docs

* Support for 0 header length

* Fix travis build and coverage

* Coverage

* Update docs and fix message header length

* Update docs

* Fixed example message in unpack test

* PHP CS (#5)

* Port to docker-compose

* Refactor bitmap calculation

* [#7] Fixed handing of DateTime fields (#8)
  • Loading branch information
kaperys authored Nov 3, 2017
1 parent 8229144 commit 6f050b1
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 81 deletions.
2 changes: 2 additions & 0 deletions examples/pack.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
* We are now able to set fields on the message schema through the schema manager (with the help of type hinting).
* The schema manager will log the fields we set in preparation for packing the generated message.
*/
$schemaManager->setProcessingCode(123625);
$schemaManager->setCurrencyCodeCardholderBilling('GBP');
$schemaManager->setLocalTransactionTime((new DateTime("now"))->format("His"));
$schemaManager->setPrivateReserved6('sample');

/*
Expand Down
13 changes: 6 additions & 7 deletions examples/unpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@
* We are now able define our message. We need to set the ISO message to parse and the header length. The length and
* fields will be validated when they are unpacked.
*/
$isoMessage = "012430323030f23e4491a8e08020000000000000002031362a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a3030303030303030303030" .
"3030303130303031323132313435343038303030303039313435343038313231323137303331323133303030303930323030433030303030" .
"3030303036303030303230303630303030323033372a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a" .
"2a2a504652333437303030303039323837353937353830303030303030303030333039333733303134373430342054657374204167656e74" .
"203220204861746669656c64202020202048654742383236303238303030303030323136317c303030307c50465233343730303030303930" .
"3135353630313031323634303243313031";

$message->setHeaderLength(2);
$isoMessage = "012430323030f23e4491a8e08020000000000000002031363030303030303030303030303030303030303030303030303030" .
"3030303031303030313231323134353430383030303030393134353430383132313231373033313231333030303039303230" .
"304330303030303030303036303030303230303630303030323033372a2a2a2a2a2a2a2a2a3d2a2a2a2a2a2a2a2a2a2a2a2a" .
"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a5046523334373030303030393238373539373538303030303030303030303330393337" .
"33303134373430342054657374204167656e74203220204861746669656c6420202020204865474238323630323830303030" .
"3030323136317c303030307c504652333437303030303039303135353630313031323634303243313031";

/*
* 5) Parse the unpacked message
Expand Down
12 changes: 7 additions & 5 deletions src/Message/Packer/MessagePacker.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,19 @@ protected function parseBitmap(array $setFields): string
*/
protected function parseDataElement(array $setFields): string
{
ksort($setFields);

$schemaCache = $this->cacheManager->getSchemaCache($this->schemaManager->getSchema());
$dataCache = [];

$dataElement = '';
foreach ($setFields as $field) {
$fieldData = $schemaCache->getDataForProperty($field);

$dataElement .= $fieldData->getMapper()->pack($this->schemaManager->{$fieldData->getGetterName()}());
$dataCache[$fieldData->getBit()] = $fieldData->getMapper()->pack(
$this->schemaManager->{$fieldData->getGetterName()}()
);
}

return $dataElement;
ksort($dataCache);

return implode("", $dataCache);
}
}
82 changes: 40 additions & 42 deletions src/Message/Schema/ISO8583.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Kaperys\Financial\Message\Schema;

use DateTime;

/**
* Class ISO8583 (1987 spec)
*
Expand Down Expand Up @@ -70,7 +68,7 @@ class ISO8583 implements MessageSchemaInterface
protected $amountCardholderBilling;

/**
* @var DateTime
* @var string
*
* @bit 7
* @display n
Expand Down Expand Up @@ -121,7 +119,7 @@ class ISO8583 implements MessageSchemaInterface
protected $systemsTraceAuditNumber;

/**
* @var DateTime
* @var string
*
* @bit 12
* @display n
Expand All @@ -132,7 +130,7 @@ class ISO8583 implements MessageSchemaInterface
protected $localTransactionTime;

/**
* @var DateTime
* @var string
*
* @bit 13
* @display n
Expand All @@ -143,7 +141,7 @@ class ISO8583 implements MessageSchemaInterface
protected $localTransactionDate;

/**
* @var DateTime
* @var string
*
* @bit 14
* @display n
Expand All @@ -154,7 +152,7 @@ class ISO8583 implements MessageSchemaInterface
protected $expirationDate;

/**
* @var DateTime
* @var string
*
* @bit 15
* @display n
Expand All @@ -165,7 +163,7 @@ class ISO8583 implements MessageSchemaInterface
protected $settlementDate;

/**
* @var DateTime
* @var string
*
* @bit 16
* @display n
Expand All @@ -176,7 +174,7 @@ class ISO8583 implements MessageSchemaInterface
protected $conversionDate;

/**
* @var DateTime
* @var string
*
* @bit 17
* @display n
Expand Down Expand Up @@ -767,7 +765,7 @@ class ISO8583 implements MessageSchemaInterface
protected $messageNumberLast;

/**
* @var DateTime
* @var string
*
* @bit 73
* @display n
Expand Down Expand Up @@ -1481,19 +1479,19 @@ public function setAmountCardholderBilling(int $amountCardholderBilling): ISO858
}

/**
* @return DateTime
* @return string
*/
public function getTransmissionDateTime(): DateTime
public function getTransmissionDateTime(): string
{
return $this->transmissionDateTime;
}

/**
* @param DateTime $transmissionDateTime
* @param string $transmissionDateTime
*
* @return ISO8583
*/
public function setTransmissionDateTime(DateTime $transmissionDateTime): ISO8583
public function setTransmissionDateTime(string $transmissionDateTime): ISO8583
{
$this->transmissionDateTime = $transmissionDateTime;
return $this;
Expand Down Expand Up @@ -1576,114 +1574,114 @@ public function setSystemsTraceAuditNumber(int $systemsTraceAuditNumber): ISO858
}

/**
* @return DateTime
* @return string
*/
public function getLocalTransactionTime(): DateTime
public function getLocalTransactionTime(): string
{
return $this->localTransactionTime;
}

/**
* @param DateTime $localTransactionTime
* @param string $localTransactionTime
*
* @return ISO8583
*/
public function setLocalTransactionTime(DateTime $localTransactionTime): ISO8583
public function setLocalTransactionTime(string $localTransactionTime): ISO8583
{
$this->localTransactionTime = $localTransactionTime;
return $this;
}

/**
* @return DateTime
* @return string
*/
public function getLocalTransactionDate(): DateTime
public function getLocalTransactionDate(): string
{
return $this->localTransactionDate;
}

/**
* @param DateTime $localTransactionDate
* @param string $localTransactionDate
*
* @return ISO8583
*/
public function setLocalTransactionDate(DateTime $localTransactionDate): ISO8583
public function setLocalTransactionDate(string $localTransactionDate): ISO8583
{
$this->localTransactionDate = $localTransactionDate;
return $this;
}

/**
* @return DateTime
* @return string
*/
public function getExpirationDate(): DateTime
public function getExpirationDate(): string
{
return $this->expirationDate;
}

/**
* @param DateTime $expirationDate
* @param string $expirationDate
*
* @return ISO8583
*/
public function setExpirationDate(DateTime $expirationDate): ISO8583
public function setExpirationDate(string $expirationDate): ISO8583
{
$this->expirationDate = $expirationDate;
return $this;
}

/**
* @return DateTime
* @return string
*/
public function getSettlementDate(): DateTime
public function getSettlementDate(): string
{
return $this->settlementDate;
}

/**
* @param DateTime $settlementDate
* @param string $settlementDate
*
* @return ISO8583
*/
public function setSettlementDate(DateTime $settlementDate): ISO8583
public function setSettlementDate(string $settlementDate): ISO8583
{
$this->settlementDate = $settlementDate;
return $this;
}

/**
* @return DateTime
* @return string
*/
public function getConversionDate(): DateTime
public function getConversionDate(): string
{
return $this->conversionDate;
}

/**
* @param DateTime $conversionDate
* @param string $conversionDate
*
* @return ISO8583
*/
public function setConversionDate(DateTime $conversionDate): ISO8583
public function setConversionDate(string $conversionDate): ISO8583
{
$this->conversionDate = $conversionDate;
return $this;
}

/**
* @return DateTime
* @return string
*/
public function getCaptureDate(): DateTime
public function getCaptureDate(): string
{
return $this->captureDate;
}

/**
* @param DateTime $captureDate
* @param string $captureDate
*
* @return ISO8583
*/
public function setCaptureDate(DateTime $captureDate): ISO8583
public function setCaptureDate(string $captureDate): ISO8583
{
$this->captureDate = $captureDate;
return $this;
Expand Down Expand Up @@ -2716,19 +2714,19 @@ public function setMessageNumberLast(int $messageNumberLast): ISO8583
}

/**
* @return DateTime
* @return string
*/
public function getDateAction(): DateTime
public function getDateAction(): string
{
return $this->dateAction;
}

/**
* @param DateTime $dateAction
* @param string $dateAction
*
* @return ISO8583
*/
public function setDateAction(DateTime $dateAction): ISO8583
public function setDateAction(string $dateAction): ISO8583
{
$this->dateAction = $dateAction;
return $this;
Expand Down
24 changes: 0 additions & 24 deletions src/Message/Schema/Validator/FieldValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Kaperys\Financial\Message\Schema\Validator;

use DateTime;
use Kaperys\Financial\Container\PropertyAnnotationContainer;
use Kaperys\Financial\Message\Constants\Display;
use Kaperys\Financial\Message\Schema\Validator\Exception\FieldValidationException;
Expand Down Expand Up @@ -45,21 +44,6 @@ public function validate(PropertyAnnotationContainer $propertyAnnotationContaine
*/
protected function validateType(PropertyAnnotationContainer $propertyAnnotationContainer, $data): bool
{
if ($propertyAnnotationContainer->getType() == 'DateTime') {
if (!$data instanceof DateTime) {
$exception = new FieldValidationException(
'Bit ' . $propertyAnnotationContainer->getBit() . ' should be an instance of DateTime'
);

$exception->setData($data);
$exception->setPropertyAnnotationContainer($propertyAnnotationContainer);

throw $exception;
}

return true;
}

// @todo: Complete this display-based validation

if (Display::ALPHA == $propertyAnnotationContainer->getDisplay()) {
Expand Down Expand Up @@ -158,10 +142,6 @@ protected function validateType(PropertyAnnotationContainer $propertyAnnotationC
*/
protected function validateFixedLengthField(PropertyAnnotationContainer $propertyAnnotationContainer, $data): bool
{
if ('DateTime' == $propertyAnnotationContainer->getType()) {
return true;
}

if ($propertyAnnotationContainer->getLength() != strlen($data)) {
throw new FieldValidationException(
'Bit ' . $propertyAnnotationContainer->getBit() . ' should be length ' .
Expand All @@ -186,10 +166,6 @@ protected function validateVariableLengthField(
PropertyAnnotationContainer $propertyAnnotationContainer,
$data
): bool {
if ('DateTime' == $propertyAnnotationContainer->getType()) {
return true;
}

if (strlen($data) > $propertyAnnotationContainer->getMaxLength() ||
strlen($data) < $propertyAnnotationContainer->getMinLength()
) {
Expand Down
8 changes: 5 additions & 3 deletions src/Message/Unpacker/MessageUnpacker.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ public function parse(string $message): MessageUnpacker
// Parse the bitmap
$bitmap = $this->parseBitmap($message);

$numberOfBitmaps = 1;

if (strlen($bitmap) > 64) {
$numberOfBitmaps = 2;
} elseif (strlen($bitmap) > 128) {
}

if (strlen($bitmap) > 128) {
$numberOfBitmaps = 3;
} else {
$numberOfBitmaps = 1;
}

// Message without bitmaps
Expand Down

0 comments on commit 6f050b1

Please sign in to comment.