diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..6e30299c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ +* text=auto + +/tests export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/phpunit.xml.dist export-ignore +/README.markdown export-ignore +/CHANGELOG.markdown export-ignore \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..c6653fb9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ +# VI generated files +.*.sw[a-z] +*.un~ +Session.vim +.DS_Store + +# IntelliJ Idea generated files +*.ipr +*.iws +.idea +*.iml +*plugin.xml + +# Eclipse generated files +*.pydevproject +.project +.metadata +bin/** +tmp/** +tmp/**/* +*~.nib +.classpath +.settings/ +.loadpath +.git/ +build/ +.buildpath + +# Composer specific files +composer.lock +#composer.phar // TODO: Remove after release +vendor/* diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown new file mode 100644 index 00000000..a48fd43b --- /dev/null +++ b/CHANGELOG.markdown @@ -0,0 +1,6 @@ +# Changelog + +## 1.0.0 + +- Initialized git project. +- Added bootstrap and composer support. \ No newline at end of file diff --git a/IyzipayBootstrap.php b/IyzipayBootstrap.php new file mode 100644 index 00000000..db020e6c --- /dev/null +++ b/IyzipayBootstrap.php @@ -0,0 +1,183 @@ +register(); + } +} + +/* + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This software consists of voluntary contributions made by many individuals + * and is licensed under the MIT license. For more information, see + * . + */ + +/** + * SplClassLoader implementation that implements the technical interoperability + * standards for PHP 5.3 namespaces and class names. + * + * http://groups.google.com/group/php-standards/web/psr-0-final-proposal?pli=1 + * + * // Example which loads classes for the Doctrine Common package in the + * // Doctrine\Common namespace. + * $classLoader = new SplClassLoader('Doctrine\Common', '/path/to/doctrine'); + * $classLoader->register(); + * + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @author Jonathan H. Wage + * @author Roman S. Borschel + * @author Matthew Weier O'Phinney + * @author Kris Wallsmith + * @author Fabien Potencier + */ +class SplClassLoader +{ + private $_fileExtension = '.php'; + private $_namespace; + private $_includePath; + private $_namespaceSeparator = '\\'; + + /** + * Creates a new SplClassLoader that loads classes of the + * specified namespace. + * + * @param string $ns + * The namespace to use. + * @param string $includePath + * The base path. + */ + public function __construct($ns = null, $includePath = null) + { + $this->_namespace = $ns; + $this->_includePath = $includePath; + } + + /** + * Sets the namespace separator used by classes in the namespace of this class loader. + * + * @param string $sep + * The separator to use. + */ + public function setNamespaceSeparator($sep) + { + $this->_namespaceSeparator = $sep; + } + + /** + * Gets the namespace separator used by classes in the namespace of this class loader. + * + * @return string $_namespaceSeparator + */ + public function getNamespaceSeparator() + { + return $this->_namespaceSeparator; + } + + /** + * Sets the base include path for all class files in the namespace of this class loader. + * + * @param string $includePath + */ + public function setIncludePath($includePath) + { + $this->_includePath = $includePath; + } + + /** + * Gets the base include path for all class files in the namespace of this class loader. + * + * @return string $includePath + */ + public function getIncludePath() + { + return $this->_includePath; + } + + /** + * Sets the file extension of class files in the namespace of this class loader. + * + * @param string $fileExtension + */ + public function setFileExtension($fileExtension) + { + $this->_fileExtension = $fileExtension; + } + + /** + * Gets the file extension of class files in the namespace of this class loader. + * + * @return string $fileExtension + */ + public function getFileExtension() + { + return $this->_fileExtension; + } + + /** + * Installs this class loader on the SPL autoload stack. + */ + public function register() + { + spl_autoload_register(array( + $this, + 'loadClass' + )); + } + + /** + * Uninstalls this class loader from the SPL autoloader stack. + */ + public function unregister() + { + spl_autoload_unregister(array( + $this, + 'loadClass' + )); + } + + /** + * Loads the given class or interface. + * + * @param string $className + * The name of the class to load. + * @return void + */ + public function loadClass($className) + { + if (null === $this->_namespace || $this->_namespace . $this->_namespaceSeparator === substr($className, 0, strlen($this->_namespace . $this->_namespaceSeparator))) { + $fileName = ''; + if (false !== ($lastNsPos = strripos($className, $this->_namespaceSeparator))) { + $namespace = substr($className, 0, $lastNsPos); + $className = substr($className, $lastNsPos + 1); + $fileName = str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; + } + $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . $this->_fileExtension; + + require ($this->_includePath !== null ? $this->_includePath . DIRECTORY_SEPARATOR : '') . $fileName; + } + } +} \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..3f513ac8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 - iyzico Ödeme Hizmetleri A.Ş. (https://iyzico.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.markdown b/README.markdown new file mode 100644 index 00000000..d455e728 --- /dev/null +++ b/README.markdown @@ -0,0 +1 @@ +# iyzipay API PHP Client \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 00000000..1b16f1d6 --- /dev/null +++ b/composer.json @@ -0,0 +1,32 @@ +{ + "name": "iyzico/iyzipay-php", + "type": "library", + "description": "iyzipay api php client", + "homepage": "https://github.com/iyzico/iyzipay-php", + "keywords": [ + "iyzico", + "iyzipay", + "iyzico.com", + "iyzipay php", + "iyzipay api", + "iyzipay api php client", + "iyzipay api php" + ], + "license": "MIT", + "authors": [ + { + "name": "Sabri Onur Tuzun", + "email": "onur.tuzun@iyzico.com", + "homepage": "http://www.iyzico.com" + } + ], + "require": {}, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "autoload": { + "psr-0": { + "Iyzipay": "src/" + } + } +} diff --git a/composer.phar b/composer.phar new file mode 100755 index 00000000..1f745ef3 Binary files /dev/null and b/composer.phar differ diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 00000000..c5a1efd5 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,31 @@ + + + + + + + ./tests/Iyzipay/ + + + + + + functional + + + + + + ./src/Iyzipay/ + + + diff --git a/samples/AutoloadBinNumberSample.php b/samples/AutoloadBinNumberSample.php new file mode 100644 index 00000000..6d4adb2a --- /dev/null +++ b/samples/AutoloadBinNumberSample.php @@ -0,0 +1,21 @@ +setApiKey("api key"); +$options->setSecretKey("secret key"); +$options->setBaseUrl("https://stg.iyzipay.com"); + +# create request class +$request = new \Iyzipay\Request\RetrieveBinNumberRequest(); +$request->setLocale(\Iyzipay\Model\Locale::TR); +$request->setConversationId("123456789"); +$request->setBinNumber("554960"); + +# make request +$binNumber = \Iyzipay\Model\BinNumber::retrieve($request, $options); + +# print response +print_r($binNumber); \ No newline at end of file diff --git a/samples/BootstrapBinNumberSample.php b/samples/BootstrapBinNumberSample.php new file mode 100644 index 00000000..256e4f9f --- /dev/null +++ b/samples/BootstrapBinNumberSample.php @@ -0,0 +1,23 @@ +setApiKey("api key"); +$options->setSecretKey("secret key"); +$options->setBaseUrl("https://stg.iyzipay.com"); + +# create request class +$request = new \Iyzipay\Request\RetrieveBinNumberRequest(); +$request->setLocale(\Iyzipay\Model\Locale::TR); +$request->setConversationId("123456789"); +$request->setBinNumber("554960"); + +# make request +$binNumber = \Iyzipay\Model\BinNumber::retrieve($request, $options); + +# print response +print_r($binNumber); \ No newline at end of file diff --git a/src/Iyzipay/BaseModel.php b/src/Iyzipay/BaseModel.php new file mode 100644 index 00000000..5d5ae150 --- /dev/null +++ b/src/Iyzipay/BaseModel.php @@ -0,0 +1,11 @@ +getJsonObject()); + } +} \ No newline at end of file diff --git a/src/Iyzipay/HashGenerator.php b/src/Iyzipay/HashGenerator.php new file mode 100644 index 00000000..b0d797a4 --- /dev/null +++ b/src/Iyzipay/HashGenerator.php @@ -0,0 +1,12 @@ +toPKIRequestString(); + return base64_encode(sha1($hashStr, true)); + } +} \ No newline at end of file diff --git a/src/Iyzipay/HttpClient.php b/src/Iyzipay/HttpClient.php new file mode 100644 index 00000000..b023fc57 --- /dev/null +++ b/src/Iyzipay/HttpClient.php @@ -0,0 +1,66 @@ +exchange($url, array( + CURLOPT_CUSTOMREQUEST => "GET", + CURLOPT_RETURNTRANSFER => true, + CURLOPT_VERBOSE => false, + CURLOPT_HEADER => false, + CURLOPT_HTTPHEADER => $header + )); + } + + public function post($url, $header, $content) + { + return $this->exchange($url, array( + CURLOPT_CUSTOMREQUEST => "POST", + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => $content, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_VERBOSE => false, + CURLOPT_HEADER => false, + CURLOPT_HTTPHEADER => $header + )); + } + + public function put($url, $header, $content) + { + return $this->exchange($url, array( + CURLOPT_CUSTOMREQUEST => "PUT", + CURLOPT_POSTFIELDS => $content, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_VERBOSE => false, + CURLOPT_HEADER => false, + CURLOPT_HTTPHEADER => $header + )); + } + + public function delete($url, $header, $content = null) + { + return $this->exchange($url, array( + CURLOPT_CUSTOMREQUEST => "DELETE", + CURLOPT_POSTFIELDS => $content, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_VERBOSE => false, + CURLOPT_HEADER => false, + CURLOPT_HTTPHEADER => $header + )); + } + + public function exchange($url, $options) + { + $ch = curl_init($url); + curl_setopt_array($ch, $options); + return curl_exec($ch); + } +} \ No newline at end of file diff --git a/src/Iyzipay/IyzipayResource.php b/src/Iyzipay/IyzipayResource.php new file mode 100644 index 00000000..48ac0d2b --- /dev/null +++ b/src/Iyzipay/IyzipayResource.php @@ -0,0 +1,103 @@ +getApiKey(), $options->getSecretKey(), $randomHeaderValue, $request); + return RequestHelper::formatHeaderString(array($options->getApiKey(), $hash)); + } + + public function getStatus() + { + return $this->status; + } + + public function setStatus($status) + { + $this->status = $status; + } + + public function getErrorCode() + { + return $this->errorCode; + } + + public function setErrorCode($errorCode) + { + $this->errorCode = $errorCode; + } + + public function getErrorMessage() + { + return $this->errorMessage; + } + + public function setErrorMessage($errorMessage) + { + $this->errorMessage = $errorMessage; + } + + public function getErrorGroup() + { + return $this->errorGroup; + } + + public function setErrorGroup($errorGroup) + { + $this->errorGroup = $errorGroup; + } + + public function getLocale() + { + return $this->locale; + } + + public function setLocale($locale) + { + $this->locale = $locale; + } + + public function getSystemTime() + { + return $this->systemTime; + } + + public function setSystemTime($systemTime) + { + $this->systemTime = $systemTime; + } + + public function getConversationId() + { + return $this->conversationId; + } + + public function setConversationId($conversationId) + { + $this->conversationId = $conversationId; + } +} \ No newline at end of file diff --git a/src/Iyzipay/JsonBuilder.php b/src/Iyzipay/JsonBuilder.php new file mode 100644 index 00000000..5af6dd1f --- /dev/null +++ b/src/Iyzipay/JsonBuilder.php @@ -0,0 +1,87 @@ +json = $json; + } + + public static function create() + { + return new JsonBuilder(array()); + } + + public static function fromJsonObject($json) + { + return new JsonBuilder($json); + } + + /** + * @param $key + * @param $value + * @return JsonBuilder + */ + public function add($key, $value = null) + { + if (isset($value)) { + if ($value instanceof JsonConvertible) { + $this->json[$key] = $value->getJsonObject(); + } else { + $this->json[$key] = $value; + } + } + return $this; + } + + /** + * @param $key + * @param $value + * @return JsonBuilder + */ + public function addPrice($key, $value = null) + { + if (isset($value)) { + $this->json[$key] = RequestFormatter::formatPrice($value); + } + return $this; + } + + /** + * @param $key + * @param array $array + * @return JsonBuilder + */ + public function addArray($key, array $array = null) + { + if (isset($array)) { + foreach ($array as $index => $value) { + if ($value instanceof JsonConvertible) { + $this->json[$key][$index] = $value->getJsonObject(); + } else { + $this->json[$key][$index] = $value; + } + } + } + return $this; + } + + public function getObject() + { + return $this->json; + } + + public static function jsonEncode($jsonObject) + { + return json_encode($jsonObject); + } + + public static function jsonDecode($rawResult) + { + return json_decode($rawResult); + } +} \ No newline at end of file diff --git a/src/Iyzipay/JsonConvertible.php b/src/Iyzipay/JsonConvertible.php new file mode 100644 index 00000000..9c5180f8 --- /dev/null +++ b/src/Iyzipay/JsonConvertible.php @@ -0,0 +1,10 @@ +post($options->getBaseUrl() . "/payment/bin/check", parent::getHttpHeaders($request, $options), $request->toJsonString()); + return BinNumberMapper::create()->map(new BinNumber(), JsonBuilder::jsonDecode($rawResult)); + } + + public function getBinNumber() + { + return $this->binNumber; + } + + public function setBinNumber($binNumber) + { + $this->binNumber = $binNumber; + } + + public function getCardType() + { + return $this->cardType; + } + + public function setCardType($cardType) + { + $this->cardType = $cardType; + } + + public function getCardAssociation() + { + return $this->cardAssociation; + } + + public function setCardAssociation($cardAssociation) + { + $this->cardAssociation = $cardAssociation; + } + + public function getCardFamily() + { + return $this->cardFamily; + } + + public function setCardFamily($cardFamily) + { + $this->cardFamily = $cardFamily; + } + + public function getBankName() + { + return $this->bankName; + } + + public function setBankName($bankName) + { + $this->bankName = $bankName; + } + + public function getBankCode() + { + return $this->bankCode; + } + + public function setBankCode($bankCode) + { + $this->bankCode = $bankCode; + } +} \ No newline at end of file diff --git a/src/Iyzipay/Model/Locale.php b/src/Iyzipay/Model/Locale.php new file mode 100644 index 00000000..229bb819 --- /dev/null +++ b/src/Iyzipay/Model/Locale.php @@ -0,0 +1,9 @@ +binNumber)) { + $binNumber->setBinNumber($jsonResult->binNumber); + } + if (isset($jsonResult->cardType)) { + $binNumber->setCardType($jsonResult->cardType); + } + if (isset($jsonResult->cardAssociation)) { + $binNumber->setCardAssociation($jsonResult->cardAssociation); + } + if (isset($jsonResult->cardFamily)) { + $binNumber->setCardFamily($jsonResult->cardFamily); + } + if (isset($jsonResult->bankName)) { + $binNumber->setBankName($jsonResult->bankName); + } + if (isset($jsonResult->bankCode)) { + $binNumber->setBankCode($jsonResult->bankCode); + } + return $binNumber; + } +} \ No newline at end of file diff --git a/src/Iyzipay/Model/Mapper/IyzipayResourceMapper.php b/src/Iyzipay/Model/Mapper/IyzipayResourceMapper.php new file mode 100644 index 00000000..22a236a0 --- /dev/null +++ b/src/Iyzipay/Model/Mapper/IyzipayResourceMapper.php @@ -0,0 +1,39 @@ +status)) { + $resource->setStatus($jsonResult->status); + } + if (isset($jsonResult->conversationId)) { + $resource->setConversationId($jsonResult->conversationId); + } + if (isset($jsonResult->errorCode)) { + $resource->setErrorCode($jsonResult->errorCode); + } + if (isset($jsonResult->errorMessage)) { + $resource->setErrorMessage($jsonResult->errorMessage); + } + if (isset($jsonResult->errorGroup)) { + $resource->setErrorGroup($jsonResult->errorGroup); + } + if (isset($jsonResult->locale)) { + $resource->setLocale($jsonResult->locale); + } + if (isset($jsonResult->systemTime)) { + $resource->setSystemTime($jsonResult->systemTime); + } + return $resource; + } +} \ No newline at end of file diff --git a/src/Iyzipay/Model/Status.php b/src/Iyzipay/Model/Status.php new file mode 100644 index 00000000..0616a17e --- /dev/null +++ b/src/Iyzipay/Model/Status.php @@ -0,0 +1,9 @@ +apiKey; + } + + public function setApiKey($apiKey) + { + $this->apiKey = $apiKey; + } + + public function getSecretKey() + { + return $this->secretKey; + } + + public function setSecretKey($secretKey) + { + $this->secretKey = $secretKey; + } + + public function getBaseUrl() + { + return $this->baseUrl; + } + + public function setBaseUrl($baseUrl) + { + $this->baseUrl = $baseUrl; + } +} \ No newline at end of file diff --git a/src/Iyzipay/Request.php b/src/Iyzipay/Request.php new file mode 100644 index 00000000..906c16e9 --- /dev/null +++ b/src/Iyzipay/Request.php @@ -0,0 +1,45 @@ +locale; + } + + public function setLocale($locale) + { + $this->locale = $locale; + } + + public function getConversationId() + { + return $this->conversationId; + } + + public function setConversationId($conversationId) + { + $this->conversationId = $conversationId; + } + + public function getJsonObject() + { + return JsonBuilder::create() + ->add("locale", $this->getLocale()) + ->add("conversationId", $this->getConversationId()) + ->getObject(); + } + + public function toPKIRequestString() + { + return RequestStringBuilder::newInstance() + ->append("locale", $this->getLocale()) + ->append("conversationId", $this->getConversationId()) + ->getRequestString(); + } +} \ No newline at end of file diff --git a/src/Iyzipay/Request/RetrieveBinNumberRequest.php b/src/Iyzipay/Request/RetrieveBinNumberRequest.php new file mode 100644 index 00000000..a1b4425f --- /dev/null +++ b/src/Iyzipay/Request/RetrieveBinNumberRequest.php @@ -0,0 +1,37 @@ +binNumber; + } + + public function setBinNumber($binNumber) + { + $this->binNumber = $binNumber; + } + + public function getJsonObject() + { + return JsonBuilder::fromJsonObject(parent::getJsonObject()) + ->add("binNumber", $this->getBinNumber()) + ->getObject(); + } + + public function toPKIRequestString() + { + return RequestStringBuilder::newInstance() + ->appendSuper(parent::toPKIRequestString()) + ->append("binNumber", $this->getBinNumber()) + ->getRequestString(); + } +} \ No newline at end of file diff --git a/src/Iyzipay/RequestFormatter.php b/src/Iyzipay/RequestFormatter.php new file mode 100644 index 00000000..ac131238 --- /dev/null +++ b/src/Iyzipay/RequestFormatter.php @@ -0,0 +1,26 @@ +requestString = $requestString; + } + + public static function newInstance() + { + return new RequestStringBuilder(""); + } + + public static function fromRequestString($requestString) + { + return new RequestStringBuilder($requestString); + } + + /** + * @param $superRequestString + * @return RequestStringBuilder + */ + public function appendSuper($superRequestString) + { + if (isset($superRequestString)) { + $superRequestString = substr($superRequestString, 1); + $superRequestString = substr($superRequestString, 0, -1); + + if (strlen($superRequestString) > 0) { + $this->requestString = $this->requestString . $superRequestString . ","; + } + } + return $this; + } + + /** + * @param $key + * @param $value + * @return RequestStringBuilder + */ + public function append($key, $value = null) + { + if (isset($value)) { + if ($value instanceof RequestStringConvertible) { + $this->appendKeyValue($key, $value->toPKIRequestString()); + } else { + $this->appendKeyValue($key, $value); + } + } + return $this; + } + + /** + * @param $key + * @param $value + * @return RequestStringBuilder + */ + public function appendPrice($key, $value = null) + { + if (isset($value)) { + $this->appendKeyValue($key, RequestFormatter::formatPrice($value)); + } + return $this; + } + + /** + * @param $key + * @param array $array + * @return RequestStringBuilder + */ + public function appendArray($key, array $array = null) + { + if (isset($array)) { + $appendedValue = ""; + foreach ($array as $value) { + if ($value instanceof RequestStringConvertible) { + $appendedValue = $appendedValue . $value->toPKIRequestString(); + } else { + $appendedValue = $appendedValue . $value; + } + $appendedValue = $appendedValue . ", "; + } + $this->appendKeyValueArray($key, $appendedValue); + } + return $this; + } + + /** + * @param $key + * @param $value + * @return RequestStringBuilder + */ + private function appendKeyValue($key, $value) + { + if (isset($value)) { + $this->requestString = $this->requestString . $key . "=" . $value . ","; + } + return $this; + } + + /** + * @param $key + * @param $value + * @return RequestStringBuilder + */ + private function appendKeyValueArray($key, $value) + { + if (isset($value)) { + $value = substr($value, 0, -2); + $this->requestString = $this->requestString . $key . "=[" . $value . "],"; + } + return $this; + } + + /** + * @return RequestStringBuilder + */ + private function appendPrefix() + { + $this->requestString = "[" . $this->requestString . "]"; + return $this; + } + + /** + * @return RequestStringBuilder + */ + private function removeTrailingComma() + { + $this->requestString = substr($this->requestString, 0, -1); + return $this; + } + + public function getRequestString() + { + $this->removeTrailingComma(); + $this->appendPrefix(); + return $this->requestString; + } +} \ No newline at end of file diff --git a/src/Iyzipay/RequestStringConvertible.php b/src/Iyzipay/RequestStringConvertible.php new file mode 100644 index 00000000..b72da3fa --- /dev/null +++ b/src/Iyzipay/RequestStringConvertible.php @@ -0,0 +1,8 @@ +add('Iyzipay\Tests', __DIR__); + +return $loader; diff --git a/tests/Iyzipay/Tests/OptionsTest.php b/tests/Iyzipay/Tests/OptionsTest.php new file mode 100644 index 00000000..2c136e3c --- /dev/null +++ b/tests/Iyzipay/Tests/OptionsTest.php @@ -0,0 +1,16 @@ +setApiKey("api key"); + $options->setSecretKey("secret key"); + $options->setBaseUrl("base url"); + + $this->assertEquals("api key", $options->getApiKey()); + $this->assertEquals("secret key", $options->getSecretKey()); + $this->assertEquals("base url", $options->getBaseUrl()); + } +} \ No newline at end of file