<?php

require_once 'credentials.php';
require_once 'bootstrap.php';
use FedEx\ShipService, FedEx\ShipService\ComplexType, FedEx\ShipService\SimpleType;
$userCredential = new ComplexType\WebAuthenticationCredential();
$userCredential->setKey(FEDEX_KEY)->setPassword(FEDEX_PASSWORD);
$webAuthenticationDetail = new ComplexType\WebAuthenticationDetail();
$webAuthenticationDetail->setUserCredential($userCredential);
$clientDetail = new ComplexType\ClientDetail();
$clientDetail->setAccountNumber(FEDEX_ACCOUNT_NUMBER)->setMeterNumber(FEDEX_METER_NUMBER);
$version = new ComplexType\VersionId();
$version->setServiceId('ship')->setMajor(12)->setIntermediate(1)->setMinor(0);
$trackingId = new ComplexType\TrackingId();
$trackingId->setTrackingNumber('12345')->setTrackingIdType(SimpleType\TrackingIdType::_FEDEX);
$deleteShipmentRequest = new ComplexType\DeleteShipmentRequest();
$deleteShipmentRequest->setWebAuthenticationDetail($webAuthenticationDetail);
$deleteShipmentRequest->setClientDetail($clientDetail);
$deleteShipmentRequest->setVersion($version);
$deleteShipmentRequest->setTrackingId($trackingId);
$deleteShipmentRequest->setDeletionControl(SimpleType\DeletionControlType::_DELETE_ALL_PACKAGES);
$validateShipmentRequest = new ShipService\Request();
$validateShipmentRequest->getSoapClient()->__setLocation('https://ws.fedex.com:443/web-services/ship');
$response = $validateShipmentRequest->getDeleteShipmentReply($deleteShipmentRequest);
var_dump($response);
$shipperContact = new ComplexType\Contact();
$shipperContact->setCompanyName('Company Name')->setEMailAddress('*****@*****.**')->setPersonName('Person Name')->setPhoneNumber('123-123-1234');
$shipper = new ComplexType\Party();
$shipper->setAccountNumber(FEDEX_ACCOUNT_NUMBER)->setAddress($shipperAddress)->setContact($shipperContact);
$recipientAddress = new ComplexType\Address();
$recipientAddress->setStreetLines(array('54312 1st Ave'))->setCity('Anytown')->setStateOrProvinceCode('NY')->setPostalCode('12345')->setCountryCode('US');
$recipientContact = new ComplexType\Contact();
$recipientContact->setPersonName('Contact Name');
$recipient = new ComplexType\Party();
$recipient->setAddress($recipientAddress)->setContact($recipientContact);
$labelSpecification = new ComplexType\LabelSpecification();
$labelSpecification->setLabelStockType(new SimpleType\LabelStockType(SimpleType\LabelStockType::_PAPER_7X4point75))->setImageType(new SimpleType\ShippingDocumentImageType(SimpleType\ShippingDocumentImageType::_PDF))->setLabelFormatType(new SimpleType\LabelFormatType(SimpleType\LabelFormatType::_COMMON2D));
$requestedShipment = new ComplexType\RequestedShipment();
$requestedShipment->setShipTimestamp(date('c'));
$requestedShipment->setDropoffType(new SimpleType\DropoffType(SimpleType\DropoffType::_REGULAR_PICKUP));
$requestedShipment->setServiceType(new SimpleType\ServiceType(SimpleType\ServiceType::_FEDEX_GROUND));
$requestedShipment->setPackagingType(new SimpleType\PackagingType(SimpleType\PackagingType::_YOUR_PACKAGING));
$requestedShipment->setShipper($shipper);
$requestedShipment->setRecipient($recipient);
$requestedShipment->setLabelSpecification($labelSpecification);
$requestedShipment->setRateRequestTypes(array(new SimpleType\RateRequestType(SimpleType\RateRequestType::_ACCOUNT)));
$requestedShipment->setPackageCount(1);
$createPendingShipmentRequest = new ComplexType\CreatePendingShipmentRequest();
$createPendingShipmentRequest->setWebAuthenticationDetail($webAuthenticationDetail);
$createPendingShipmentRequest->setClientDetail($clientDetail);
$createPendingShipmentRequest->setVersion($version);
$createPendingShipmentRequest->setRequestedShipment($requestedShipment);
$shipService = new ShipService\Request();
$shipService->getSoapClient()->__setLocation('https://ws.fedex.com:443/web-services/ship');
$result = $shipService->getCreatePendingShipmentReply($createPendingShipmentRequest);
var_dump($result);