Skip to content

Commit

Permalink
Resolves #1
Browse files Browse the repository at this point in the history
- Kolay tanımlama için constructor eklendi
- Default status tanımlaması yapıldı
  • Loading branch information
smberg committed Jan 29, 2023
1 parent 67bbaeb commit a9b4cee
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 35 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Yurtiçi Kargo PHP

Yurtiçi Kargo php api entegrasyonu

# Installation
Expand Down Expand Up @@ -31,8 +32,8 @@ require_once('/path/to/yurtici-kargo-php/YurticiKargoBootstrap.php');
<?php
require_once "../vendor/autoload.php";

$request = new YurticiKargo\Request();
$request->setUser("YKTEST", "YK")->init("test");
$request = new YurticiKargo\Request("test");
$request->setUser("YKTEST", "YK");

$shipmentDetails = array(
"receiverCustName" => "Berkay Gümüştekin",
Expand Down Expand Up @@ -66,4 +67,4 @@ $queryShipment = $request->queryShipment("SBG5448C616D8");
echo '<pre>';
print_r($queryShipment->getResultData());
echo '</pre>';
```
```
16 changes: 10 additions & 6 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php
require_once "../vendor/autoload.php";

$request = new YurticiKargo\Request();
$request->setUser("YKTEST", "YK")->init("test");
$request = new YurticiKargo\Request("test");
$request->setUser("YKTEST", "YK");

$shipmentDetails = array(
"receiverCustName" => "Berkay Gümüştekin",
Expand All @@ -47,13 +49,15 @@ echo '<pre>';
print_r($createShipment);
echo '</pre>';
```

## Cancel a shipment request

```php
<?php
require_once "../vendor/autoload.php";

$request = new YurticiKargo\Request();
$request->setUser("YKTEST", "YK")->init("test");
$request = new YurticiKargo\Request("test");
$request->setUser("YKTEST", "YK");

$cancelShipment = $request->cancelShipment("CARGO_KEY");

Expand All @@ -68,8 +72,8 @@ echo '</pre>';
<?php
require_once "../vendor/autoload.php";

$request = new YurticiKargo\Request();
$request->setUser("YKTEST", "YK")->init("test");
$request = new YurticiKargo\Request("test");
$request->setUser("YKTEST", "YK");


$queryShipment = $request->queryShipment("SBG5448C616D8");
Expand Down
10 changes: 5 additions & 5 deletions samples/CreateShipment.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
require_once "../vendor/autoload.php";

$request = new YurticiKargo\Request();
$request->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);
Expand All @@ -18,4 +18,4 @@

echo '<pre>';
print_r($createShipment);
echo '</pre>';
echo '</pre>';
6 changes: 3 additions & 3 deletions samples/QueryShipment.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
require_once "../vendor/autoload.php";

$request = new YurticiKargo\Request();
$request->setUser("YKTEST", "YK")->init("test");
$request = new YurticiKargo\Request("test");
$request->setUser("YKTEST", "YK");


$queryShipment = $request->queryShipment("SBG5448C616D8");

echo '<pre>';
print_r($queryShipment->getResultData());
echo '</pre>';
echo '</pre>';
50 changes: 32 additions & 18 deletions src/YurticiKargo/Request.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
<?php

namespace YurticiKargo;

use \SoapClient;

class Request
class Request
{
private $userName = '';
private $password = '';
private $apiURL = null;
private $soapClient = null;


/**
* __construct
* @param string $status test || prod
*/
public function __construct($status = 'prod')
{
$this->init($status);
}

/**
* setUser
*
Expand All @@ -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
*
Expand All @@ -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
*
Expand Down Expand Up @@ -86,7 +100,7 @@ public function createShipment($shipmentDetails)

return $result;
}

/**
* Kargo durumu sorgulama
*
Expand All @@ -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 {
Expand All @@ -119,7 +133,7 @@ public function queryShipment($cargoInfo, $historical = true)
$queryShipment = new QueryShipment($result);
return $queryShipment;
}

/**
* Kargo anahtarı ile işlemi iptal et
*
Expand All @@ -139,7 +153,7 @@ public function cancelShipment($cargoKey)

return $result;
}

/**
* Benzersiz anahtar üret
*
Expand All @@ -151,4 +165,4 @@ public static function generateKey($characterCount = 17)
$limit = (int) $characterCount;
return strtoupper(substr(md5(microtime()), 0, $limit));
}
}
}

0 comments on commit a9b4cee

Please sign in to comment.