/**
  * @param NonContractShipmentType $NcShipment
  * @return bool|MessagesType|NonContractShipmentInfoType
  */
 public function createNcShipment(NonContractShipmentType $NcShipment)
 {
     $XmlNonContractShipment = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><non-contract-shipment xmlns="http://www.canadapost.ca/ws/ncshipment-v' . self::API_VERSION . '"/>');
     $XmlNonContractShipment->addChild('requested-shipping-point', $NcShipment->getRequestedShippingPoint());
     $XmlNonContractShipmentDeliverySpec = $XmlNonContractShipment->addChild('delivery-spec');
     $XmlNonContractShipmentDeliverySpec->addChild('service-code', $NcShipment->getDeliverySpec()->getServiceCode());
     $XmlNonContractShipmentDeliverySpecSender = $XmlNonContractShipmentDeliverySpec->addchild('sender');
     $XmlNonContractShipmentDeliverySpecSender->addChild('name', $NcShipment->getDeliverySpec()->getSender()->getName());
     $XmlNonContractShipmentDeliverySpecSender->addChild('company', $NcShipment->getDeliverySpec()->getSender()->getCompany());
     $XmlNonContractShipmentDeliverySpecSender->addChild('contact-phone', $NcShipment->getDeliverySpec()->getSender()->getContactPhone());
     $XmlNonContractShipmentDeliverySpecSenderAddressDetails = $XmlNonContractShipmentDeliverySpecSender->addChild('address-details');
     $XmlNonContractShipmentDeliverySpecSenderAddressDetails->addChild('address-line-1', $NcShipment->getDeliverySpec()->getSender()->getAddressDetails()->getAddressLine1());
     $XmlNonContractShipmentDeliverySpecSenderAddressDetails->addChild('city', $NcShipment->getDeliverySpec()->getSender()->getAddressDetails()->getCity());
     $XmlNonContractShipmentDeliverySpecSenderAddressDetails->addChild('prov-state', $NcShipment->getDeliverySpec()->getSender()->getAddressDetails()->getProvState());
     $XmlNonContractShipmentDeliverySpecSenderAddressDetails->addChild('postal-zip-code', $NcShipment->getDeliverySpec()->getSender()->getAddressDetails()->getPostalZipCode());
     $XmlNonContractShipmentDeliverySpecDestination = $XmlNonContractShipmentDeliverySpec->addChild('destination');
     $XmlNonContractShipmentDeliverySpecDestination->addChild('name', $NcShipment->getDeliverySpec()->getDestination()->getName());
     $XmlNonContractShipmentDeliverySpecDestination->addChild('company', $NcShipment->getDeliverySpec()->getDestination()->getCompany());
     $XmlNonContractShipmentDeliverySpecDestinationAddressDetails = $XmlNonContractShipmentDeliverySpecDestination->addChild('address-details');
     $XmlNonContractShipmentDeliverySpecDestinationAddressDetails->addChild('address-line-1', $NcShipment->getDeliverySpec()->getDestination()->getAddressDetails()->getAddressLine1());
     $XmlNonContractShipmentDeliverySpecDestinationAddressDetails->addChild('city', $NcShipment->getDeliverySpec()->getDestination()->getAddressDetails()->getCity());
     $XmlNonContractShipmentDeliverySpecDestinationAddressDetails->addChild('prov-state', $NcShipment->getDeliverySpec()->getDestination()->getAddressDetails()->getProvState());
     $XmlNonContractShipmentDeliverySpecDestinationAddressDetails->addChild('country-code', $NcShipment->getDeliverySpec()->getDestination()->getAddressDetails()->getCountryCode());
     $XmlNonContractShipmentDeliverySpecDestinationAddressDetails->addChild('postal-zip-code', $NcShipment->getDeliverySpec()->getDestination()->getAddressDetails()->getPostalZipCode());
     $OptionsList = $NcShipment->getDeliverySpec()->getOptions();
     if ($OptionsList) {
         $Options = $OptionsList->getOptions();
         if ($Options) {
             $XmlNonContractShipmentDeliverySpecOptions = $XmlNonContractShipmentDeliverySpec->addChild('options');
             foreach ($Options as $Option) {
                 $XmlNonContractShipmentDeliverySpecOptionsOption = $XmlNonContractShipmentDeliverySpecOptions->addChild('option');
                 $XmlNonContractShipmentDeliverySpecOptionsOption->addChild('option-code', $Option->getOptionCode());
                 if (null !== $Option->getOptionAmount()) {
                     $XmlNonContractShipmentDeliverySpecOptionsOption->addChild('option-amount', number_format($Option->getOptionAmount(), 2, '.', ''));
                 }
                 if (null !== $Option->isOptionQualifier1()) {
                     $XmlNonContractShipmentDeliverySpecOptionsOption->addChild('option-qualifier-1', ['false', 'true'][(int) $Option->isOptionQualifier1()]);
                 }
                 if (null !== $Option->getOptionQualifier2()) {
                     $XmlNonContractShipmentDeliverySpecOptionsOption->addChild('option-amount', $Option->getOptionQualifier2());
                 }
             }
         }
     }
     $XmlNonContractShipmentDeliverySpecParcelCharacteristics = $XmlNonContractShipmentDeliverySpec->addChild('parcel-characteristics');
     $XmlNonContractShipmentDeliverySpecParcelCharacteristics->addChild('weight', $NcShipment->getDeliverySpec()->getParcelCharacteristics()->getWeight());
     $XmlNonContractShipmentDeliverySpecParcelCharacteristicsDimensions = $XmlNonContractShipmentDeliverySpecParcelCharacteristics->addChild('dimensions');
     $XmlNonContractShipmentDeliverySpecParcelCharacteristicsDimensions->addChild('length', $NcShipment->getDeliverySpec()->getParcelCharacteristics()->getDimensions()->getLength());
     $XmlNonContractShipmentDeliverySpecParcelCharacteristicsDimensions->addChild('width', $NcShipment->getDeliverySpec()->getParcelCharacteristics()->getDimensions()->getWidth());
     $XmlNonContractShipmentDeliverySpecParcelCharacteristicsDimensions->addChild('height', $NcShipment->getDeliverySpec()->getParcelCharacteristics()->getDimensions()->getHeight());
     $XmlNonContractShipmentDeliverySpecPreferences = $XmlNonContractShipmentDeliverySpec->addChild('preferences');
     $XmlNonContractShipmentDeliverySpecPreferences->addChild('show-packing-instructions', ['false', 'true'][(int) $NcShipment->getDeliverySpec()->getPreferences()->isShowPackingInstructions()]);
     $XmlNonContractShipmentDeliverySpecPreferences->addChild('show-postage-rate', ['false', 'true'][(int) $NcShipment->getDeliverySpec()->getPreferences()->isShowPostageRate()]);
     $XmlNonContractShipmentDeliverySpecPreferences->addChild('show-insured-value', ['false', 'true'][(int) $NcShipment->getDeliverySpec()->getPreferences()->isShowInsuredValue()]);
     $XmlNonContractShipmentDeliverySpecReferences = $XmlNonContractShipmentDeliverySpec->addChild('references');
     $XmlNonContractShipmentDeliverySpecReferences->addChild('cost-centre', $NcShipment->getDeliverySpec()->getReferences()->getCostCentre());
     $XmlNonContractShipmentDeliverySpecReferences->addChild('customer-ref-1', $NcShipment->getDeliverySpec()->getReferences()->getCustomerRef1());
     $XmlNonContractShipmentDeliverySpecReferences->addChild('customer-ref-2', $NcShipment->getDeliverySpec()->getReferences()->getCustomerRef2());
     $request = $XmlNonContractShipment->asXML();
     $response = $this->processRequest(['request_url' => '/ncshipment', 'headers' => ['Content-Type: application/vnd.cpc.ncshipment-v' . self::API_VERSION . '+xml', 'Accept: application/vnd.cpc.ncshipment-v' . self::API_VERSION . '+xml'], 'request' => $request]);
     $responseXML = new SimpleXMLElement($response);
     switch ($responseXML->getName()) {
         case 'non-contract-shipment-info':
             $NonContractShipmentInfoType = new NonContractShipmentInfoType();
             $NonContractShipmentInfoType->setShipmentId((string) $responseXML->{'shipment-id'});
             $NonContractShipmentInfoType->setTrackingPin((string) $responseXML->{'tracking-pin'});
             if ($responseXML->{'links'}->link) {
                 foreach ($responseXML->{'links'}->link as $link) {
                     $LinkType = new LinkType();
                     $LinkType->setHref((string) $link['href']);
                     $LinkType->setRel((string) $link['rel']);
                     $LinkType->setMediaType((string) $link['media-type']);
                     if (isset($link['index'])) {
                         $LinkType->setIndex((string) $link['index']);
                     }
                     $NonContractShipmentInfoType->addLink($LinkType);
                 }
             }
             return $NonContractShipmentInfoType;
             break;
         case 'messages':
             return WebService::getMessagesType($responseXML);
             break;
         default:
             return false;
             break;
     }
 }
use Distantia\CanadaPostWs\Type\NcShipment\DomesticAddressDetailsType;
use Distantia\CanadaPostWs\Type\NcShipment\NonContractShipmentInfoType;
use Distantia\CanadaPostWs\Type\NcShipment\NonContractShipmentType;
use Distantia\CanadaPostWs\Type\NcShipment\OptionsType;
use Distantia\CanadaPostWs\Type\NcShipment\OptionType;
use Distantia\CanadaPostWs\Type\NcShipment\ParcelCharacteristicsType;
use Distantia\CanadaPostWs\Type\NcShipment\PreferencesType;
use Distantia\CanadaPostWs\Type\NcShipment\ReferencesType;
use Distantia\CanadaPostWs\Type\NcShipment\SenderType;
use Distantia\CanadaPostWs\WebService;
require_once __DIR__ . '/../../vendor/autoload.php';
// Config (Must use an account without contract)
define('CANADA_POST_API_CUSTOMER_NUMBER', '');
define('CANADA_POST_API_KEY', '');
// Shipment object to create
$NcShipment = new NonContractShipmentType();
$NcShipment->setRequestedShippingPoint('H2B1A0');
$DeliverySpec = new DeliverySpecType();
$DeliverySpec->setServiceCode(WebService::$serviceCodes[WebService::SHIPPING_CODE_DOMESTIC_EXPEDITED]);
$Sender = new SenderType();
$Sender->setName('Bulma');
$Sender->setCompany('Capsule Corp.');
$Sender->setContactPhone('1 (514) 820 5879');
$AddressDetails = new DomesticAddressDetailsType();
$AddressDetails->setAddressLine1('502 MAIN ST N');
$AddressDetails->setCity('Montréal');
$AddressDetails->setProvState('QC');
$AddressDetails->setPostalZipCode('H2B1A0');
$Sender->setAddressDetails($AddressDetails);
$DeliverySpec->setSender($Sender);
$Destination = new DestinationType();