PHPackages                             mhunesi/yii2-ups - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. mhunesi/yii2-ups

ActiveYii2-extension[API Development](/categories/api)

mhunesi/yii2-ups
================

Yii2 UPS Integration

04PHP

Since Jan 31Pushed 4y ago1 watchersCompare

[ Source](https://github.com/mhunesi/yii2-ups)[ Packagist](https://packagist.org/packages/mhunesi/yii2-ups)[ RSS](/packages/mhunesi-yii2-ups/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Yii2 UPS Integration
====================

[](#yii2-ups-integration)

Ups Kargo şirketi ile kargo entegrasyonlarının gerçekleşmesi için gerekli imlementasyonun sağlanmasını amaçlanmıştır.

1 - Component Olarak eklenmesi
------------------------------

[](#1---component-olarak-eklenmesi)

```
'ups' => [
    'class' => 'mhunesi\ups\UPS',
    'customerNumber' => 'customerNumber',
    'username' => 'username',
    'password' => 'password',
    'isTestInstance' => true
]
```

2- Nesne üretimi
----------------

[](#2--nesne-üretimi)

```
 $ups = Yii::$app->ups;
```

Session ID alma işlemi
----------------------

[](#session-id-alma-işlemi)

tüm request'lerden önce bir sessionID alma request'i göndermek gerekir. bu sessionID sonraki request'lerde kullanılacaktır.

```
$sessionID = $ups->login();
```

2- Create Shipment işlemi
-------------------------

[](#2--create-shipment-işlemi)

```
/**
 * dimettion bilgisi yoksa bile en az 1 paket eklenmeli
 */
$packageCount = count($shipment->dimetions)==0? 1 : count($shipment->dimetions);
$serviceDesicion = UpsServiceLevel::Standard;
$packageType = UpsPackingType::NonDocument; //tahmin ederim ki nonDox tur ama teyid etmekte fayda var
$paymentType  = GoodsPaymentType::DDP; ///DDP olmadığı durumları konuşalım
/////paket boyutlarını tanımlayalım
$dimetions = [];
foreach ($shipment->dimetions as $key => $value)
{
    $upsDimetions[]=[
        "DescriptionOfGoods"=>$value->description,
        "Length"=>$value->length,
        "Height"=>$value->height,
        "Width"=>$value->width,
        "Weight"=>$value->weight,
    ];
}

$shipmentInfo = new ShipmentInfo
(
    [
    "ShipperAccountNumber"=>$this->component->customerNumber,
    "ShipperName"=> $shipment->sender->SenderName,
    "ShipperContactName"=> $shipment->sender->ContactName,
    "ShipperAddress"=> $shipment->sender->address->fullAdress,
    "ShipperCityCode"=> "34",
    "ShipperAreaCode"=> "5662",
    "ShipperPostalCode"=> $shipment->sender->address->zipcode,
    "ShipperPhoneNumber"=> $shipment->sender->phone,
    "ShipperEMail"=> $shipment->sender->email,
    "ShipperExpenseCode"=> "?",
    "ConsigneeAccountNumber"=> "",
    "ConsigneeName"=> $shipment->receiver->ReceiverName,
    "ConsigneeContactName"=> $shipment->receiver->ContactName,
    "ConsigneeAddress"=> $shipment->receiver->address->fullAdress,
    "ConsigneeCityCode"=> "01", ///bu kodlar UPS 'ten toplu olarak alınmalıdır.
    "ConsigneeAreaCode"=> "12", /// Bu kodlar UPS'ten toplu alarak alınmalıdır
    "ConsigneePostalCode"=>$shipment->receiver->address->zipcode,
    "ConsigneePhoneNumber"=> $shipment->receiver->phone,
    "ConsigneeEMail"=> $shipment->receiver->email,
    "ConsigneeExpenseCode"=> "",
    "ServiceLevel"=>$serviceDesicion, ///sevis pakedinin ne olacağını ifade eder önemli
    "PaymentType"=> $paymentType, 1-2-3 ne olabilir
    "PackageType"=> $packageType,
    "NumberOfPackages"=>$packageCount,
    "CustomerReference"=> $shipment->customerReference,
    "CustomerInvoiceNumber"=> $shipment->InvoiceNo,
    "DescriptionOfGoods"=> $shipment->productsDescription,
    "DeliveryNotificationEmail"=> $shipment->sender->email,
    "IdControlFlag"=>"0",
    "PhonePrealertFlag"=>"0",
    "SmsToShipper"=>"0",
    "SmsToConsignee"=>"0",
    "InsuranceValue"=>"0",
    "InsuranceValueCurrency"=>"",
    "ValueOfGoods"=>"0",
    "ValueOfGoodsCurrency"=>"",
    "ValueOfGoodsPaymentType"=>"",
    "DeliveryByTally"=>"0",
    "ThirdPartyAccountNumber"=>"",
    "ThirdPartyExpenseCode"=>"0",
    "PackageDimensions" => $dimetions,
    ]
);

$sessionID = $this->ups->login();
$shipmentRequest = new UpsShipmentModel();
$shipmentRequest->SessionID  = $sessionID;
$shipmentRequest->ShipmentInfo = $shipmentInfo;
$shipmentRequest->ReturnLabelLink =false;
$shipmentRequest->ReturnLabelImage= true;
$shipmentRequest->PaperSize="4X6";

$createShipmentResponse = $this->ups->createShipment($shipmentRequest);
if($createShipmentResponse->status)
{
    echo($createShipmentResponse->cargoTrackingNo);
    foreach ($createShipmentResponse->labelImage->string as $key => $value) {
        file_put_contents($createShipmentResponse->cargoTrackingNo.$key."_.png",$value);
    }
}else
{
    print_r($createShipmentResponse->errorMessage);
    $this->log($createShipmentResponse->requestAsXML,$result->responseAsXML);
}
```

3- Cancel işlemi
----------------

[](#3--cancel-işlemi)

```
$sessionID = $this->ups->login();
$customerRefferance="123459678";
$cargoTrackingNumber="1Z3X9A7768036475220";
$upsBaseModel = $this->ups->cancelShipment($sessionID,$customerRefferance,$cargoTrackingNumber);
if(!$upsBaseModel->status)
{
    print_r($upsBaseModel->errorMessage);
    $this->log($upsBaseModel->requestAsXML,$upsBaseModel->responseAsXML);
}
```

4- Tracking işlemi
------------------

[](#4--tracking-işlemi)

```
$cargo = Yii::$app->cargo;
$shipment = new ShipmentModel();
$shipment->cargoTrackingNumber="1ZA786886800730327";
$response = $cargo->tracking($shipment);
if(!$response->status)
{
    print_r($response->TrackingHistory);
    //$this->log($response->requestAsXML,$response->responseAsXML);
}
```

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity27

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15876915?v=4)[Mustafa Hayri ÜNEŞİ](/maintainers/mhunesi)[@mhunesi](https://github.com/mhunesi)

---

Top Contributors

[![mhunesi](https://avatars.githubusercontent.com/u/15876915?v=4)](https://github.com/mhunesi "mhunesi (3 commits)")

---

Tags

upsyii2yii2-extension

### Embed Badge

![Health badge](/badges/mhunesi-yii2-ups/health.svg)

```
[![Health](https://phpackages.com/badges/mhunesi-yii2-ups/health.svg)](https://phpackages.com/packages/mhunesi-yii2-ups)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35816.3M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24015.5M18](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172437.8k11](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93452.6k6](/packages/botman-driver-telegram)[pixelant/pxa-social-feed

Add Facebook, Instagram, and Twitter feeds to your site.

2349.3k](/packages/pixelant-pxa-social-feed)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
