$DeliverySpec->setNotification($Notification); $PrintPreferences = new PrintPreferencesType(); $PrintPreferences->setOutputFormat(PrintPreferencesType::OUTPUT_FORMAT_LETTER); $DeliverySpec->setPrintPreferences($PrintPreferences); $Preferences = new PreferencesType(); $Preferences->setShowPackingInstructions(true); $Preferences->setShowPostageRate(false); $Preferences->setShowInsuredValue(true); $DeliverySpec->setPreferences($Preferences); $References = new ReferencesType(); $References->setCostCentre('ccent'); $References->setCustomerRef1('ML5'); $References->setCustomerRef2('custref2'); $DeliverySpec->setReferences($References); $SettlementInfo = new SettlementInfoType(); $SettlementInfo->setContractId(CANADA_POST_API_CONTRACT_ID); $SettlementInfo->setIntendedMethodOfPayment('Account'); $DeliverySpec->setSettlementInfo($SettlementInfo); $Shipment->setDeliverySpec($DeliverySpec); // Initiate Canada Post's API $Shipping = new Shipping(['api_customer_number' => CANADA_POST_API_CUSTOMER_NUMBER, 'api_key' => CANADA_POST_API_KEY, 'env' => WebService::ENV_DEV, 'ssl' => true]); // Send request to create shipment $shipmentResponse = $Shipping->createShipment($Shipment); // Output result for debug if ($shipmentResponse instanceof ShipmentInfoType) { var_dump($shipmentResponse); } elseif ($shipmentResponse instanceof MessagesType) { var_dump($shipmentResponse); } else { throw new \Exception('Unexpected response.'); }
<?php use Distantia\CanadaPostWs\Shipping; use Distantia\CanadaPostWs\Type\Manifest\ManifestType; use Distantia\CanadaPostWs\Type\Messages\MessagesType; use Distantia\CanadaPostWs\WebService; require_once __DIR__ . '/../../vendor/autoload.php'; // Config define('CANADA_POST_API_CUSTOMER_NUMBER', '2004381'); define('CANADA_POST_API_CONTRACT_ID', '42708517'); define('CANADA_POST_API_KEY', '6e93d53968881714:0bfa9fcb9853d1f51ee57a'); $manifestId = '92021451409891971'; // Initiate Canada Post's API $Shipping = new Shipping(['api_customer_number' => CANADA_POST_API_CUSTOMER_NUMBER, 'api_key' => CANADA_POST_API_KEY, 'env' => WebService::ENV_DEV, 'ssl' => true]); // Send request to get manifests $manifestResponse = $Shipping->getManifest($manifestId); // Output result for debug if ($manifestResponse instanceof ManifestType) { var_dump($manifestResponse); } elseif ($manifestResponse instanceof MessagesType) { var_dump($manifestResponse); } else { throw new \Exception('Unexpected response.'); }
<?php use Distantia\CanadaPostWs\Shipping; use Distantia\CanadaPostWs\Type\Manifest\ManifestsType; use Distantia\CanadaPostWs\Type\Messages\MessagesType; use Distantia\CanadaPostWs\WebService; require_once __DIR__ . '/../../vendor/autoload.php'; // Config define('CANADA_POST_API_CUSTOMER_NUMBER', '2004381'); define('CANADA_POST_API_CONTRACT_ID', '42708517'); define('CANADA_POST_API_KEY', '6e93d53968881714:0bfa9fcb9853d1f51ee57a'); $startDate = new \DateTime('-5 days'); $endDate = new \DateTime(); // Initiate Canada Post's API $Shipping = new Shipping(['api_customer_number' => CANADA_POST_API_CUSTOMER_NUMBER, 'api_key' => CANADA_POST_API_KEY, 'env' => WebService::ENV_DEV, 'ssl' => true]); // Send request to get manifests $manifestsResponse = $Shipping->getManifests($startDate, $endDate); // Output result for debug if ($manifestsResponse instanceof ManifestsType) { var_dump($manifestsResponse); } elseif ($manifestsResponse instanceof MessagesType) { var_dump($manifestsResponse); } else { throw new \Exception('Unexpected response.'); }
<?php use Distantia\CanadaPostWs\Shipping; use Distantia\CanadaPostWs\Type\Messages\MessagesType; use Distantia\CanadaPostWs\Type\Shipment\ShipmentInfoType; use Distantia\CanadaPostWs\WebService; require_once __DIR__ . '/../../vendor/autoload.php'; // Config define('CANADA_POST_API_CUSTOMER_NUMBER', '2004381'); define('CANADA_POST_API_CONTRACT_ID', '42708517'); define('CANADA_POST_API_KEY', '6e93d53968881714:0bfa9fcb9853d1f51ee57a'); $shipmentId = '90011451428208409'; // Initiate Canada Post's API $Shipping = new Shipping(['api_customer_number' => CANADA_POST_API_CUSTOMER_NUMBER, 'api_key' => CANADA_POST_API_KEY, 'env' => WebService::ENV_DEV, 'ssl' => true]); // Send request to get shipment $shipmentResponse = $Shipping->getShipment($shipmentId); // Output result for debug if ($shipmentResponse instanceof ShipmentInfoType) { var_dump($shipmentResponse); $Links = $shipmentResponse->getLinks(); if ($Links) { foreach ($Links as $Link) { echo $Link->getRel() . '<br>'; var_dump($Link->processLink(CANADA_POST_API_KEY, true)); } } } elseif ($shipmentResponse instanceof MessagesType) { var_dump($shipmentResponse); } else { throw new \Exception('Unexpected response.'); }
$ShipmentTransmitSet = new ShipmentTransmitSetType(); $GroupIds = new GroupIdListType(); $GroupIds->setGroupId('4326432'); $ShipmentTransmitSet->addGroupId($GroupIds); $ShipmentTransmitSet->setRequestedShippingPoint('H2B1A0'); $ShipmentTransmitSet->setCpcPickupIndicator(true); $ShipmentTransmitSet->setDetailedManifests(true); $ShipmentTransmitSet->setMethodOfPayment('Account'); $ManifestAddress = new ManifestAddressType(); $ManifestAddress->setManifestCompany('MajorShop'); $ManifestAddress->setPhoneNumber('514 829 5879'); $AddressDetails = new AddressDetailsType(); $AddressDetails->setAddressLine1('1230 Tako RD.'); $AddressDetails->setCity('Ottawa'); $AddressDetails->setProvState('ON'); $AddressDetails->setCountryCode('CA'); $AddressDetails->setPostalZipCode('H2B1A0'); $ManifestAddress->setAddressDetails($AddressDetails); $ShipmentTransmitSet->setManifestAddress($ManifestAddress); // Initiate Canada Post's API $Shipping = new Shipping(['api_customer_number' => CANADA_POST_API_CUSTOMER_NUMBER, 'api_key' => CANADA_POST_API_KEY, 'env' => WebService::ENV_DEV, 'ssl' => true]); // Send request to transmit shipments $transmitShipmentsResponse = $Shipping->transmitShipments($ShipmentTransmitSet); // Output result for debug if ($transmitShipmentsResponse instanceof ManifestsType) { var_dump($transmitShipmentsResponse); } elseif ($transmitShipmentsResponse instanceof MessagesType) { var_dump($transmitShipmentsResponse); } else { throw new \Exception('Unexpected response.'); }