-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ragod123/shipping-label
Shipping label
- Loading branch information
Showing
28 changed files
with
2,075 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
<?php | ||
|
||
use RahulGodiyal\PhpUpsApiWrapper\Entity\Address; | ||
use RahulGodiyal\PhpUpsApiWrapper\Entity\BillShipper; | ||
use RahulGodiyal\PhpUpsApiWrapper\Entity\Dimensions; | ||
use RahulGodiyal\PhpUpsApiWrapper\Entity\LabelImageFormat; | ||
use RahulGodiyal\PhpUpsApiWrapper\Entity\LabelSpecification; | ||
use RahulGodiyal\PhpUpsApiWrapper\Entity\LabelStockSize; | ||
use RahulGodiyal\PhpUpsApiWrapper\Entity\Package; | ||
use RahulGodiyal\PhpUpsApiWrapper\Entity\PackageWeight; | ||
use RahulGodiyal\PhpUpsApiWrapper\Entity\Packaging; | ||
use RahulGodiyal\PhpUpsApiWrapper\Entity\PaymentInformation; | ||
use RahulGodiyal\PhpUpsApiWrapper\Entity\Phone; | ||
use RahulGodiyal\PhpUpsApiWrapper\Entity\Request; | ||
use RahulGodiyal\PhpUpsApiWrapper\Entity\Service; | ||
use RahulGodiyal\PhpUpsApiWrapper\Entity\ShipFrom; | ||
use RahulGodiyal\PhpUpsApiWrapper\Entity\Shipment; | ||
use RahulGodiyal\PhpUpsApiWrapper\Entity\ShipmentCharge; | ||
use RahulGodiyal\PhpUpsApiWrapper\Entity\ShipmentRequest; | ||
use RahulGodiyal\PhpUpsApiWrapper\Entity\Shipper; | ||
use RahulGodiyal\PhpUpsApiWrapper\Entity\ShipTo; | ||
use RahulGodiyal\PhpUpsApiWrapper\Entity\UnitOfMeasurement; | ||
use RahulGodiyal\PhpUpsApiWrapper\Ship; | ||
|
||
require_once('./vendor/autoload.php'); | ||
|
||
$client_id = "************************"; // UPS Client ID | ||
$client_secret = "*****************************"; // UPS Client Secret | ||
|
||
/********* Shipper **********/ | ||
$address = new Address(); | ||
$address->setAddressLine1("address line 1"); | ||
$address->setAddressLine2(""); // optional | ||
$address->setCity("Timonium"); | ||
$address->setStateProvinceCode("MD"); | ||
$address->setPostalCode("21093"); | ||
$address->setCountryCode("US"); | ||
|
||
$phone = new Phone(); | ||
$phone->setNumber("1115554758"); | ||
$phone->setExtension(""); // optional | ||
|
||
$shipper = new Shipper(); | ||
$shipper->setName("Shipper Test"); | ||
$shipper->setAttentionName(""); // optional | ||
$shipper->setTaxIdentificationNumber(""); // optional | ||
$shipper->setPhone($phone); | ||
$shipper->setShippingNumber("123456"); | ||
$shipper->setFaxNumber(""); // optional | ||
$shipper->setAddress($address); | ||
/********* End Shipper **********/ | ||
|
||
/************ ShipTo **********/ | ||
$address = new Address(); | ||
$address->setAddressLine1("address line 1"); | ||
$address->setAddressLine2(""); // optional | ||
$address->setCity("Timonium"); | ||
$address->setStateProvinceCode("MD"); | ||
$address->setPostalCode("21093"); | ||
$address->setCountryCode("US"); | ||
|
||
$phone = new Phone(); | ||
$phone->setNumber("1115554758"); | ||
|
||
$shipTo = new ShipTo(); | ||
$shipTo->setName("Shipper Test"); | ||
$shipTo->setAttentionName(""); // optional | ||
$shipTo->setPhone($phone); | ||
$shipTo->setAddress($address); | ||
$shipTo->setResidential(""); // optional | ||
/************ End ShipTo **********/ | ||
|
||
/************ ShipFrom **********/ | ||
$address = new Address(); | ||
$address->setAddressLine1("address line 1"); | ||
$address->setAddressLine2(""); // optional | ||
$address->setCity("Timonium"); | ||
$address->setStateProvinceCode("MD"); | ||
$address->setPostalCode("21093"); | ||
$address->setCountryCode("US"); | ||
|
||
$phone = new Phone(); | ||
$phone->setNumber("1115554758"); | ||
|
||
$shipFrom = new ShipFrom(); | ||
$shipFrom->setName("Shipper Test"); | ||
$shipFrom->setAttentionName(""); // optional | ||
$shipFrom->setPhone($phone); | ||
$shipFrom->setFaxNumber(""); // optional | ||
$shipFrom->setAddress($address); | ||
/************ End ShipFrom **********/ | ||
|
||
/************ PaymentInformation **********/ | ||
$billShipper = new BillShipper(); | ||
$billShipper->setAccountNumber("123456"); | ||
|
||
$shipmentCharge = new ShipmentCharge(); | ||
$shipmentCharge->setBillShipper($billShipper); | ||
|
||
$paymentInformation = new PaymentInformation(); | ||
$paymentInformation->setShipmentCharge($shipmentCharge); | ||
/************ End PaymentInformation **********/ | ||
|
||
/************ Service **********/ | ||
$service = new Service(); | ||
$service->setCode(Service::GROUND); | ||
$service->setDescription("Ground"); // optional | ||
/************ End Service **********/ | ||
|
||
/************ Package **********/ | ||
$packaging = new Packaging(); | ||
$packaging->setCode(Packaging::CUSTOMER_SUPPLIED_PACKAGE); | ||
$packaging->setDescription("Ups Letter"); // optional | ||
|
||
$unitOfMeasurement = new UnitOfMeasurement(); | ||
$unitOfMeasurement->setCode(UnitOfMeasurement::INCHES); | ||
$unitOfMeasurement->setDescription("Inches"); // optional | ||
|
||
$dimensions = new Dimensions(); | ||
$dimensions->setUnitOfMeasurement($unitOfMeasurement); | ||
$dimensions->setLength("10"); | ||
$dimensions->setWidth("30"); | ||
$dimensions->setHeight("45"); | ||
|
||
$unitOfMeasurement = new UnitOfMeasurement(); | ||
$unitOfMeasurement->setCode(UnitOfMeasurement::POUNDS); | ||
$unitOfMeasurement->setDescription("POUNDS"); // optional | ||
|
||
$packageWeight = new PackageWeight(); | ||
$packageWeight->setUnitOfMeasurement($unitOfMeasurement); | ||
$packageWeight->setWeight("5"); | ||
|
||
$package = new Package(); | ||
$package->setDescription(""); // optional | ||
$package->setPackaging($packaging); | ||
$package->setDimensions($dimensions); | ||
$package->setPackageWeight($packageWeight); | ||
/************ End Package **********/ | ||
|
||
/************ Shipment **********/ | ||
$shipment = new Shipment(); | ||
$shipment->setDescription("Ship WS test"); | ||
$shipment->setShipper($shipper); | ||
$shipment->setShipTo($shipTo); | ||
$shipment->setShipFrom($shipFrom); | ||
$shipment->setPaymentInformation($paymentInformation); | ||
$shipment->setService($service); | ||
$shipment->setPackage($package); | ||
/************ End Shipment **********/ | ||
|
||
/************ Label Specification **********/ | ||
$labelImageFormat = new LabelImageFormat(); | ||
$labelImageFormat->setCode(LabelImageFormat::GIF); | ||
$labelImageFormat->setDescription("GIF"); // optional | ||
|
||
$labelStockSize = new LabelStockSize(); | ||
$labelStockSize->setHeight(LabelStockSize::H_8); | ||
$labelStockSize->setWidth(LabelStockSize::W_4); | ||
|
||
$labelSpecification = new LabelSpecification(); | ||
$labelSpecification->setLabelImageFormat($labelImageFormat); | ||
$labelSpecification->setLabelStockSize($labelStockSize); | ||
$labelSpecification->setHttpUserAgent("Mozilla/4.5"); // optional | ||
/************ End Label Specification **********/ | ||
|
||
/************ Shipment Request **********/ | ||
$shipmentRequest = new ShipmentRequest(); | ||
$shipmentRequest->setRequest(new Request); | ||
$shipmentRequest->setShipment($shipment); | ||
$shipmentRequest->setLabelSpecification($labelSpecification); | ||
/************ End Shipment Request **********/ | ||
|
||
/************ Create Ship **********/ | ||
$ship = new Ship(); | ||
$ship->setShipmentRequest($shipmentRequest); | ||
$ship->setOnlyLabel(true); // optional | ||
// $ship->setMode('PROD'); // Optional | only used for prod | ||
$shipRes = $ship->createShipment($client_id, $client_secret); | ||
/************ End Create Ship **********/ | ||
|
||
echo '<pre>'; print_r($shipRes); echo '</pre>'; | ||
?> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Shipping Label</title> | ||
</head> | ||
<body> | ||
<img src="data:image/png;base64,<?= $shipRes['data']->GraphicImage ?>" alt="Shipping Label"> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.