Skip to content

Commit

Permalink
Merge pull request #7 from teknomavi/analysis-lKgwd9
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
GoktugOzturk authored Jul 2, 2020
2 parents 2f5e39e + b6cfaa9 commit 4f47fc1
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 127 deletions.
4 changes: 3 additions & 1 deletion src/Company/Yurtici/Helper/ShipmentInfo.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Teknomavi\Kargo\Company\Yurtici\Helper;

use Teknomavi\Kargo\Model\Package;
Expand Down Expand Up @@ -32,8 +31,10 @@ public static function generatePackage(ShipmentInfo $sI): Package
$package->setConsigneeMobilPhone($sI->consigneeMobilPhone);
$package->setConsigneeEmail($sI->consigneeEmail);
$package->setNumberOfPackages($sI->noOfPackages);

return $package;
}

public static function generateFromPackage(Package $p): ShipmentInfo
{
$sI = new ShipmentInfo();
Expand All @@ -46,6 +47,7 @@ public static function generateFromPackage(Package $p): ShipmentInfo
$sI->consigneeMobilPhone = $p->getConsigneeMobilPhone();
$sI->consigneeEmail = $p->getConsigneeEmail();
$sI->noOfPackages = $p->getNumberOfPackages();

return $sI;
}
}
121 changes: 61 additions & 60 deletions src/Company/Yurtici/Helper/YKSoapClient.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
<?php

namespace Teknomavi\Kargo\Company\Yurtici\Helper;

class YKSoapClient
{

private $username = "";
private $password = "";
private static $language = "TR";
private $username = '';
private $password = '';
private static $language = 'TR';

public function __construct($options)
{
$this->username = $options["username"];
$this->password = $options["password"];
$this->username = $options['username'];
$this->password = $options['password'];
}

/**
* @param string $params
*
* Gönderici Ödemeli, Normal Gönderi
* @param string $params
*
* Gönderici Ödemeli, Normal Gönderi
*/
public function createShipment(
$cargoKey,
Expand All @@ -27,64 +26,66 @@ public function createShipment(
$cityName,
$townName,
$receiverPhone1,
$receiverPhone2 = "",
$receiverPhone3 = "",
$emailAddress = "",
$taxOfficeId = "",
$taxNumber = "",
$taxOfficeName = "", // Daha sonra kargo sayisi ile de ilgilenilebilir
$receiverPhone2 = '',
$receiverPhone3 = '',
$emailAddress = '',
$taxOfficeId = '',
$taxNumber = '',
$taxOfficeName = '', // Daha sonra kargo sayisi ile de ilgilenilebilir
$cargoCount = 1
) {
$credentials = array("wsUserName" => $this->username, "wsPassword" => $this->password, "userLanguage" => self::$language);
$params = array(
"cargoKey" => $cargoKey,
"invoiceKey" => $invoiceKey,
"receiverCustName" => $receiverCustName,
"receiverAddress" => $receiverAddress,
"cityName" => $cityName,
"townName" => $townName,
"receiverPhone1" => $receiverPhone1,
"receiverPhone2" => $receiverPhone2,
"receiverPhone3" => $receiverPhone3,
"emailAddress" => $emailAddress,
"taxOfficeId" => $taxOfficeId,
"taxNumber" => $taxNumber,
"taxOfficeName" => $taxOfficeName,
'cargoCount' => $cargoCount,
'waybillNo' => "",
'specialField1' => "",
'specialField2' => "",
'specialField3' => "",
'ttInvoiceAmount' => "",
'ttDocumentId' => '',
'ttCollectionType' => "",
'ttDocumentSaveType' => "",
'dcSelectedCredit' => "",
'dcCreditRule' => '',
'description' => "",
'orgGeoCode' => "",
'privilegeOrder' => "",
'custProdId' => "",
'orgReceiverCustId' => "",
);
$body = array("ShippingOrderVO" => $params);
$credentials = ['wsUserName' => $this->username, 'wsPassword' => $this->password, 'userLanguage' => self::$language];
$params = [
'cargoKey' => $cargoKey,
'invoiceKey' => $invoiceKey,
'receiverCustName' => $receiverCustName,
'receiverAddress' => $receiverAddress,
'cityName' => $cityName,
'townName' => $townName,
'receiverPhone1' => $receiverPhone1,
'receiverPhone2' => $receiverPhone2,
'receiverPhone3' => $receiverPhone3,
'emailAddress' => $emailAddress,
'taxOfficeId' => $taxOfficeId,
'taxNumber' => $taxNumber,
'taxOfficeName' => $taxOfficeName,
'cargoCount' => $cargoCount,
'waybillNo' => '',
'specialField1' => '',
'specialField2' => '',
'specialField3' => '',
'ttInvoiceAmount' => '',
'ttDocumentId' => '',
'ttCollectionType' => '',
'ttDocumentSaveType' => '',
'dcSelectedCredit' => '',
'dcCreditRule' => '',
'description' => '',
'orgGeoCode' => '',
'privilegeOrder' => '',
'custProdId' => '',
'orgReceiverCustId' => '',
];
$body = ['ShippingOrderVO' => $params];
$data = array_merge($credentials, $body);
$_sclient = new \SoapClient("http://webservices.yurticikargo.com:8080/KOPSWebServices/ShippingOrderDispatcherServices?wsdl");
$_sclient = new \SoapClient('http://webservices.yurticikargo.com:8080/KOPSWebServices/ShippingOrderDispatcherServices?wsdl');

return $_sclient->createShipment($data);
}

public function queryShipment($cargoKey)
{
$params = array(
"wsUserName" => $this->username,
"wsPassword" => $this->password,
"wsLanguage" => self::$language,
"keys" => $cargoKey,
"keyType" => 0, // Fatura/Irsaliye anahtari ile de gonderilebilir fakat referans numarasi baz alindi
"addHistoricalData" => false,
"onlyTracking" => false
);
$_sclient = new \SoapClient("http://webservices.yurticikargo.com:8080/KOPSWebServices/ShippingOrderDispatcherServices?wsdl");
$params = [
'wsUserName' => $this->username,
'wsPassword' => $this->password,
'wsLanguage' => self::$language,
'keys' => $cargoKey,
'keyType' => 0, // Fatura/Irsaliye anahtari ile de gonderilebilir fakat referans numarasi baz alindi
'addHistoricalData' => false,
'onlyTracking' => false,
];
$_sclient = new \SoapClient('http://webservices.yurticikargo.com:8080/KOPSWebServices/ShippingOrderDispatcherServices?wsdl');

return $_sclient->queryShipment($params);
}
}
74 changes: 39 additions & 35 deletions src/Company/Yurtici/Service.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
<?php

namespace Teknomavi\Kargo\Company\Yurtici;


use Teknomavi\Kargo\Company\Yurtici\Helper\YKSoapClient;
use Teknomavi\Kargo\Company\ServiceAbstract;
use Teknomavi\Kargo\Company\ServiceInterface;
use Teknomavi\Kargo\Company\Yurtici\Helper\ShipmentInfo;
use Teknomavi\Kargo\Company\Yurtici\Helper\YKSoapClient;
use Teknomavi\Kargo\Exception\InvalidParameterValue;
use Teknomavi\Kargo\Response\CreateShipment;
use Teknomavi\Kargo\Model\Package;
use Teknomavi\Kargo\Response\CreateShipment;
use Teknomavi\Kargo\Response\PackageInfo;
use Teknomavi\Kargo\Response\ShipmentStatus;

/**
* Class Service
* @package Teknomavi\Kargo\Company\Yurtici
* Class Service.
*/
class Service extends ServiceAbstract implements ServiceInterface
{
private $YKClient;
protected $statusMapping = [
"0" => ShipmentStatus::STATUS_NOT_PROCESSED,
"1" => ShipmentStatus::STATUS_ON_DISTRIBUTION,
"2" => ShipmentStatus::STATUS_PACKAGE_SCANNED,
"3" => ShipmentStatus::STATUS_EXCEPTION,
"4" => ShipmentStatus::STATUS_RETURN_BACK,
"5" => ShipmentStatus::STATUS_DELIVERED,
'0' => ShipmentStatus::STATUS_NOT_PROCESSED,
'1' => ShipmentStatus::STATUS_ON_DISTRIBUTION,
'2' => ShipmentStatus::STATUS_PACKAGE_SCANNED,
'3' => ShipmentStatus::STATUS_EXCEPTION,
'4' => ShipmentStatus::STATUS_RETURN_BACK,
'5' => ShipmentStatus::STATUS_DELIVERED,
];

function __construct($options)
public function __construct($options)
{
$this->YKClient = new YKSoapClient($options);
}

public function sendPackages()
{
$responses = array();
$responses = [];
foreach ($this->packages as $package) {
$package = ShipmentInfo::generatePackage($package);
$res = $this->YKClient->createShipment(
Expand All @@ -47,30 +44,30 @@ public function sendPackages()
$package->getConsigneeCity(),
$package->getConsigneeTown(),
$package->getConsigneeMobilPhone(),
"",
"",
'',
'',
$package->getConsigneeEmail(),
"",
"",
"",
'',
'',
'',
$package->getNumberOfPackages()
);
$response = new CreateShipment();
if ($res->ShippingOrderResultVO->outFlag == 0) {
$response = $response->setSuccess(true);
$response->setReferenceNumber($res->ShippingOrderResultVO->shippingOrderDetailVO->cargoKey);
} else if (property_exists($res->ShippingOrderResultVO, 'errCode')) {
} elseif (property_exists($res->ShippingOrderResultVO, 'errCode')) {
$response->setErrorCode($res->ShippingOrderResultVO->errCode);
$response->setErrorDescription($res->ShippingOrderResultVO->outResult);
$response->setSuccess(false);
} else {

$response = $response->setSuccess(false);
$response = $response->setErrorDescription($res->ShippingOrderResultVO->shippingOrderDetailVO->errMessage);
$response = $response->setErrorCode($res->ShippingOrderResultVO->shippingOrderDetailVO->errCode);
}
$responses[$package->getReferenceNo()] = $response;
}

return $responses;
}

Expand Down Expand Up @@ -103,7 +100,7 @@ public function getPackageInfoByReferenceNumber(string $referenceNumber): Packag
// price
$price = $res->ShippingDeliveryVO->shippingDeliveryDetailVO->shippingDeliveryItemDetailVO->totalPrice;
$packageInfo->setShipmentCost($price);
$packageInfo->setShipmentCostCurrency("TRY");
$packageInfo->setShipmentCostCurrency('TRY');
}
// total Cargo
if (property_exists($res->ShippingDeliveryVO->shippingDeliveryDetailVO->shippingDeliveryItemDetailVO, 'totalCargo')) {
Expand All @@ -115,13 +112,15 @@ public function getPackageInfoByReferenceNumber(string $referenceNumber): Packag
if (property_exists($res->ShippingDeliveryVO->shippingDeliveryDetailVO->shippingDeliveryItemDetailVO, 'cargoType')) {
$cargoType = $res->ShippingDeliveryVO->shippingDeliveryDetailVO->shippingDeliveryItemDetailVO->cargoType;
$packageInfo->setPackageType(PackageInfo::PACKAGE_TYPE_ENVELOPE);
if ($cargoType != 0)
if ($cargoType != 0) {
$packageInfo->setPackageType(PackageInfo::PACKAGE_TYPE_BOX);
}
}
$this->addTrackingNumber($res, $packageInfo);

return $packageInfo;
}

/**
* @param string $referenceNumber
*
Expand All @@ -142,6 +141,7 @@ public function getShipmentStatusByReferenceNumber(string $referenceNumber): Shi
$opMsg = $res->ShippingDeliveryVO->shippingDeliveryDetailVO->operationMessage;
$shipmentStatus->setStatusDetails($opMsg);
$shipmentStatus->setOriginalStatus($opCode);

try {
$shipmentStatus->setStatusCode($this->mapStatus($opCode));
} catch (InvalidParameterValue $a) {
Expand All @@ -156,7 +156,7 @@ public function getShipmentStatusByReferenceNumber(string $referenceNumber): Shi
if (property_exists($res->ShippingDeliveryVO->shippingDeliveryDetailVO->shippingDeliveryItemDetailVO, 'documentDate')) {
$date = $res->ShippingDeliveryVO->shippingDeliveryDetailVO->shippingDeliveryItemDetailVO->documentDate;
$time = $res->ShippingDeliveryVO->shippingDeliveryDetailVO->shippingDeliveryItemDetailVO->documentTime;
$shipmentStatus->setUpdateTime(\DateTime::createFromFormat("YmdGis", $date . $time, new \DateTimeZone('Asia/Istanbul')));
$shipmentStatus->setUpdateTime(\DateTime::createFromFormat('YmdGis', $date . $time, new \DateTimeZone('Asia/Istanbul')));
}
$this->addTrackingNumber($res, $shipmentStatus);

Expand All @@ -170,44 +170,48 @@ public function getShipmentStatusByReferenceNumber(string $referenceNumber): Shi
*/
public function getShipmentStatusByReferenceNumberList(array $list): array
{
$shipmentStatusList = array();
$shipmentStatusList = [];
foreach ($list as $value) {
$shipmentStatus = $this->getShipmentStatusByReferenceNumber($value);
$shipmentStatusList[] = $shipmentStatus;
}

return $shipmentStatusList;
}


/**
* Takes the soap client response and processes it until TrackingNumber fullfilment
* for both ShipmentStatis and PackageInfo types
*
* @param object $res takes the soap client response as $res
* for both ShipmentStatis and PackageInfo types.
*
* @param object $res takes the soap client response as $res
* @param ShipmentStatus,PackageInfo $package it takes ShipmentStatus
* or PackageInfo as parameter
* @return array
* the first index is the processed item
* the second index is a flag for package to be processed more
* or PackageInfo as parameter
*
* @return array
* the first index is the processed item
* the second index is a flag for package to be processed more
*/
private function isErrorMessage($res, $packageInfo)
{
if ($res->ShippingDeliveryVO->outResult != "Başarılı") {
if ($res->ShippingDeliveryVO->outResult != 'Başarılı') {
// error
$packageInfo->setErrorMessage($res->ShippingDeliveryVO->outResult);
$packageInfo->setErrorCode($res->ShippingDeliveryVO->errCode);

return true;
}
if (property_exists($res->ShippingDeliveryVO->shippingDeliveryDetailVO, 'errCode')) {
$packageInfo->setErrorCode($res->ShippingDeliveryVO->shippingDeliveryDetailVO->errCode);
$packageInfo->setErrorMessage($res->ShippingDeliveryVO->shippingDeliveryDetailVO->errMessage);

return true;
}
// Then the cargo is successfull
if ($res->ShippingDeliveryVO->shippingDeliveryDetailVO->operationCode == 0) {
// Kargo islem gormemis eklenecek veri de yok
return false;
}

return false;
}

Expand All @@ -218,7 +222,7 @@ private function addTrackingNumber($res, $item)
{
if (property_exists($res->ShippingDeliveryVO->shippingDeliveryDetailVO->shippingDeliveryItemDetailVO, 'trackingUrl')) {
$trackingUrl = $res->ShippingDeliveryVO->shippingDeliveryDetailVO->shippingDeliveryItemDetailVO->trackingUrl;
$no = explode("code=", $trackingUrl)[1];
$no = explode('code=', $trackingUrl)[1];
$item->setTrackingNumber($no);
}
}
Expand Down
Loading

0 comments on commit 4f47fc1

Please sign in to comment.