Skip to content

Commit

Permalink
Merge pull request #40 from nuryagdym/master
Browse files Browse the repository at this point in the history
fix php 8 version issue
  • Loading branch information
mewebstudio authored Oct 14, 2021
2 parents b9e07aa + 6afae22 commit 62c6605
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -11,7 +11,7 @@
}
],
"require": {
"php": "^7.1.3",
"php": ">=7.1.3",
"ext-dom": "*",
"ext-json": "*",
"ext-openssl": "*",
Expand All @@ -35,5 +35,8 @@
"squizlabs/php_codesniffer": "^3.5",
"escapestudios/symfony2-coding-standard": "^3.11",
"symfony/var-dumper": "^5.1"
},
"config": {
"sort-packages": true
}
}
24 changes: 16 additions & 8 deletions src/Entity/Card/AbstractCreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}

/**
Expand Down
24 changes: 24 additions & 0 deletions tests/Entity/Card/AbstractCreditCardTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Mews\Pos\Tests\Entity\Card;

use Mews\Pos\Entity\Card\AbstractCreditCard;
use PHPUnit\Framework\TestCase;

/**
* @covers \Mews\Pos\Entity\Card\AbstractCreditCard
*/
class AbstractCreditCardTest extends TestCase
{
public function testInvalidDateException()
{
$testData = [
'number' => '1234567890123456',
'expireYear' => '',
'expireMonth' => '',
'cvv' => '123',
];
$this->expectException(\DomainException::class);
$this->getMockForAbstractClass(AbstractCreditCard::class, $testData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Encoder\XmlEncoder;

class VakifBankPostTest extends TestCase
class VakifBankPosTest extends TestCase
{
/**
* @var VakifBankAccount
Expand Down

0 comments on commit 62c6605

Please sign in to comment.