diff --git a/composer.json b/composer.json index eba18fca..1c907091 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "mews/pos", "description": "Türk bankaları için sanal pos kütüphanesi", - "keywords": ["pos", "sanal pos", "est", "est pos", "akbank"], + "keywords": ["pos", "sanal pos", "est", "est pos", "akbank", "posnet", "payfor", "vakifbankpos"], "homepage": "https://github.com/mewebstudio/pos", "license": "MIT", "authors": [ @@ -11,7 +11,7 @@ } ], "require": { - "php": "^7.1.3", + "php": ">=7.1.3", "ext-dom": "*", "ext-json": "*", "ext-openssl": "*", @@ -35,5 +35,8 @@ "squizlabs/php_codesniffer": "^3.5", "escapestudios/symfony2-coding-standard": "^3.11", "symfony/var-dumper": "^5.1" + }, + "config": { + "sort-packages": true } } diff --git a/src/Entity/Card/AbstractCreditCard.php b/src/Entity/Card/AbstractCreditCard.php index 6984570f..bc73a040 100644 --- a/src/Entity/Card/AbstractCreditCard.php +++ b/src/Entity/Card/AbstractCreditCard.php @@ -8,17 +8,18 @@ abstract class AbstractCreditCard { /** + * 16 digit credit card number without spaces * @var string */ protected $number; /** - * @var \DateTime + * @var \DateTimeImmutable */ protected $expireYear; /** - * @var \DateTime + * @var \DateTimeImmutable */ protected $expireMonth; @@ -40,24 +41,31 @@ abstract class AbstractCreditCard /** * AbstractCreditCard constructor. + * * @param string $number credit card number with or without spaces - * @param string $expireYear accepts year in 1, 2 and 4 digit format. accepted year formats '1' (2001), '02' (2002), '20' (2020), '2024' (2024) + * @param string $expireYear accepts year in 1, 2 and 4 digit format. accepted year formats '1' (2001), '02' + * (2002), '20' (2020), '2024' (2024) * @param string $expireMonth single digit or double digit month values are accepted * @param string $cvv * @param string|null $cardHolderName * @param string|null $cardType examples values: 'visa', 'master', '1', '2' + * + * @throws \DomainException */ public function __construct(string $number, string $expireYear, string $expireMonth, string $cvv, ?string $cardHolderName = null, ?string $cardType = null) { $this->number = preg_replace('/\s+/', '', $number); - $yearFormat = 4 === strlen($expireYear) ? 'Y' : 'y'; - $this->expireYear = \DateTime::createFromFormat($yearFormat, $expireYear); + $yearFormat = 4 === strlen($expireYear) ? 'Y' : 'y'; + $this->expireYear = \DateTimeImmutable::createFromFormat($yearFormat, $expireYear); + $this->expireMonth = \DateTimeImmutable::createFromFormat('m', $expireMonth); + if (!$this->expireYear || !$this->expireMonth) { + throw new \DomainException('INVALID DATE FORMAT'); + } - $this->expireMonth = \DateTime::createFromFormat('m', $expireMonth); - $this->cvv = $cvv; + $this->cvv = $cvv; $this->holderName = $cardHolderName; - $this->type = $cardType; + $this->type = $cardType; } /** diff --git a/tests/Entity/Card/AbstractCreditCardTest.php b/tests/Entity/Card/AbstractCreditCardTest.php new file mode 100644 index 00000000..102d58a2 --- /dev/null +++ b/tests/Entity/Card/AbstractCreditCardTest.php @@ -0,0 +1,24 @@ + '1234567890123456', + 'expireYear' => '', + 'expireMonth' => '', + 'cvv' => '123', + ]; + $this->expectException(\DomainException::class); + $this->getMockForAbstractClass(AbstractCreditCard::class, $testData); + } +} diff --git a/tests/Gateways/VakifBankPostTest.php b/tests/Gateways/VakifBankPosTest.php similarity index 99% rename from tests/Gateways/VakifBankPostTest.php rename to tests/Gateways/VakifBankPosTest.php index 831afcc1..15fc9516 100644 --- a/tests/Gateways/VakifBankPostTest.php +++ b/tests/Gateways/VakifBankPosTest.php @@ -11,7 +11,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Serializer\Encoder\XmlEncoder; -class VakifBankPostTest extends TestCase +class VakifBankPosTest extends TestCase { /** * @var VakifBankAccount