Skip to content

Commit

Permalink
IyziLink / Search Merchant Products complete
Browse files Browse the repository at this point in the history
  • Loading branch information
osman-keser committed Mar 14, 2024
1 parent d8c9827 commit db6f326
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 0 deletions.
16 changes: 16 additions & 0 deletions samples/iyzilink_search_merchant_products_example.php
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 src/Iyzipay/Model/Iyzilink/IyziLinkSearchMerchantProducts.php
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());
}
}
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);
}
}
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();
}
}
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);
}
}
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;
}
}

0 comments on commit db6f326

Please sign in to comment.