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/create_blacklisted_card.php b/samples/create_blacklisted_card.php new file mode 100644 index 00000000..be1ac1ae --- /dev/null +++ b/samples/create_blacklisted_card.php @@ -0,0 +1,16 @@ +setLocale(\Iyzipay\Model\Locale::TR); + $request->setConversationId("123456789"); + $request->setCardToken('G7Zzo5Y24cxwaIwC4h+jUJXtqTA='); + $request->setCardUserKey('ew9hzoujBUJgOUer8st0ler0dOQ='); + + $blacklistedCard = \Iyzipay\Model\BlacklistedCard::create($request, Config::options()); + print_r($blacklistedCard); +} + +createBlacklistedCard(); diff --git a/samples/iyzilink_add_product_sample.php b/samples/iyzilink_add_product_sample.php index 27d517ef..e009e198 100644 --- a/samples/iyzilink_add_product_sample.php +++ b/samples/iyzilink_add_product_sample.php @@ -14,6 +14,9 @@ $request->setAddressIgnorable(false); $request->setSoldLimit(1); $request->setInstallmentRequest(false); +$request->setSourceType('API'); +$request->setStockEnabled(true); +$request->setStockCount(1); $response = \Iyzipay\Model\Iyzilink\IyziLinkSaveProduct::create($request, Config::options()); print_r($response); diff --git a/samples/iyzilink_create_fastlink_sample.php b/samples/iyzilink_create_fastlink_sample.php new file mode 100644 index 00000000..d6c788e2 --- /dev/null +++ b/samples/iyzilink_create_fastlink_sample.php @@ -0,0 +1,18 @@ +setLocale(\Iyzipay\Model\Locale::TR); + $request->setConversationId("123456789"); + $request->setDescription("ft-description-fast-link"); + $request->setPrice(99.73); + $request->setCurrencyCode("TRY"); + $request->setSourceType("WEB"); + + $iyzilinkFastLink = \Iyzipay\Model\Iyzilink\IyziLinkFastLink::create($request, Config::options()); + print_r($iyzilinkFastLink); +} + +iyzilinkCreateFastLink(); diff --git a/samples/iyzilink_search_merchant_products_example.php b/samples/iyzilink_search_merchant_products_example.php new file mode 100644 index 00000000..ee1c7e25 --- /dev/null +++ b/samples/iyzilink_search_merchant_products_example.php @@ -0,0 +1,16 @@ +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(); diff --git a/samples/iyzilink_update_product_status.php b/samples/iyzilink_update_product_status.php new file mode 100644 index 00000000..87a058b3 --- /dev/null +++ b/samples/iyzilink_update_product_status.php @@ -0,0 +1,15 @@ +setLocale(\Iyzipay\Model\Locale::TR); + $request->setProductStatus(\Iyzipay\Model\Status::PASSIVE); + $request->setToken('AAM'); + + $iyzilinkUpdateProductStatus = \Iyzipay\Model\Iyzilink\IyziLinkUpdateProductStatus::create($request, Config::options()); + print_r($iyzilinkUpdateProductStatus); +} + +iyzilinkUpdateProductStatus(); diff --git a/samples/retrieve_blacklisted_card.php b/samples/retrieve_blacklisted_card.php new file mode 100644 index 00000000..1d0f9f02 --- /dev/null +++ b/samples/retrieve_blacklisted_card.php @@ -0,0 +1,15 @@ +setLocale(\Iyzipay\Model\Locale::TR); + $request->setConversationId("123456789"); + $request->setCardNumber('5528790000000008'); + + $blacklistedCard = \Iyzipay\Model\BlacklistedCard::retrieve($request, Config::options()); + print_r($blacklistedCard); +} + +retrieveBlacklistedCard(); diff --git a/samples/update_blacklisted_card.php b/samples/update_blacklisted_card.php new file mode 100644 index 00000000..82153f2d --- /dev/null +++ b/samples/update_blacklisted_card.php @@ -0,0 +1,16 @@ +setLocale(\Iyzipay\Model\Locale::TR); + $request->setConversationId("123456789"); + $request->setCardToken('G7Zzo5Y24cxwaIwC4h+jUJXtqTA='); + $request->setCardUserKey('ew9hzoujBUJgOUer8st0ler0dOQ='); + + $blacklistedCard = \Iyzipay\Model\BlacklistedCard::update($request,Config::options()); + print_r($blacklistedCard); +} + +updateBlacklistedCard(); 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/BlacklistedCard.php b/src/Iyzipay/Model/BlacklistedCard.php new file mode 100644 index 00000000..05d35242 --- /dev/null +++ b/src/Iyzipay/Model/BlacklistedCard.php @@ -0,0 +1,55 @@ +post($options->getBaseUrl() . "/cardstorage/blacklist/card", parent::getHttpHeaders($request, $options), $request->toJsonString()); + return BlacklistedCardMapper::create($rawResult)->jsonDecode()->mapBlacklistedCard(new BlacklistedCard()); + } + + public static function retrieve(RetrieveBlacklistedCardRequest $request, Options $options): BlacklistedCard { + $rawResult = parent::httpClient()->post(($options)->getBaseUrl() . '/cardstorage/blacklist/card/retrieve', parent::getHttpHeaders($request, $options), $request->toJsonString()); + return BlacklistedCardMapper::create($rawResult)->jsonDecode()->mapRetrieveBlacklistedCard(new BlacklistedCard()); + } + + public static function update(UpdateBlackListedCardRequest $request, Options $options): BlacklistedCard { + $rawResult = parent::httpClient()->post(($options)->getBaseUrl() . '/cardstorage/blacklist/card/inactive', parent::getHttpHeaders($request, $options), $request->toJsonString()); + return BlacklistedCardMapper::create($rawResult)->jsonDecode()->mapBlacklistedCard(new BlacklistedCard()); + } + + public function getCardUserKey(): string { + return $this->cardUserKey; + } + + public function setCardUserKey($cardUserKey): void { + $this->cardUserKey = $cardUserKey; + } + + public function getCardToken(): string { + return $this->cardToken; + } + + public function setCardToken($cardToken): void { + $this->cardToken = $cardToken; + } + + public function getCardNumber(): string { + return $this->cardNumber; + } + + public function setCardNumber(string $cardNumber): void { + $this->cardNumber = $cardNumber; + } +} \ No newline at end of file diff --git a/src/Iyzipay/Model/Iyzilink/IyziLinkFastLink.php b/src/Iyzipay/Model/Iyzilink/IyziLinkFastLink.php new file mode 100644 index 00000000..67c3a754 --- /dev/null +++ b/src/Iyzipay/Model/Iyzilink/IyziLinkFastLink.php @@ -0,0 +1,54 @@ +getBaseUrl() . "/v2/iyzilink/fast-link/products" . RequestStringBuilder::requestToStringQuery($request, 'locale'); + $rawResult = parent::httpClient()->post($uri, parent::getHttpHeadersV2($uri, $request, $options), $request->toJsonString()); + return IyziLinkCreateFastLinkMapper::create($rawResult)->jsonDecode()->mapIyziLinkCreateFastLink(new IyziLinkFastLink()); + } + + public function getDescription(): string { + return $this->description; + } + + public function setDescription(string $description): void { + $this->description = $description; + } + + public function getPrice() { + return $this->price; + } + + public function setPrice($price): void { + $this->price = $price; + } + + public function getCurrencyCode(): string { + return $this->currencyCode; + } + + public function setCurrencyCode(string $currencyCode): void { + $this->currencyCode = $currencyCode; + } + + public function getSourceType(): string { + return $this->sourceType; + } + + public function setSourceType(string $sourceType): void { + $this->sourceType = $sourceType; + } +} diff --git a/src/Iyzipay/Model/Iyzilink/IyziLinkSaveProduct.php b/src/Iyzipay/Model/Iyzilink/IyziLinkSaveProduct.php index a31611ac..afeba3c5 100644 --- a/src/Iyzipay/Model/Iyzilink/IyziLinkSaveProduct.php +++ b/src/Iyzipay/Model/Iyzilink/IyziLinkSaveProduct.php @@ -7,12 +7,10 @@ use Iyzipay\Options; use Iyzipay\RequestStringBuilder; -class IyziLinkSaveProduct extends IyziLinkSaveProductResource -{ - public static function create(IyziLinkSaveProductRequest $request, Options $options) - { - $uri = $options->getBaseUrl() . "/v2/iyzilink/products/". RequestStringBuilder::requestToStringQuery($request, null); - $rawResult = parent::httpClient()->post($uri, parent::getHttpHeadersV2($uri, $request, $options), $request->toJsonString()); +class IyziLinkSaveProduct extends IyziLinkSaveProductResource { + public static function create(IyziLinkSaveProductRequest $request, Options $options): IyziLinkSaveProduct { + $uri = $options->getBaseUrl() . "/v2/iyzilink/products/" . RequestStringBuilder::requestToStringQuery($request, null); + $rawResult = parent::httpClient()->post($options->getBaseUrl() . "/v2/iyzilink/products/", parent::getHttpHeadersV2($uri, $request, $options), $request->toJsonString()); return IyziLinkSaveProductMapper::create($rawResult)->jsonDecode()->mapIyziLinkSaveProduct(new IyziLinkSaveProduct()); } } diff --git a/src/Iyzipay/Model/Iyzilink/IyziLinkSaveProductResource.php b/src/Iyzipay/Model/Iyzilink/IyziLinkSaveProductResource.php index 98691297..0a82b9ac 100644 --- a/src/Iyzipay/Model/Iyzilink/IyziLinkSaveProductResource.php +++ b/src/Iyzipay/Model/Iyzilink/IyziLinkSaveProductResource.php @@ -15,6 +15,9 @@ class IyziLinkSaveProductResource extends IyzipayResource private $token; private $url; private $imageUrl; + private $sourceType; + private $stockEnabled; + private $stockCount; public function getBase64EncodedImage() { @@ -71,4 +74,34 @@ public function setImageUrl($imageUrl) { $this->imageUrl = $imageUrl; } + + public function getSourceType() + { + return $this->sourceType; + } + + public function setSourceType($sourceType) + { + $this->sourceType = $sourceType; + } + + public function getStockEnabled() + { + return $this->stockEnabled; + } + + public function setStockEnabled($stockEnabled) + { + $this->stockEnabled = $stockEnabled; + } + + public function getStockCount() + { + return $this->stockCount; + } + + public function setStockCount($stockCount) + { + $this->stockCount = $stockCount; + } } \ No newline at end of file diff --git a/src/Iyzipay/Model/Iyzilink/IyziLinkSearchMerchantProducts.php b/src/Iyzipay/Model/Iyzilink/IyziLinkSearchMerchantProducts.php new file mode 100644 index 00000000..d2e6da5c --- /dev/null +++ b/src/Iyzipay/Model/Iyzilink/IyziLinkSearchMerchantProducts.php @@ -0,0 +1,36 @@ +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()); + } +} diff --git a/src/Iyzipay/Model/Iyzilink/IyziLinkUpdateProductStatus.php b/src/Iyzipay/Model/Iyzilink/IyziLinkUpdateProductStatus.php new file mode 100644 index 00000000..1c58397a --- /dev/null +++ b/src/Iyzipay/Model/Iyzilink/IyziLinkUpdateProductStatus.php @@ -0,0 +1,38 @@ +token; + } + + public function setToken(string $token): void { + $this->token = $token; + } + + public function getProductStatus(): string { + return $this->productStatus; + } + + public function setProductStatus(string $productStatus): void { + $this->productStatus = $productStatus; + } + + public static function create(IyziLinkUpdateProductStatusRequest $request, Options $options) { + $token = $request->getToken(); + $productStatus = $request->getProductStatus(); + $uri = $options->getBaseUrl() . "/v2/iyzilink/products/$token/status/$productStatus" . RequestStringBuilder::requestToStringQuery($request, 'locale'); + $rawResult = parent::httpClient()->patch($uri, parent::getHttpHeadersV2($uri, $request, $options), $request->toJsonString()); + return IyziLinkUpdateProductStatusMapper::create($rawResult)->jsonDecode()->mapIyziLinkUpdateProductStatus(new IyziLinkUpdateProductStatus()); + } +} diff --git a/src/Iyzipay/Model/Mapper/BlacklistedCardMapper.php b/src/Iyzipay/Model/Mapper/BlacklistedCardMapper.php new file mode 100644 index 00000000..48afe8c7 --- /dev/null +++ b/src/Iyzipay/Model/Mapper/BlacklistedCardMapper.php @@ -0,0 +1,41 @@ +cardUserKey)) { + $blacklistedCard->setCardUserKey($jsonObject->cardUserKey); + } + if (isset($jsonObject->cardToken)) { + $blacklistedCard->setCardToken($jsonObject->cardToken); + } + + return $blacklistedCard; + } + + public function mapRetrieveBlacklistedCardForm(BlacklistedCard $blacklistedCard, $jsonObject): BlacklistedCard { + parent::mapResourceFrom($blacklistedCard, $jsonObject); + + if (isset($jsonObject->cardNumber)) { + $blacklistedCard->setCardNumber(($jsonObject->cardNumber)); + } + return $blacklistedCard; + } + + public function mapBlacklistedCard(BlacklistedCard $blacklistedCard): BlacklistedCard { + return $this->mapBlacklistedCardForm($blacklistedCard, $this->jsonObject); + } + + public function mapRetrieveBlacklistedCard(BlacklistedCard $blacklistedCard): BlacklistedCard { + return $this->mapRetrieveBlacklistedCardForm($blacklistedCard, $this->jsonObject); + } +} diff --git a/src/Iyzipay/Model/Mapper/Iyzilink/IyziLinkCreateFastLinkMapper.php b/src/Iyzipay/Model/Mapper/Iyzilink/IyziLinkCreateFastLinkMapper.php new file mode 100644 index 00000000..aaf8ca71 --- /dev/null +++ b/src/Iyzipay/Model/Mapper/Iyzilink/IyziLinkCreateFastLinkMapper.php @@ -0,0 +1,38 @@ +description)) { + $iyzilinkFastLink->setDescription(($jsonObjet->description)); + } + + if (isset($jsonObjet->price)) { + $iyzilinkFastLink->setPrice($jsonObjet->pricr); + } + + if (isset($jsonObjet->currencyCode)) { + $iyzilinkFastLink->setCurrencyCode($jsonObjet->currencyCode); + } + + if (isset($jsonObjet->sourceType)) { + $iyzilinkFastLink->setSourceType($jsonObjet->sourceType); + } + + return $iyzilinkFastLink; + } + + public function mapIyziLinkCreateFastLink(IyziLinkFastLink $iyziLinkFastLink): IyziLinkFastLink { + return $this->mapIyziLinkCreateFastLinkFrom($iyziLinkFastLink, $this->jsonObject); + } +} diff --git a/src/Iyzipay/Model/Mapper/Iyzilink/IyziLinkSearchMerchantProductsMapper.php b/src/Iyzipay/Model/Mapper/Iyzilink/IyziLinkSearchMerchantProductsMapper.php new file mode 100644 index 00000000..0c2720b9 --- /dev/null +++ b/src/Iyzipay/Model/Mapper/Iyzilink/IyziLinkSearchMerchantProductsMapper.php @@ -0,0 +1,30 @@ +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); + } +} diff --git a/src/Iyzipay/Model/Mapper/Iyzilink/IyziLinkUpdateProductStatusMapper.php b/src/Iyzipay/Model/Mapper/Iyzilink/IyziLinkUpdateProductStatusMapper.php new file mode 100644 index 00000000..adc39b30 --- /dev/null +++ b/src/Iyzipay/Model/Mapper/Iyzilink/IyziLinkUpdateProductStatusMapper.php @@ -0,0 +1,30 @@ +token)) { + $iyziLinkUpdateProductStatus->setToken($jsonObject->token); + } + + if (isset($jsonObject->productStatus)) { + $iyziLinkUpdateProductStatus->setProductStatus($jsonObject->productStatus); + } + + return $iyziLinkUpdateProductStatus; + } + + public function mapIyziLinkUpdateProductStatus(IyziLinkUpdateProductStatus $iyziLinkUpdateProductStatus): IyziLinkUpdateProductStatus { + return $this->mapIyziLinkUpdateProductStatusFrom($iyziLinkUpdateProductStatus, $this->jsonObject); + } +} diff --git a/src/Iyzipay/Model/Status.php b/src/Iyzipay/Model/Status.php index 0616a17e..9a05221f 100644 --- a/src/Iyzipay/Model/Status.php +++ b/src/Iyzipay/Model/Status.php @@ -2,8 +2,9 @@ namespace Iyzipay\Model; -class Status -{ +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/CreateBlackListedCardRequest.php b/src/Iyzipay/Request/CreateBlackListedCardRequest.php new file mode 100644 index 00000000..04d242eb --- /dev/null +++ b/src/Iyzipay/Request/CreateBlackListedCardRequest.php @@ -0,0 +1,43 @@ +cardUserKey; + } + + public function setCardUserKey($cardUserKey): void { + $this->cardUserKey = $cardUserKey; + } + + public function getCardToken(): string { + return $this->cardToken; + } + + public function setCardToken($cardToken): void { + $this->cardToken = $cardToken; + } + + public function getJsonObject(): array { + return JsonBuilder::fromJsonObject(parent::getJsonObject()) + ->add("cardToken", $this->getCardToken()) + ->add("cardUserKey", $this->getCardUserKey()) + ->getObject(); + } + + public function toPKIRequestString(): string { + return RequestStringBuilder::create() + ->appendSuper(parent::toPKIRequestString()) + ->append("cardToken", $this->getCardToken()) + ->append("cardUserKey", $this->getCardUserKey()) + ->getRequestString(); + } +} diff --git a/src/Iyzipay/Request/Iyzilink/IyziLinkCreateFastLinkRequest.php b/src/Iyzipay/Request/Iyzilink/IyziLinkCreateFastLinkRequest.php new file mode 100644 index 00000000..084c2342 --- /dev/null +++ b/src/Iyzipay/Request/Iyzilink/IyziLinkCreateFastLinkRequest.php @@ -0,0 +1,54 @@ +description; + } + + public function setDescription(string $description): void { + $this->description = $description; + } + + public function getPrice() { + return $this->price; + } + + public function setPrice($price): void { + $this->price = $price; + } + + public function getCurrencyCode(): string { + return $this->currencyCode; + } + + public function setCurrencyCode(string $currencyCode): void { + $this->currencyCode = $currencyCode; + } + + public function getSourceType(): string { + return $this->sourceType; + } + + public function setSourceType(string $sourceType): void { + $this->sourceType = $sourceType; + } + + public function getJsonObject() { + return JsonBuilder::fromJsonObject(parent::getJsonObject()) + ->add('description', $this->getDescription()) + ->addPrice('price', $this->getPrice()) + ->add('currencyCode', $this->getCurrencyCode()) + ->add('sourceType', $this->getSourceType()) + ->getObject(); + } +} diff --git a/src/Iyzipay/Request/Iyzilink/IyziLinkSaveProductRequest.php b/src/Iyzipay/Request/Iyzilink/IyziLinkSaveProductRequest.php index 8c824ed7..e0d1b828 100644 --- a/src/Iyzipay/Request/Iyzilink/IyziLinkSaveProductRequest.php +++ b/src/Iyzipay/Request/Iyzilink/IyziLinkSaveProductRequest.php @@ -18,6 +18,9 @@ class IyziLinkSaveProductRequest extends Request private $token; private $url; private $imageUrl; + private $sourceType; + private $stockEnabled; + private $stockCount; public function getName() { @@ -129,6 +132,36 @@ public function setImageUrl($imageUrl) $this->imageUrl = $imageUrl; } + public function getSourceType() + { + return $this->sourceType; + } + + public function setSourceType($sourceType) + { + $this->sourceType = $sourceType; + } + + public function getStockEnabled() + { + return $this->stockEnabled; + } + + public function setStockEnabled($stockEnabled) + { + $this->stockEnabled = $stockEnabled; + } + + public function getStockCount() + { + return $this->stockCount; + } + + public function setStockCount($stockCount) + { + $this->stockCount = $stockCount; + } + public function getJsonObject() { return JsonBuilder::fromJsonObject(parent::getJsonObject()) @@ -143,6 +176,9 @@ public function getJsonObject() ->add("token", $this->getToken()) ->add("url", $this->getUrl()) ->add("imageUrl", $this->getImageUrl()) + ->add('sourceType', $this->getSourceType()) + ->add('stockEnabled', $this->getStockEnabled()) + ->add('stockCount', $this->getStockCount()) ->getObject(); } } \ No newline at end of file diff --git a/src/Iyzipay/Request/Iyzilink/IyziLinkSearchMerchantProductsRequest.php b/src/Iyzipay/Request/Iyzilink/IyziLinkSearchMerchantProductsRequest.php new file mode 100644 index 00000000..3d7ceb20 --- /dev/null +++ b/src/Iyzipay/Request/Iyzilink/IyziLinkSearchMerchantProductsRequest.php @@ -0,0 +1,43 @@ +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(); + } +} diff --git a/src/Iyzipay/Request/Iyzilink/IyziLinkUpdateProductStatusRequest.php b/src/Iyzipay/Request/Iyzilink/IyziLinkUpdateProductStatusRequest.php new file mode 100644 index 00000000..c97cebec --- /dev/null +++ b/src/Iyzipay/Request/Iyzilink/IyziLinkUpdateProductStatusRequest.php @@ -0,0 +1,34 @@ +token; + } + + public function setToken(string $token): void { + $this->token = $token; + } + + public function getProductStatus(): string { + return $this->productStatus; + } + + public function setProductStatus(string $productStatus): void { + $this->productStatus = $productStatus; + } + + public function getJsonObject() { + return JsonBuilder::fromJsonObject(parent::getJsonObject()) + ->add('token', $this->getToken()) + ->add('productStatus', $this->getProductStatus()) + ->getObject(); + } +} \ No newline at end of file diff --git a/src/Iyzipay/Request/RetrieveBlacklistedCardRequest.php b/src/Iyzipay/Request/RetrieveBlacklistedCardRequest.php new file mode 100644 index 00000000..efbebb70 --- /dev/null +++ b/src/Iyzipay/Request/RetrieveBlacklistedCardRequest.php @@ -0,0 +1,32 @@ +cardNumber; + } + + public function setCardNumber(string $cardNumber): void { + $this->cardNumber = $cardNumber; + } + + public function getJsonObject(): array { + return JsonBuilder::fromJsonObject(parent::getJsonObject()) + ->add("cardNumber", $this->getCardNumber()) + ->getObject(); + } + + public function toPKIRequestString(): string { + return RequestStringBuilder::create() + ->appendSuper(parent::toPKIRequestString()) + ->append("cardNumber", $this->getCardNumber()) + ->getRequestString(); + } +} \ No newline at end of file diff --git a/src/Iyzipay/Request/UpdateBlackListedCardRequest.php b/src/Iyzipay/Request/UpdateBlackListedCardRequest.php new file mode 100644 index 00000000..45801c18 --- /dev/null +++ b/src/Iyzipay/Request/UpdateBlackListedCardRequest.php @@ -0,0 +1,43 @@ +cardUserKey; + } + + public function setCardUserKey($cardUserKey): void { + $this->cardUserKey = $cardUserKey; + } + + public function getCardToken(): string { + return $this->cardToken; + } + + public function setCardToken($cardToken): void { + $this->cardToken = $cardToken; + } + + public function getJsonObject(): array { + return JsonBuilder::fromJsonObject(parent::getJsonObject()) + ->add("cardToken", $this->getCardToken()) + ->add("cardUserKey", $this->getCardUserKey()) + ->getObject(); + } + + public function toPKIRequestString(): string { + return RequestStringBuilder::create() + ->appendSuper(parent::toPKIRequestString()) + ->append("cardToken", $this->getCardToken()) + ->append("cardUserKey", $this->getCardUserKey()) + ->getRequestString(); + } +} diff --git a/src/Iyzipay/RequestStringBuilder.php b/src/Iyzipay/RequestStringBuilder.php index 13682a77..784f1102 100644 --- a/src/Iyzipay/RequestStringBuilder.php +++ b/src/Iyzipay/RequestStringBuilder.php @@ -139,7 +139,6 @@ public function getRequestString() public static function requestToStringQuery(Request $request, $type = null) { - $stringQuery = false; if($request->getConversationId()) { @@ -150,6 +149,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(); 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/BlacklistedCardTest.php b/tests/Iyzipay/Tests/Model/BlacklistedCardTest.php new file mode 100644 index 00000000..9dcbd0c8 --- /dev/null +++ b/tests/Iyzipay/Tests/Model/BlacklistedCardTest.php @@ -0,0 +1,29 @@ +expectHttpPost(); + $blacklistedCard = BlacklistedCard::create(new CreateBlackListedCardRequest(), $this->options); + $this->verifyResource($blacklistedCard); + } + + public function test_should_retrieve_blacklisted_card() { + $this->expectHttpPost(); + $blacklistedCard = BlacklistedCard::retrieve(new RetrieveBlacklistedCardRequest(), $this->options); + $this->verifyResource($blacklistedCard); + } + + public function test_should_update_blacklisted_card() { + $this->expectHttpPost(); + $blacklistedCard = BlacklistedCard::update(new UpdateBlackListedCardRequest(), $this->options); + $this->verifyResource($blacklistedCard); + } +} diff --git a/tests/Iyzipay/Tests/Model/Iyzilink/IyziLinkCreateFastLinkTest.php b/tests/Iyzipay/Tests/Model/Iyzilink/IyziLinkCreateFastLinkTest.php new file mode 100644 index 00000000..e2a476cd --- /dev/null +++ b/tests/Iyzipay/Tests/Model/Iyzilink/IyziLinkCreateFastLinkTest.php @@ -0,0 +1,23 @@ +setLocale(\Iyzipay\Model\Locale::TR); + $request->setConversationId("123456789"); + $request->setDescription("ft-description-fast-link"); + $request->setPrice(10); + $request->setCurrencyCode("TRY"); + $request->setSourceType("WEB"); + + $this->expectHttpPost(); + $fastLink = IyziLinkFastLink::create($request, $this->options); + $this->verifyResource($fastLink); + } +} diff --git a/tests/Iyzipay/Tests/Model/Iyzilink/IyziLinkSearchMerchantProductsTest.php b/tests/Iyzipay/Tests/Model/Iyzilink/IyziLinkSearchMerchantProductsTest.php new file mode 100644 index 00000000..4d5e0a55 --- /dev/null +++ b/tests/Iyzipay/Tests/Model/Iyzilink/IyziLinkSearchMerchantProductsTest.php @@ -0,0 +1,21 @@ +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); + } +} diff --git a/tests/Iyzipay/Tests/Model/Iyzilink/IyziLinkUpdateProductStatusTest.php b/tests/Iyzipay/Tests/Model/Iyzilink/IyziLinkUpdateProductStatusTest.php new file mode 100644 index 00000000..fabd0c8d --- /dev/null +++ b/tests/Iyzipay/Tests/Model/Iyzilink/IyziLinkUpdateProductStatusTest.php @@ -0,0 +1,21 @@ +setLocale(\Iyzipay\Model\Locale::TR); + $request->setToken('AAM'); + $request->setProductStatus(Status::PASSIVE); + + $this->expectHttpPut(); + $iyziLinkUpdateProductStatus = IyziLinkUpdateProductStatus::create($request, $this->options); + $this->verifyResource($iyziLinkUpdateProductStatus); + } +} diff --git a/tests/Iyzipay/Tests/Model/Mapper/BlacklistedCardMapperTest.php b/tests/Iyzipay/Tests/Model/Mapper/BlacklistedCardMapperTest.php new file mode 100644 index 00000000..d67a95e8 --- /dev/null +++ b/tests/Iyzipay/Tests/Model/Mapper/BlacklistedCardMapperTest.php @@ -0,0 +1,43 @@ +retrieveJsonFile('blacklisted-card.json'); + + $blacklistedCard = BlacklistedCardMapper::create($json)->jsonDecode()->mapBlacklistedCard(new BlacklistedCard()); + + $this->assertNotEmpty($blacklistedCard); + $this->assertEquals(Status::FAILURE, $blacklistedCard->getStatus()); + $this->assertEquals("123456", $blacklistedCard->getConversationId()); + $this->assertEquals("10000", $blacklistedCard->getErrorCode()); + $this->assertEquals("error message", $blacklistedCard->getErrorMessage()); + $this->assertEquals("ERROR_GROUP", $blacklistedCard->getErrorGroup()); + $this->assertEquals(Locale::TR, $blacklistedCard->getLocale()); + $this->assertEquals("1458545234852", $blacklistedCard->getSystemTime()); + $this->assertEquals("cardUserKey", $blacklistedCard->getCardUserKey()); + $this->assertEquals("cardToken", $blacklistedCard->getCardToken()); + } + + public function test_should_map_retrieve_blacklisted_card() { + $json = $this->retrieveJsonFile('retrieve-blacklisted-card.json'); + + $blacklistedCard = BlacklistedCardMapper::create($json)->jsonDecode()->mapRetrieveBlacklistedCard(new BlacklistedCard()); + + $this->assertEquals(Status::FAILURE, $blacklistedCard->getStatus()); + $this->assertEquals("123456", $blacklistedCard->getConversationId()); + $this->assertEquals("10000", $blacklistedCard->getErrorCode()); + $this->assertEquals("error message", $blacklistedCard->getErrorMessage()); + $this->assertEquals("ERROR_GROUP", $blacklistedCard->getErrorGroup()); + $this->assertEquals(Locale::TR, $blacklistedCard->getLocale()); + $this->assertEquals("1458545234852", $blacklistedCard->getSystemTime()); + $this->assertEquals("cardNumber", $blacklistedCard->getCardNumber()); + } +} diff --git a/tests/Iyzipay/Tests/Model/Mapper/Iyzilink/IyziLinkUpdateProductStatusMapperTest.php b/tests/Iyzipay/Tests/Model/Mapper/Iyzilink/IyziLinkUpdateProductStatusMapperTest.php new file mode 100644 index 00000000..28dea879 --- /dev/null +++ b/tests/Iyzipay/Tests/Model/Mapper/Iyzilink/IyziLinkUpdateProductStatusMapperTest.php @@ -0,0 +1,21 @@ +retrieveJsonFile("iyzilink-update-product-status.json"); + $iyziLinkUpdateProductStatus = IyziLinkUpdateProductStatusMapper::create($json)->jsonDecode()->mapIyziLinkUpdateProductStatus(new IyziLinkUpdateProductStatus()); + + $this->assertNotEmpty($iyziLinkUpdateProductStatus); + $this->assertEquals(Status::SUCCESS, $iyziLinkUpdateProductStatus->getStatus()); + $this->assertEquals(Locale::TR, $iyziLinkUpdateProductStatus->getLocale()); + $this->assertEquals(1710349430773, $iyziLinkUpdateProductStatus->getSystemTime()); + } +} diff --git a/tests/Iyzipay/Tests/Request/CreateBlacklistedCardRequestTest.php b/tests/Iyzipay/Tests/Request/CreateBlacklistedCardRequestTest.php new file mode 100644 index 00000000..27c825bd --- /dev/null +++ b/tests/Iyzipay/Tests/Request/CreateBlacklistedCardRequestTest.php @@ -0,0 +1,54 @@ +prepareRequest(); + $jsonObject = $request->getJsonObject(); + + $this->assertEquals(Locale::TR, $jsonObject["locale"]); + $this->assertEquals("123456789", $jsonObject["conversationId"]); + $this->assertEquals("card user key", $jsonObject["cardUserKey"]); + $this->assertEquals("card token", $jsonObject["cardToken"]); + } + + public function test_should_convert_to_pki_request_string(): void { + $request = $this->prepareRequest(); + + $str = "[locale=tr," . + "conversationId=123456789," . + "cardUserKey=card user key," . + "cardToken=card token]"; + + $this->assertEquals($str, $request->toPKIRequestString()); + } + + public function test_should_get_json_string(): void { + $request = $this->prepareRequest(); + + $json = ' + { + "locale":"tr", + "conversationId":"123456789", + "cardToken":"card token", + "cardUserKey":"card user key" + }'; + + $this->assertJson($request->toJsonString()); + $this->assertJsonStringEqualsJsonString($json, $request->toJsonString()); + } + + private function prepareRequest(): CreateBlackListedCardRequest { + $request = new CreateBlackListedCardRequest(); + $request->setLocale(Locale::TR); + $request->setConversationId("123456789"); + $request->setCardUserKey("card user key"); + $request->setCardToken("card token"); + return $request; + } +} diff --git a/tests/Iyzipay/Tests/Request/Iyzilink/IyziLinkCreateFastLinkRequestTest.php b/tests/Iyzipay/Tests/Request/Iyzilink/IyziLinkCreateFastLinkRequestTest.php new file mode 100644 index 00000000..4f8d134b --- /dev/null +++ b/tests/Iyzipay/Tests/Request/Iyzilink/IyziLinkCreateFastLinkRequestTest.php @@ -0,0 +1,35 @@ +prepareRequest(); + $jsonObject = $request->getJsonObject(); + + $this->assertEquals(Locale::TR, $jsonObject["locale"]); + $this->assertEquals("123456789", $jsonObject["conversationId"]); + $this->assertEquals("ft-description-fast-link", $jsonObject["description"]); + $this->assertEquals(10, $jsonObject["price"]); + $this->assertEquals(Currency::TL, $jsonObject["currencyCode"]); + $this->assertEquals("WEB", $jsonObject["sourceType"]); + } + + public function prepareRequest(): IyziLinkCreateFastLinkRequest { + $request = new IyziLinkCreateFastLinkRequest(); + $request->setLocale(Locale::TR); + $request->setConversationId("123456789"); + $request->setDescription("ft-description-fast-link"); + $request->setPrice(10); + $request->setCurrencyCode("TRY"); + $request->setSourceType("WEB"); + + return $request; + } +} diff --git a/tests/Iyzipay/Tests/Request/Iyzilink/IyziLinkSaveRequestProductTest.php b/tests/Iyzipay/Tests/Request/Iyzilink/IyziLinkSaveRequestProductTest.php index 367ce4e9..0942b41d 100644 --- a/tests/Iyzipay/Tests/Request/Iyzilink/IyziLinkSaveRequestProductTest.php +++ b/tests/Iyzipay/Tests/Request/Iyzilink/IyziLinkSaveRequestProductTest.php @@ -2,7 +2,7 @@ namespace Iyzipay\Tests\Request\Iyzilink; use Iyzipay\Tests\TestCase; -use IyziPay\Request\Iyzilink\IyziLinkSaveProductRequest; +use Iyzipay\Request\Iyzilink\IyziLinkSaveProductRequest; use Iyzipay\Model\Locale; use Iyzipay\Model\Currency; use Iyzipay\FileBase64Encoder; @@ -28,6 +28,9 @@ public function test_should_save_request_object() $this->assertEquals("test", $jsonObject["token"]); $this->assertEquals("test", $jsonObject["url"]); $this->assertEquals("test", $jsonObject["imageUrl"]); + $this->assertEquals("API", $jsonObject['sourceType']); + $this->assertTrue($jsonObject['stockEnabled']); + $this->assertEquals(1, $jsonObject['stockCount']); } @@ -48,6 +51,9 @@ private function prepareRequest() $request->setToken('test'); $request->setUrl('test'); $request->setImageUrl('test'); + $request->setSourceType('API'); + $request->setStockEnabled(true); + $request->setStockCount(1); return $request; } diff --git a/tests/Iyzipay/Tests/Request/Iyzilink/IyziLinkSearchMerchantProductsRequestTest.php b/tests/Iyzipay/Tests/Request/Iyzilink/IyziLinkSearchMerchantProductsRequestTest.php new file mode 100644 index 00000000..15bea67e --- /dev/null +++ b/tests/Iyzipay/Tests/Request/Iyzilink/IyziLinkSearchMerchantProductsRequestTest.php @@ -0,0 +1,29 @@ +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; + } +} diff --git a/tests/Iyzipay/Tests/Request/Iyzilink/IyziLinkUpdateProductStatusRequestTest.php b/tests/Iyzipay/Tests/Request/Iyzilink/IyziLinkUpdateProductStatusRequestTest.php new file mode 100644 index 00000000..2bdf273e --- /dev/null +++ b/tests/Iyzipay/Tests/Request/Iyzilink/IyziLinkUpdateProductStatusRequestTest.php @@ -0,0 +1,28 @@ +prepareRequest(); + $jsonObject = $request->getJsonObject(); + + $this->assertEquals(Locale::TR, $jsonObject["locale"]); + $this->assertEquals("AAM", $jsonObject["token"]); + $this->assertEquals(Status::PASSIVE, $jsonObject['productStatus']); + } + + public function prepareRequest(): IyziLinkUpdateProductStatusRequest { + $request = new IyziLinkUpdateProductStatusRequest(); + $request->setLocale(Locale::TR); + $request->setToken('AAM'); + $request->setProductStatus(Status::PASSIVE); + + return $request; + } +} diff --git a/tests/Iyzipay/Tests/Request/RetrieveBlacklistedCardRequestTest.php b/tests/Iyzipay/Tests/Request/RetrieveBlacklistedCardRequestTest.php new file mode 100644 index 00000000..91c11b7e --- /dev/null +++ b/tests/Iyzipay/Tests/Request/RetrieveBlacklistedCardRequestTest.php @@ -0,0 +1,50 @@ +prepareRequest(); + $jsonObject = $request->getJsonObject(); + + $this->assertEquals(Locale::TR, $jsonObject["locale"]); + $this->assertEquals("123456789", $jsonObject["conversationId"]); + $this->assertEquals("card number", $jsonObject["cardNumber"]); + } + + public function test_should_convert_to_pki_request_string() { + $request = $this->prepareRequest(); + + $str = "[locale=tr," . + "conversationId=123456789," . + "cardNumber=card number]"; + + $this->assertEquals($str, $request->toPKIRequestString()); + } + + public function test_should_get_json_string() { + $request = $this->prepareRequest(); + + $json = ' + { + "locale":"tr", + "conversationId":"123456789", + "cardNumber":"card number" + }'; + + $this->assertJson($request->toJsonString()); + $this->assertJsonStringEqualsJsonString($json, $request->toJsonString()); + } + + private function prepareRequest(): RetrieveBlacklistedCardRequest { + $request = new RetrieveBlacklistedCardRequest(); + $request->setLocale(Locale::TR); + $request->setConversationId("123456789"); + $request->setCardNumber("card number"); + return $request; + } +} diff --git a/tests/Iyzipay/Tests/Request/UpdateBlacklistedCardRequestTest.php b/tests/Iyzipay/Tests/Request/UpdateBlacklistedCardRequestTest.php new file mode 100644 index 00000000..f05046bb --- /dev/null +++ b/tests/Iyzipay/Tests/Request/UpdateBlacklistedCardRequestTest.php @@ -0,0 +1,54 @@ +prepareRequest(); + $jsonObject = $request->getJsonObject(); + + $this->assertEquals(Locale::TR, $jsonObject["locale"]); + $this->assertEquals("123456789", $jsonObject["conversationId"]); + $this->assertEquals("card user key", $jsonObject["cardUserKey"]); + $this->assertEquals("card token", $jsonObject["cardToken"]); + } + + public function test_should_convert_to_pki_request_string(): void { + $request = $this->prepareRequest(); + + $str = "[locale=tr," . + "conversationId=123456789," . + "cardUserKey=card user key," . + "cardToken=card token]"; + + $this->assertEquals($str, $request->toPKIRequestString()); + } + + public function test_should_get_json_string(): void { + $request = $this->prepareRequest(); + + $json = ' + { + "locale":"tr", + "conversationId":"123456789", + "cardToken":"card token", + "cardUserKey":"card user key" + }'; + + $this->assertJson($request->toJsonString()); + $this->assertJsonStringEqualsJsonString($json, $request->toJsonString()); + } + + private function prepareRequest(): UpdateBlackListedCardRequest { + $request = new UpdateBlackListedCardRequest(); + $request->setLocale(Locale::TR); + $request->setConversationId("123456789"); + $request->setCardUserKey("card user key"); + $request->setCardToken("card token"); + 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 +} diff --git a/tests/Iyzipay/Tests/mock/blacklisted-card.json b/tests/Iyzipay/Tests/mock/blacklisted-card.json new file mode 100644 index 00000000..8261b86a --- /dev/null +++ b/tests/Iyzipay/Tests/mock/blacklisted-card.json @@ -0,0 +1,12 @@ +{ + "status": "failure", + "errorCode": 10000, + "errorMessage": "error message", + "errorGroup": "ERROR_GROUP", + "locale": "tr", + "systemTime": "1458545234852", + "conversationId": "123456", + "cardUserKey": "cardUserKey", + "cardToken": "cardToken", + "cardNumber": "cardNumber" +} \ No newline at end of file diff --git a/tests/Iyzipay/Tests/mock/iyzilink.update-product-status.json b/tests/Iyzipay/Tests/mock/iyzilink.update-product-status.json new file mode 100644 index 00000000..6bf40b51 --- /dev/null +++ b/tests/Iyzipay/Tests/mock/iyzilink.update-product-status.json @@ -0,0 +1,5 @@ +{ + "status": "success", + "locale": "tr", + "systemTime": "1710349430773" +} \ No newline at end of file diff --git a/tests/Iyzipay/Tests/mock/retrieve-blacklisted-card.json b/tests/Iyzipay/Tests/mock/retrieve-blacklisted-card.json new file mode 100644 index 00000000..95bf5f09 --- /dev/null +++ b/tests/Iyzipay/Tests/mock/retrieve-blacklisted-card.json @@ -0,0 +1,10 @@ +{ + "status": "failure", + "errorCode": 10000, + "errorMessage": "error message", + "errorGroup": "ERROR_GROUP", + "locale": "tr", + "systemTime": "1458545234852", + "conversationId": "123456", + "cardNumber": "cardNumber" +}