├── src ├── n11Client.php └── Client │ ├── Contracts │ ├── GatewayInterface.php │ ├── GatewayAbstract.php │ ├── RequestInterface.php │ └── RequestAbstract.php │ ├── SoapRequest.php │ └── Gateway.php ├── tests └── n11Client │ ├── Client │ ├── SoapRequestTest.php │ ├── Contracts │ │ ├── GatewayAbstractTest.php │ │ └── RequestAbstractTest.php │ └── GatewayTest.php │ └── n11ClientTest.php ├── phpunit.xml ├── composer.json └── README.md /src/n11Client.php: -------------------------------------------------------------------------------- 1 | makeRequest($GLOBALS['soap_test_wsdl'],$GLOBALS['soap_test_wsdl_method']); 10 | $this->assertEquals('success',$response->result->status); 11 | } 12 | } -------------------------------------------------------------------------------- /tests/n11Client/n11ClientTest.php: -------------------------------------------------------------------------------- 1 | client = new n11Client(); 13 | } 14 | 15 | public function testToString() 16 | { 17 | $this->assertTrue(is_string($this->client->toString())); 18 | } 19 | } -------------------------------------------------------------------------------- /src/Client/Contracts/GatewayInterface.php: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | Tests 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/Client/Contracts/GatewayAbstract.php: -------------------------------------------------------------------------------- 1 | client = $request; 22 | } 23 | 24 | /** 25 | * @return RequestInterface 26 | */ 27 | public function getClient() 28 | { 29 | return $this->client; 30 | } 31 | } -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eray-akartuna/n11client", 3 | "description": "n11.com web service client", 4 | "keywords": [ 5 | "n11", 6 | "soap", 7 | "api", 8 | "client" 9 | ], 10 | "authors": [ 11 | { 12 | "name": "Eray Akartuna", 13 | "email": "erayakartuna@gmail.com" 14 | } 15 | ], 16 | "require": { 17 | "php": ">=5.4.0" 18 | }, 19 | "require-dev": { 20 | "phpunit/phpunit": "~4.0" 21 | }, 22 | "autoload": { 23 | "psr-4": { 24 | "ErayAkartuna\\n11Client\\": "src/" 25 | } 26 | }, 27 | "extra": { 28 | "branch-alias": { 29 | "dev-master": "4.1-dev" 30 | } 31 | }, 32 | "minimum-stability": "dev", 33 | "license": "MIT" 34 | } 35 | -------------------------------------------------------------------------------- /tests/n11Client/Client/Contracts/GatewayAbstractTest.php: -------------------------------------------------------------------------------- 1 | stub = $this->getMockForAbstractClass('\ErayAkartuna\n11Client\Client\Contracts\GatewayAbstract'); 9 | } 10 | 11 | public function testSetAndGetClient() 12 | { 13 | $request = $this->getMockForAbstractClass('\ErayAkartuna\n11Client\Client\Contracts\RequestAbstract'); 14 | $this->stub->setClient($request); 15 | $this->assertTrue(($request == $this->stub->getClient())); 16 | } 17 | 18 | public function testAuth() 19 | { 20 | $this->stub 21 | ->expects($this->any()) 22 | ->method('auth') 23 | ->will($this->returnValue(TRUE)); 24 | $this->assertTrue($this->stub->auth()); 25 | } 26 | } -------------------------------------------------------------------------------- /src/Client/Contracts/RequestInterface.php: -------------------------------------------------------------------------------- 1 | getParam('soap_options') ? $this->getParam('soap_options') : []; 19 | $this->deleteParam('soap_options'); 20 | 21 | $params = !empty($this->getParams()) ? array_merge($this->getParams(),$temp_params) : $temp_params; 22 | 23 | try{ 24 | $client = new \SoapClient($url,$soap_options); 25 | $response = $client->{$method}($params); 26 | } 27 | catch(\SoapFault $fault){ 28 | trigger_error("SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR); 29 | } 30 | 31 | return $response; 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /src/Client/Contracts/RequestAbstract.php: -------------------------------------------------------------------------------- 1 | params = $params; 25 | } 26 | 27 | /** 28 | * @return string 29 | */ 30 | public function getParams() 31 | { 32 | return $this->params; 33 | } 34 | 35 | /** 36 | * @param $key 37 | * @param $value 38 | */ 39 | public function setParam($key,$value) 40 | { 41 | $this->params[$key] = $value; 42 | } 43 | 44 | /** 45 | * @param $key 46 | * @return mixed 47 | */ 48 | public function getParam($key) 49 | { 50 | if(!isset($this->params[$key])) 51 | return false; 52 | 53 | return $this->params[$key]; 54 | } 55 | 56 | /** 57 | * @param $key 58 | * @return bool 59 | */ 60 | public function deleteParam($key) 61 | { 62 | if(!isset($this->params[$key])) 63 | return false; 64 | 65 | unset($this->params[$key]); 66 | return true; 67 | } 68 | 69 | 70 | } -------------------------------------------------------------------------------- /tests/n11Client/Client/Contracts/RequestAbstractTest.php: -------------------------------------------------------------------------------- 1 | stub = $this->getMockForAbstractClass('\ErayAkartuna\n11Client\Client\Contracts\RequestAbstract'); 9 | } 10 | 11 | public function testMakeRequest() 12 | { 13 | $this->stub 14 | ->expects($this->any()) 15 | ->method('makeRequest') 16 | ->with($GLOBALS['soap_test_wsdl'],$GLOBALS['soap_test_wsdl_method']) 17 | ->will($this->returnValue(TRUE)); 18 | 19 | $this->assertTrue($this->stub->makeRequest($GLOBALS['soap_test_wsdl'],$GLOBALS['soap_test_wsdl_method'])); 20 | } 21 | 22 | public function testSetAndGetParam() 23 | { 24 | $array = ['key' => 'value']; 25 | $this->stub->setParam('test',$array); 26 | $this->assertTrue(($array == $this->stub->getParam('test'))); 27 | } 28 | 29 | public function testSetAndGetParams() 30 | { 31 | $array = ['key' => 'value']; 32 | $this->stub->setParams($array); 33 | $params = $this->stub->getParams(); 34 | $this->assertTrue((isset($params['key']))); 35 | } 36 | 37 | public function testDeleteParam() 38 | { 39 | $array = ['key' => 'value']; 40 | 41 | $this->assertFalse($this->stub->getParam(key($array))); 42 | 43 | $this->stub->setParams($array); 44 | $this->assertNotFalse($this->stub->getParam(key($array))); 45 | 46 | $this->stub->deleteParam(key($array)); 47 | $this->assertFalse($this->stub->getParam(key($array))); 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # N11 Web Servis 2 | Bu kütüphane ile n11 web servislerine erişebilirsiniz. 3 | 4 | ###Örnek Kod 5 | ```php 6 | $client = new n11Client(); 7 | 8 | // App key ve app secretları giriyoruz. 9 | $client->auth(array('appKey' => 'xxxx-xxxx-xxxx','appSecret' => 'xxxxxxx')); 10 | 11 | $categories = $client->getTopLevelCategories(); //Kategorileri Çekiyoruz 12 | $cities = $client->getCities(); //İl listesine ulaşıyoruz. 13 | 14 | //Ürün ekleme - daha fazlası için n11 dökümanına bakabilirsiniz. 15 | $client->saveProduct([ 16 | 'productSellerCode' => 'exp-111', 17 | 'title' => 'Test Product', 18 | 'subtitle' => 'Web service test ', 19 | 'description' => 'test product detail', 20 | 'attributes' => 21 | [ 22 | 'attribute' => Array() 23 | ], 24 | 'category' => 25 | [ 26 | 'id' => 1000038 27 | ], 28 | 'price' => 0.99, 29 | 'currencyType' => 'TL', 30 | 'images' => 31 | [ 32 | 'image' => 33 | [ 34 | ] 35 | ], 36 | 'saleStartDate' => '', 37 | 'saleEndDate' => '', 38 | 'productionDate' => '', 39 | 'expirationDate' => '', 40 | 'productCondition' => '1', 41 | 'preparingDay' => '3', 42 | 'discount' => 10, 43 | 'shipmentTemplate' => 'Kapıda Ödeme', 44 | 'stockItems' => 45 | [ 46 | 'stockItem' => 47 | [ 48 | ] 49 | ] 50 | ]); 51 | ``` 52 | 53 | Yazılan diğer metodları görmek için client/Gateway.php dosyasını inceleyebilirsiniz. 54 | 55 | Geliştirmek için kodlarınızı n11Client.php içine ekleyebilirsiniz. 56 | 57 | -------------------------------------------------------------------------------- /tests/n11Client/Client/GatewayTest.php: -------------------------------------------------------------------------------- 1 | 1, 12 | 'exceptions' => 1, 13 | "stream_context" => stream_context_create( 14 | array( 15 | 'ssl' => array( 16 | 'verify_peer' => false, 17 | 'verify_peer_name' => false, 18 | ) 19 | ) 20 | ) 21 | ]; 22 | self::$gateway = new Gateway($soap_options); 23 | } 24 | 25 | public function testAuth() 26 | { 27 | $secrets = ['appKey' => $GLOBALS['app_key'] , 'appSecret' => $GLOBALS['app_secret']]; 28 | self::$gateway->auth($secrets); 29 | $this->assertEquals(($secrets == self::$gateway->getClient()->getParam('auth')),true); 30 | } 31 | 32 | /** 33 | * @depends testAuth 34 | */ 35 | public function testGetTopLevelCategories() 36 | { 37 | $categories = self::$gateway->getTopLevelCategories(); 38 | $this->assertEquals((count($categories) > 0),true); 39 | } 40 | 41 | /** 42 | * @depends testAuth 43 | */ 44 | public function testGetSubCategories() 45 | { 46 | $categories = self::$gateway->getTopLevelCategories(); 47 | $subcategories = self::$gateway->getSubCategories($categories[0]->id); 48 | $this->assertEquals((count($subcategories) > 0),true); 49 | } 50 | 51 | /** 52 | * @depends testAuth 53 | */ 54 | public function testGetProductList() 55 | { 56 | $limit = 10; 57 | $page = 0; 58 | $products = self::$gateway->getProductList($limit,$page); 59 | $this->assertEquals((count($products) == 10),true); 60 | } 61 | 62 | /** 63 | * @depends testAuth 64 | */ 65 | public function testGetProductBySellerCode() 66 | { 67 | $products = self::$gateway->getProductList(); 68 | $sellerCode = $products[0]->productSellerCode; 69 | $product = self::$gateway->getProductBySellerCode($sellerCode); 70 | $this->assertEquals(($sellerCode == $product->productSellerCode),true); 71 | } 72 | 73 | /** 74 | * 75 | */ 76 | public function testGetCities() 77 | { 78 | $cities = self::$gateway->getCities(); 79 | $this->assertEquals((isset($cities->result->status)),false); 80 | $this->assertEquals((count($cities) > 0),true); 81 | } 82 | 83 | /** 84 | * @depends testAuth 85 | */ 86 | public function testSaveProduct() 87 | { 88 | $product = [ 89 | 'productSellerCode' => 'exp-111', 90 | 'title' => 'Test Product', 91 | 'subtitle' => 'Web service test ', 92 | 'description' => 'test product detail', 93 | 'attributes' => 94 | [ 95 | 'attribute' => Array() 96 | ], 97 | 'category' => 98 | [ 99 | 'id' => 1000038 100 | ], 101 | 'price' => 0.99, 102 | 'currencyType' => 'TL', 103 | 'images' => 104 | [ 105 | 'image' => 106 | [ 107 | ] 108 | ], 109 | 'saleStartDate' => '', 110 | 'saleEndDate' => '', 111 | 'productionDate' => '', 112 | 'expirationDate' => '', 113 | 'productCondition' => '1', 114 | 'preparingDay' => '3', 115 | 'discount' => 10, 116 | 'shipmentTemplate' => 'Kapıda Ödeme', 117 | 'stockItems' => 118 | [ 119 | 'stockItem' => 120 | [ 121 | ] 122 | ] 123 | ]; 124 | 125 | $result = self::$gateway->saveProduct($product); 126 | 127 | $this->assertEquals($result->result->status,'success'); 128 | } 129 | } -------------------------------------------------------------------------------- /src/Client/Gateway.php: -------------------------------------------------------------------------------- 1 | setParam('soap_options',$soap_options); 15 | parent::setClient($soapClient); 16 | } 17 | 18 | /** 19 | * @param array $secrets 20 | */ 21 | public function auth($secrets = []) 22 | { 23 | $this->client->setParam('auth',['appKey' => $secrets['appKey'],'appSecret' => $secrets['appSecret']]); 24 | } 25 | 26 | /** 27 | * @return mixed 28 | */ 29 | public function getTopLevelCategories() 30 | { 31 | $response = $this->client->makeRequest('https://api.n11.com/ws/CategoryService.wsdl','getTopLevelCategories'); 32 | return isset($response->categoryList->category) ? $response->categoryList->category : $response; 33 | } 34 | 35 | /** 36 | * @param $category_id 37 | * @return mixed 38 | */ 39 | public function getSubCategories($category_id) 40 | { 41 | $response = $this->client->makeRequest('https://api.n11.com/ws/CategoryService.wsdl','getTopLevelCategories',['category_id' => $category_id]); 42 | return isset($response->categoryList->category) ? $response->categoryList->category : $response; 43 | } 44 | 45 | /** 46 | * @param int $limit 47 | * @param int $page 48 | * @return mixed 49 | */ 50 | public function getProductList($limit = 20,$page = 0) 51 | { 52 | $response = $this->client->makeRequest('https://api.n11.com/ws/ProductService.wsdl','getProductList',['pagingData' => ['pageSize' => $limit,'currentPage' => $page]]); 53 | return isset($response->products->product) ? $response->products->product : $response; 54 | } 55 | 56 | /** 57 | * @param $sellerCode 58 | * @return mixed 59 | */ 60 | public function getProductBySellerCode($sellerCode) 61 | { 62 | $response = $this->client->makeRequest('https://api.n11.com/ws/ProductService.wsdl','getProductBySellerCode',['sellerCode' => $sellerCode]); 63 | return isset($response->product) ? $response->product : $response; 64 | } 65 | 66 | /** 67 | * @param array $product 68 | * @return mixed 69 | */ 70 | public function saveProduct($product = []) 71 | { 72 | $response = $this->client->makeRequest('https://api.n11.com/ws/ProductService.wsdl','saveProduct',['product' => $product]); 73 | return $response; 74 | } 75 | 76 | /** 77 | * @param $sellerCode 78 | * @return mixed 79 | */ 80 | public function deleteProductBySellerCode($sellerCode) 81 | { 82 | $response = $this->client->makeRequest('https://api.n11.com/ws/ProductService.wsdl','deleteProductBySellerCode',['productSellerCode' => $sellerCode]); 83 | return $response; 84 | } 85 | 86 | /** 87 | * @param array $searchData 88 | * @return mixed 89 | */ 90 | public function getOrderList($searchData = []) 91 | { 92 | $response = $this->client->makeRequest('https://api.n11.com/ws/OrderService.wsdl','orderList',['searchData' => $searchData]); 93 | return $response; 94 | } 95 | 96 | /** 97 | * @param $sellerCode 98 | * @param $price 99 | * @param string $currencyType 100 | * @return mixed 101 | */ 102 | public function updateProductPriceBySellerCode($sellerCode,$price,$currencyType = "") 103 | { 104 | $response = $this->client->makeRequest('https://api.n11.com/ws/ProductService.wsdl','UpdateProductPriceBySellerCode',['productSellerCode' => $sellerCode,'price' => $price,'currencyType' => $currencyType]); 105 | return isset($response->products->product) ? $response->product : $response; 106 | } 107 | 108 | /** 109 | * @param $sellerCode 110 | * @return mixed 111 | */ 112 | public function getProductStockBySellerCode($sellerCode) 113 | { 114 | $response = $this->client->makeRequest('https://api.n11.com/ws/ProductStockService.wsdl','UpdateProductPriceBySellerCode',['productSellerCode' => $sellerCode]); 115 | return isset($response->products->product) ? $response->product : $response; 116 | } 117 | 118 | /** 119 | * @param $sellerCode 120 | * @param $quantity 121 | * @return mixed 122 | */ 123 | public function updateStockByStockSellerCodeRequest($sellerCode,$quantity) 124 | { 125 | $response = $this->client->makeRequest('https://api.n11.com/ws/ProductStockService.wsdl','UpdateProductPriceBySellerCode',['productSellerCode' => $sellerCode,'quantity' => $quantity]); 126 | return $response; 127 | } 128 | 129 | /** 130 | * @return mixed 131 | */ 132 | public function getCities() { 133 | $response = $this->client->makeRequest('https://api.n11.com/ws/CityService.wsdl','getCities'); 134 | return isset($response->cities->city) ? $response->cities->city : $response; 135 | } 136 | 137 | } --------------------------------------------------------------------------------