-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IyziLink / Search Merchant Products complete
- Loading branch information
1 parent
d8c9827
commit db6f326
Showing
6 changed files
with
175 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,16 @@ | ||
<?php | ||
|
||
require_once("config.php"); | ||
|
||
function iyzilinkSearchMerchantProducts(): void { | ||
$request = new \Iyzipay\Request\Iyzilink\IyziLinkSearchMerchantProductsRequest(); | ||
$request->setLocale(\Iyzipay\Model\Locale::TR); | ||
$request->setPage(1); | ||
$request->setCount(10); | ||
$request->setConversationId('123456'); | ||
|
||
$iyziLinkSearchMerchantProducts= \Iyzipay\Model\Iyzilink\IyziLinkSearchMerchantProducts::create($request,Config::options()); | ||
print_r($iyziLinkSearchMerchantProducts); | ||
} | ||
|
||
iyzilinkSearchMerchantProducts(); |
36 changes: 36 additions & 0 deletions
36
src/Iyzipay/Model/Iyzilink/IyziLinkSearchMerchantProducts.php
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,36 @@ | ||
<?php | ||
|
||
namespace Iyzipay\Model\Iyzilink; | ||
|
||
use Iyzipay\IyzipayResource; | ||
use Iyzipay\Model\Mapper\Iyzilink\IyziLinkSearchMerchantProductsMapper; | ||
use Iyzipay\Request\Iyzilink\IyziLinkSearchMerchantProductsRequest; | ||
use Iyzipay\Options; | ||
use Iyzipay\RequestStringBuilder; | ||
|
||
class IyziLinkSearchMerchantProducts extends IyzipayResource { | ||
private int $page; | ||
private int $count; | ||
|
||
public function getPage(): int { | ||
return $this->page; | ||
} | ||
|
||
public function setPage(int $page): void { | ||
$this->page = $page; | ||
} | ||
|
||
public function getCount(): int { | ||
return $this->count; | ||
} | ||
|
||
public function setCount(int $count): void { | ||
$this->count = $count; | ||
} | ||
|
||
public static function create(IyziLinkSearchMerchantProductsRequest $request, Options $options): IyziLinkSearchMerchantProducts { | ||
$uri = $options->getBaseUrl() . "/v2/iyzilink/products" . RequestStringBuilder::requestToStringQuery($request, 'pages'); | ||
$rawResult = parent::httpClient()->getV2($uri, parent::getHttpHeadersV2($uri, null, $options)); | ||
return IyziLinkSearchMerchantProductsMapper::create($rawResult)->jsonDecode()->mapIyziLinkSearchMerchantProducts(new IyziLinkSearchMerchantProducts()); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Iyzipay/Model/Mapper/Iyzilink/IyziLinkSearchMerchantProductsMapper.php
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,30 @@ | ||
<?php | ||
|
||
namespace Iyzipay\Model\Mapper\Iyzilink; | ||
|
||
use Iyzipay\Model\Mapper\IyzipayResourceMapper; | ||
use Iyzipay\Model\Iyzilink\IyziLinkSearchMerchantProducts; | ||
|
||
class IyziLinkSearchMerchantProductsMapper extends IyzipayResourceMapper { | ||
public static function create($rawResult = null): IyziLinkSearchMerchantProductsMapper { | ||
return new IyziLinkSearchMerchantProductsMapper($rawResult); | ||
} | ||
|
||
public function mapIyziLinkSearchMerchantProductsFrom(IyziLinkSearchMerchantProducts $iyziLinkSearchMerchantProducts, object $jsonObject): IyziLinkSearchMerchantProducts { | ||
parent::mapResourceFrom($iyziLinkSearchMerchantProducts, $jsonObject); | ||
|
||
if (isset($jsonObject->page)) { | ||
$iyziLinkSearchMerchantProducts->setPage($jsonObject->page); | ||
} | ||
|
||
if (isset($jsonObject->count)) { | ||
$iyziLinkSearchMerchantProducts->setCount($jsonObject->count); | ||
} | ||
|
||
return $iyziLinkSearchMerchantProducts; | ||
} | ||
|
||
public function mapIyziLinkSearchMerchantProducts(IyziLinkSearchMerchantProducts $iyziLinkSearchMerchantProducts): IyziLinkSearchMerchantProducts { | ||
return $this->mapIyziLinkSearchMerchantProductsFrom($iyziLinkSearchMerchantProducts, $this->jsonObject); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/Iyzipay/Request/Iyzilink/IyziLinkSearchMerchantProductsRequest.php
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,43 @@ | ||
<?php | ||
|
||
namespace Iyzipay\Request\Iyzilink; | ||
|
||
use Iyzipay\JsonBuilder; | ||
use Iyzipay\Request; | ||
use Iyzipay\RequestStringBuilder; | ||
|
||
class IyziLinkSearchMerchantProductsRequest extends Request { | ||
private int $page; | ||
private int $count; | ||
|
||
public function getPage(): int { | ||
return $this->page; | ||
} | ||
|
||
public function setPage(int $page): void { | ||
$this->page = $page; | ||
} | ||
|
||
public function getCount(): int { | ||
return $this->count; | ||
} | ||
|
||
public function setCount(int $count): void { | ||
$this->count = $count; | ||
} | ||
|
||
public function getJsonObject() { | ||
return JsonBuilder::fromJsonObject(parent::getJsonObject()) | ||
->add('page', $this->getPage()) | ||
->add('count', $this->getCount()) | ||
->getObject(); | ||
} | ||
|
||
public function toPKIRequestString(): RequestStringBuilder { | ||
return RequestStringBuilder::create() | ||
->appendSuper(parent::toPKIRequestString()) | ||
->append('page', $this->getPage()) | ||
->append('count', $this->getCount()) | ||
->getRequestString(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/Iyzipay/Tests/Model/Iyzilink/IyziLinkSearchMerchantProductsTest.php
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,21 @@ | ||
<?php | ||
|
||
namespace Iyzipay\Tests\Model\Iyzilink; | ||
|
||
use Iyzipay\Model\Iyzilink\IyziLinkSearchMerchantProducts; | ||
use Iyzipay\Request\Iyzilink\IyziLinkSearchMerchantProductsRequest; | ||
use Iyzipay\Tests\IyzipayResourceTestCase; | ||
|
||
class IyziLinkSearchMerchantProductsTest extends IyzipayResourceTestCase { | ||
public function testShouldSearchMerchantProducts(): void { | ||
$request = new IyziLinkSearchMerchantProductsRequest(); | ||
$request->setLocale(\Iyzipay\Model\Locale::TR); | ||
$request->setConversationId('123456'); | ||
$request->setPage(1); | ||
$request->setCount(10); | ||
|
||
$this->expectHttpGetV2(); | ||
$iyziLinkSearchMerchantProducts = IyziLinkSearchMerchantProducts::create($request, $this->options); | ||
$this->verifyResource($iyziLinkSearchMerchantProducts); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/Iyzipay/Tests/Request/Iyzilink/IyziLinkSearchMerchantProductsRequestTest.php
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 Iyzipay\Tests\Request\Iyzilink; | ||
|
||
use Iyzipay\Model\Status; | ||
use Iyzipay\Model\Locale; | ||
use Iyzipay\Tests\TestCase; | ||
use Iyzipay\Request\Iyzilink\IyziLinkSearchMerchantProductsRequest; | ||
|
||
class IyziLinkSearchMerchantProductsRequestTest extends TestCase { | ||
public function testShouldCreateIyziLinkSearchMerchantProductsRequest(): void { | ||
$request = $this->prepareRequest(); | ||
$jsonObject = $request->getJsonObject(); | ||
|
||
$this->assertEquals(Locale::TR, $jsonObject["locale"]); | ||
$this->assertEquals(1, $jsonObject['page']); | ||
$this->assertEquals(10, $jsonObject['count']); | ||
} | ||
|
||
public function prepareRequest(): IyziLinkSearchMerchantProductsRequest { | ||
$request = new IyziLinkSearchMerchantProductsRequest(); | ||
$request->setLocale(Locale::TR); | ||
$request->setConversationId('123456'); | ||
$request->setPage(1); | ||
$request->setCount(10); | ||
|
||
return $request; | ||
} | ||
} |