Пример #1
0
$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.');
}