diff --git a/README.md b/README.md index babb58b..65ccb61 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Yurtiçi Kargo PHP + Yurtiçi Kargo php api entegrasyonu # Installation @@ -31,8 +32,8 @@ require_once('/path/to/yurtici-kargo-php/YurticiKargoBootstrap.php'); setUser("YKTEST", "YK")->init("test"); +$request = new YurticiKargo\Request("test"); +$request->setUser("YKTEST", "YK"); $shipmentDetails = array( "receiverCustName" => "Berkay Gümüştekin", @@ -66,4 +67,4 @@ $queryShipment = $request->queryShipment("SBG5448C616D8"); echo '
'; print_r($queryShipment->getResultData()); echo ''; -``` \ No newline at end of file +``` diff --git a/docs/index.md b/docs/index.md index 9cdbd2e..52b7033 100644 --- a/docs/index.md +++ b/docs/index.md @@ -21,15 +21,17 @@ If you do not wish to use Composer, you can download the [latest release](https: ```php require_once('/path/to/yurtici-kargo-php/YurticiKargoBootstrap.php'); ``` + # Examples + ## Create a shipment request ```php setUser("YKTEST", "YK")->init("test"); +$request = new YurticiKargo\Request("test"); +$request->setUser("YKTEST", "YK"); $shipmentDetails = array( "receiverCustName" => "Berkay Gümüştekin", @@ -47,13 +49,15 @@ echo '
'; print_r($createShipment); echo ''; ``` + ## Cancel a shipment request + ```php setUser("YKTEST", "YK")->init("test"); +$request = new YurticiKargo\Request("test"); +$request->setUser("YKTEST", "YK"); $cancelShipment = $request->cancelShipment("CARGO_KEY"); @@ -68,8 +72,8 @@ echo ''; setUser("YKTEST", "YK")->init("test"); +$request = new YurticiKargo\Request("test"); +$request->setUser("YKTEST", "YK"); $queryShipment = $request->queryShipment("SBG5448C616D8"); diff --git a/samples/CreateShipment.php b/samples/CreateShipment.php index 2af8032..22af607 100644 --- a/samples/CreateShipment.php +++ b/samples/CreateShipment.php @@ -1,15 +1,15 @@ setUser("YKTEST", "YK")->init("test"); +$request = new YurticiKargo\Request("test"); +$request->setUser("YKTEST", "YK"); $shipmentDetails = array( "receiverCustName" => "Berkay Gümüştekin", "receiverAddress" => "Test Mah. Deneme Sk. No:3", "receiverPhone1" => "05555555555", - "invoiceKey" => "SBG".YurticiKargo\Request::generateKey(17), - "cargoKey" => "SBG".YurticiKargo\Request::generateKey(10) + "invoiceKey" => "SBG" . YurticiKargo\Request::generateKey(17), + "cargoKey" => "SBG" . YurticiKargo\Request::generateKey(10) ); $shipment = new YurticiKargo\Shipment(); $shipment->setShipmentDetails($shipmentDetails); @@ -18,4 +18,4 @@ echo '
'; print_r($createShipment); -echo ''; \ No newline at end of file +echo ''; diff --git a/samples/QueryShipment.php b/samples/QueryShipment.php index 484265e..be78830 100644 --- a/samples/QueryShipment.php +++ b/samples/QueryShipment.php @@ -1,12 +1,12 @@ setUser("YKTEST", "YK")->init("test"); +$request = new YurticiKargo\Request("test"); +$request->setUser("YKTEST", "YK"); $queryShipment = $request->queryShipment("SBG5448C616D8"); echo '
'; print_r($queryShipment->getResultData()); -echo ''; \ No newline at end of file +echo ''; diff --git a/src/YurticiKargo/Request.php b/src/YurticiKargo/Request.php index 40e1886..6d91422 100644 --- a/src/YurticiKargo/Request.php +++ b/src/YurticiKargo/Request.php @@ -1,14 +1,25 @@ init($status); + } + /** * setUser * @@ -18,13 +29,13 @@ class Request * @param string $pass * @return Request */ - public function setUser($username,$pass) + public function setUser($username, $pass) { - $this->userName = $username; - $this->password = $pass; - return $this; + $this->userName = $username; + $this->password = $pass; + return $this; } - + /** * setApiURL * @@ -38,26 +49,29 @@ public function setApiURL($url) $this->apiURL = $url; return $this; } - + /** * init * * @param string $status test || prod * @return Request */ - public function init($status) + public function init($status = 'prod') { - if($status == 'test') { + if ($status == 'test') { $this->setApiURL("http://testwebservices.yurticikargo.com:9090/KOPSWebServices/ShippingOrderDispatcherServices?wsdl"); - $this->setUser("YKTEST","YK"); + + if ($this->userName == '' || $this->password == '') { + $this->setUser("YKTEST", "YK"); + } } else { $this->setApiURL("http://webservices.yurticikargo.com:8080/KOPSWebServices/ShippingOrderDispatcherServices?wsdl"); } - + $this->soapClient = new SoapClient($this->apiURL, array("trace" => 1, "exception" => 0)); return $this; } - + /** * Kargo oluşturma * @@ -86,7 +100,7 @@ public function createShipment($shipmentDetails) return $result; } - + /** * Kargo durumu sorgulama * @@ -107,7 +121,7 @@ public function queryShipment($cargoInfo, $historical = true) "onlyTracking" => "", ); $finalValues = array(); - if($type == "string") { + if ($type == "string") { $finalValues = $defaults; $finalValues["keys"] = $cargoInfo; } else { @@ -119,7 +133,7 @@ public function queryShipment($cargoInfo, $historical = true) $queryShipment = new QueryShipment($result); return $queryShipment; } - + /** * Kargo anahtarı ile işlemi iptal et * @@ -139,7 +153,7 @@ public function cancelShipment($cargoKey) return $result; } - + /** * Benzersiz anahtar üret * @@ -151,4 +165,4 @@ public static function generateKey($characterCount = 17) $limit = (int) $characterCount; return strtoupper(substr(md5(microtime()), 0, $limit)); } -} \ No newline at end of file +}