diff --git a/.gitignore b/.gitignore index 5017d9c4..84e11ab2 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ build/ composer.lock composer.phar vendor/* + +.phpunit.result.cache diff --git a/composer.json b/composer.json index c829ea44..b9b013f9 100644 --- a/composer.json +++ b/composer.json @@ -21,11 +21,11 @@ } ], "require": { - "php": ">=5.3.0", + "php": ">=7.4.0", "ext-curl": "*" }, "require-dev": { - "phpunit/phpunit": "~4.0", + "phpunit/phpunit": "~9.6", "satooshi/php-coveralls": "~0.6.1" }, "autoload": { diff --git a/samples/reporting_scroll_transaction.php b/samples/reporting_scroll_transaction.php new file mode 100644 index 00000000..749e25f3 --- /dev/null +++ b/samples/reporting_scroll_transaction.php @@ -0,0 +1,16 @@ +setConversationId('1234567890'); + $request->setTransactionDate('2023-08-17'); + $request->setDocumentScrollVoSortingOrder('ASC'); + $request->setLastId('1689853839161'); + + $result = \Iyzipay\Model\ReportingScrollTransaction::create($request, Config::options()); + print_r($result); +} + +reportingScrollTransaction(); diff --git a/src/Iyzipay/DefaultHttpClient.php b/src/Iyzipay/DefaultHttpClient.php index cab25812..08d159b2 100644 --- a/src/Iyzipay/DefaultHttpClient.php +++ b/src/Iyzipay/DefaultHttpClient.php @@ -65,6 +65,18 @@ public function put($url, $header, $content) )); } + public function patch($url, $header, $content) + { + return $this->curl->exec($url, array( + CURLOPT_CUSTOMREQUEST => "PATCH", + CURLOPT_POSTFIELDS => $content, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_VERBOSE => false, + CURLOPT_HEADER => false, + CURLOPT_HTTPHEADER => $header + )); + } + public function delete($url, $header, $content = null) { return $this->curl->exec($url, array( diff --git a/src/Iyzipay/IyzipayResource.php b/src/Iyzipay/IyzipayResource.php index 3fbc2ea9..04465838 100644 --- a/src/Iyzipay/IyzipayResource.php +++ b/src/Iyzipay/IyzipayResource.php @@ -27,7 +27,7 @@ protected static function getHttpHeaders(Request $request, Options $options) return $header; } - protected static function getHttpHeadersV2($uri, Request $request = null, Options $options) + protected static function getHttpHeadersV2($uri, Request $request = null, Options $options, bool $addRandom = false) { $header = array( "Accept: application/json", @@ -36,6 +36,7 @@ protected static function getHttpHeadersV2($uri, Request $request = null, Option $rnd = uniqid(); array_push($header, "Authorization: " . self::prepareAuthorizationStringV2($uri, $request, $options, $rnd)); + $addRandom && array_push($header, "x-iyzi-rnd: " . $rnd); array_push($header, "x-iyzi-client-version: " . "iyzipay-php-2.0.43"); return $header; diff --git a/src/Iyzipay/Model/Mapper/ReportingScrollTransactionMapper.php b/src/Iyzipay/Model/Mapper/ReportingScrollTransactionMapper.php new file mode 100644 index 00000000..8eddb26b --- /dev/null +++ b/src/Iyzipay/Model/Mapper/ReportingScrollTransactionMapper.php @@ -0,0 +1,33 @@ +transactionDate)) { + $transaction->setTransactionDate($jsonObject->transactionDate); + } + + if (isset($jsonObject->documentScrollVoSortingOrder)) { + $transaction->setDocumentScrollVoSortingOrder($jsonObject->documentScrollVoSortingOrder); + } + + if (isset($jsonObject->lastId)) { + $transaction->setLastId($jsonObject->lastId); + } + + return $transaction; + } + + public function mapReportingScrollTransaction(ReportingScrollTransaction $transaction): ReportingScrollTransaction { + return $this->mapReportingScrollTransactionFrom($transaction, $this->jsonObject); + } +} diff --git a/src/Iyzipay/Model/ReportingScrollTransaction.php b/src/Iyzipay/Model/ReportingScrollTransaction.php new file mode 100644 index 00000000..a6ffdd56 --- /dev/null +++ b/src/Iyzipay/Model/ReportingScrollTransaction.php @@ -0,0 +1,46 @@ +getBaseUrl() . '/v2/reporting/payment/scroll-transactions' . RequestStringBuilder::requestToStringQuery($request, 'reportingScrollTransaction'); + $rawResult = parent::httpClient()->getV2($uri, parent::getHttpHeadersV2($uri, null, $options)); + return ReportingScrollTransactionMapper::create($rawResult)->jsonDecode()->mapReportingScrollTransaction(new ReportingScrollTransaction()); + } + + public function getDocumentScrollVoSortingOrder(): string { + return $this->documentScrollVoSortingOrder; + } + + public function setDocumentScrollVoSortingOrder(string $documentScrollVoSortingOrder): void { + $this->documentScrollVoSortingOrder = $documentScrollVoSortingOrder; + } + + public function getTransactionDate(): string { + return $this->transactionDate; + } + + public function setTransactionDate(string $transactionDate): void { + $this->transactionDate = $transactionDate; + } + + public function getLastId(): string { + return $this->lastId; + } + + public function setLastId(string $lastId): void { + $this->lastId = $lastId; + } + +} diff --git a/src/Iyzipay/Model/Status.php b/src/Iyzipay/Model/Status.php index 0616a17e..36a2c1ca 100644 --- a/src/Iyzipay/Model/Status.php +++ b/src/Iyzipay/Model/Status.php @@ -6,4 +6,6 @@ class Status { const SUCCESS = "success"; const FAILURE = "failure"; + const ACTIVE = "ACTIVE"; + const PASSIVE = "PASSIVE"; } \ No newline at end of file diff --git a/src/Iyzipay/Request/ReportingScrollTransactionRequest.php b/src/Iyzipay/Request/ReportingScrollTransactionRequest.php new file mode 100644 index 00000000..e963cdc7 --- /dev/null +++ b/src/Iyzipay/Request/ReportingScrollTransactionRequest.php @@ -0,0 +1,44 @@ +documentScrollVoSortingOrder; + } + + public function setDocumentScrollVoSortingOrder(string $documentScrollVoSortingOrder): void { + $this->documentScrollVoSortingOrder = $documentScrollVoSortingOrder; + } + + public function getTransactionDate(): string { + return $this->transactionDate; + } + + public function setTransactionDate(string $transactionDate): void { + $this->transactionDate = $transactionDate; + } + + public function getLastId(): string { + return $this->lastId; + } + + public function setLastId(string $lastId): void { + $this->lastId = $lastId; + } + + public function getJsonObject(): array { + return JsonBuilder::fromJsonObject(parent::getJsonObject()) + ->add('documentScrollVoSortingOrder', $this->getDocumentScrollVoSortingOrder()) + ->add('transactionDate', $this->getTransactionDate()) + ->add('lastId', $this->getLastId()) + ->getObject(); + } +} diff --git a/src/Iyzipay/RequestStringBuilder.php b/src/Iyzipay/RequestStringBuilder.php index 13682a77..79547766 100644 --- a/src/Iyzipay/RequestStringBuilder.php +++ b/src/Iyzipay/RequestStringBuilder.php @@ -150,6 +150,10 @@ public static function requestToStringQuery(Request $request, $type = null) $stringQuery .= "&locale=" . $request->getLocale(); } + if ($type == 'locale') { + $stringQuery = "?locale=" . $request->getLocale(); + } + if($type == 'defaultParams' ) { if($request->getConversationId()) { $stringQuery = "?conversationId=" . $request->getConversationId(); @@ -175,6 +179,20 @@ public static function requestToStringQuery(Request $request, $type = null) } } + if($type == 'reportingScrollTransaction') { + if($request->getDocumentScrollVoSortingOrder()) { + $stringQuery = '?documentScrollVoSortingOrder=' . $request->getDocumentScrollVoSortingOrder(); + } + + if($request->getTransactionDate()) { + $stringQuery .= "&transactionDate=" . $request->getTransactionDate(); + } + + if($request->getLastId()) { + $stringQuery .= '&lastId=' . $request->getLastId(); + } + } + if($type == 'subscriptionItems' ) { if ($request->getPage()) { $stringQuery = "?page=" . $request->getPage(); diff --git a/tests/Iyzipay/Tests/IyzipayResourceTestCase.php b/tests/Iyzipay/Tests/IyzipayResourceTestCase.php index f3bca767..a3f1bd8a 100644 --- a/tests/Iyzipay/Tests/IyzipayResourceTestCase.php +++ b/tests/Iyzipay/Tests/IyzipayResourceTestCase.php @@ -21,7 +21,7 @@ class IyzipayResourceTestCase extends TestCase "conversationId":"123456" }'; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -83,4 +83,4 @@ public function test_should_check_http_client_not_empty() { $this->assertNotEmpty($this->httpClient); } -} \ No newline at end of file +} diff --git a/tests/Iyzipay/Tests/Model/ReportingScrollTransactionTest.php b/tests/Iyzipay/Tests/Model/ReportingScrollTransactionTest.php new file mode 100644 index 00000000..e371cb37 --- /dev/null +++ b/tests/Iyzipay/Tests/Model/ReportingScrollTransactionTest.php @@ -0,0 +1,22 @@ +setConversationId('1234567890'); + $request->setTransactionDate('2023-08-17'); + $request->setDocumentScrollVoSortingOrder('ASC'); + $request->setLastId('1689853839161'); + + $this->expectHttpGetV2(); + $transaction = ReportingScrollTransaction::create($request, $this->options); + $this->verifyResource($transaction); + } +} diff --git a/tests/Iyzipay/Tests/Request/ReportingScrollTransactionRequestTest.php b/tests/Iyzipay/Tests/Request/ReportingScrollTransactionRequestTest.php new file mode 100644 index 00000000..b5041040 --- /dev/null +++ b/tests/Iyzipay/Tests/Request/ReportingScrollTransactionRequestTest.php @@ -0,0 +1,27 @@ +prepareRequest(); + $jsonObject = $request->getJsonObject(); + + $this->assertEquals('123456789', $jsonObject['conversationId']); + $this->assertEquals('2023-08-17', $jsonObject['transactionDate']); + $this->assertEquals('ASC', $jsonObject['documentScrollVoSortingOrder']); + $this->assertEquals('1689853839161', $jsonObject['lastId']); + } + + private function prepareRequest(): ReportingScrollTransactionRequest { + $request = new ReportingScrollTransactionRequest(); + $request->setConversationId('123456789'); + $request->setTransactionDate('2023-08-17'); + $request->setDocumentScrollVoSortingOrder('ASC'); + $request->setLastId('1689853839161'); + return $request; + } +} diff --git a/tests/Iyzipay/Tests/TestCase.php b/tests/Iyzipay/Tests/TestCase.php index d094c4de..cd62f6e3 100644 --- a/tests/Iyzipay/Tests/TestCase.php +++ b/tests/Iyzipay/Tests/TestCase.php @@ -2,13 +2,14 @@ namespace Iyzipay\Tests; +use PHPUnit\Framework\TestCase as BaseTestCase; use Iyzipay\Options; -class TestCase extends \PHPUnit_Framework_TestCase +class TestCase extends BaseTestCase { protected $options; - protected function setUp() + protected function setUp(): void { $this->options = new Options(); $this->options->setApiKey("apiKey"); @@ -33,4 +34,4 @@ public function retrieveJsonFile($file) { return file_get_contents(__DIR__ . '/mock/' . $file, true); } -} \ No newline at end of file +}