'ShippingChargesPayment' => addShippingChargesPayment(),
	'LabelSpecification' => addLabelSpecification(), 
	'PackageCount' => 2,
	'RequestedPackageLineItems' => array(
		'0' => addPackageLineItem1()
	)
);



try {
	if(setEndpoint('changeEndpoint')){
		$newLocation = $client->__setLocation(setEndpoint('endpoint'));
	}
		
	$masterResponse = $client->processShipment($masterRequest); // FedEx web service invocation  
	
	writeToLog($client);    // Write to log file

	if ($masterResponse->HighestSeverity != 'FAILURE' && $masterResponse->HighestSeverity != 'ERROR'){
	    printSuccess($client, $masterResponse);
	
	    $fp = fopen(SHIP_CODMASTERLABEL, 'wb');   
	    fwrite($fp, $masterResponse->CompletedShipmentDetail->CompletedPackageDetails->CodReturnDetail->Label->Parts->Image); //Create COD Return PNG or PDF file
	    fclose($fp);
	    echo '<a href="./'.SHIP_CODMASTERLABEL.'">'.SHIP_CODMASTERLABEL.'</a> was generated.'.Newline;
	
	    // Create PNG or PDF label
	    // Set LabelSpecification.ImageType to 'PDF' for generating a PDF label
	    $fp = fopen(SHIP_MASTERLABEL, 'wb');   
	    fwrite($fp, ($masterResponse->CompletedShipmentDetail->CompletedPackageDetails->Label->Parts->Image));
Beispiel #2
0
 /**
  * Confirm a shipment
  *
  * @param bool $verifyPeer
  *
  * @throws \Exception
  *
  * @return array label file format, label image data
  */
 public function ship($verifyPeer = true)
 {
     $request = [];
     $request['Version'] = array('ServiceId' => 'ship', 'Major' => '17', 'Intermediate' => '0', 'Minor' => '0');
     $serviceType = isset($this->shippingInfo->serviceType) ? $this->shippingInfo->serviceType : 'STANDARD_OVERNIGHT';
     $packageType = isset($this->shippingInfo->PackagingType) ? $this->shippingInfo->PackagingType : 'YOUR_PACKAGING';
     $request['RequestedShipment'] = array('ShipTimestamp' => date('c'), 'DropoffType' => $this->dropOfType, 'ServiceType' => $serviceType, 'PackagingType' => $packageType, 'Shipper' => $this->shipFrom, 'Recipient' => $this->shipTo, 'ShippingChargesPayment' => $this->addShippingChargesPayment(), 'LabelSpecification' => $this->addLabelSpecification(), 'CustomerSpecifiedDetail' => array('MaskedData' => 'SHIPPER_ACCOUNT_NUMBER'), 'PackageCount' => 1, 'RequestedPackageLineItems' => array('0' => $this->addPackageLineItem1()));
     $request = array_merge($this->requestHeader, $request);
     $this->client = new \SoapClient($this->wsdl['shipping'], ['trace' => 1]);
     $this->response = $this->client->processShipment($request);
     if ($this->response->HighestSeverity === 'ERROR') {
         $errors = $this->response->Notifications;
         if (is_object($errors)) {
             $errors = [$errors];
         }
         foreach ($errors as $error) {
             if ($error->Severity === 'ERROR') {
                 $errorMsg[] = $error->Message;
             }
         }
         throw new \Exception(implode("\n", $errorMsg), $errors[0]->Code);
     }
     $label = $this->response->CompletedShipmentDetail->CompletedPackageDetails->Label->Parts->Image;
     return ['png', base64_decode($label)];
 }
 public function generate_label($order)
 {
     set_time_limit(30);
     // prevent timeout in batch processing
     ini_set("soap.wsdl_cache_enabled", "0");
     try {
         $client = new SoapClient($this->wsdl_path());
         // creating request object for this item
         $request = $this->create_request($order);
         // send request object to FedEx web service
         $response = $client->processShipment($request);
         // was request successful?
         if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR') {
             return array('label_data' => $response->CompletedShipmentDetail->CompletedPackageDetails->Label->Parts->Image, 'tracking_number' => $this->get_ground_tracking_number($response->CompletedShipmentDetail->CompletedPackageDetails->TrackingIds));
         } else {
             $this->write_to_log('Unable to generate label: ' . "\n" . print_r($response->Notifications, true));
             return array('error' => $this->get_error_messages($response->Notifications));
         }
     } catch (SoapFault $exception) {
         $this->write_to_log('SoapFault: ' . $exception->getMessage());
         return array('error' => 'SoapFault: ' . $exception->getMessage());
     } catch (Exception $exception) {
         $this->write_to_log($exception->getMessage());
         return array('error' => 'Exception: ' . $exception->getMessage());
     }
 }
Beispiel #4
0
$path_to_wsdl = "../../../wsdl/beta/ShipService_v17.wsdl";
define('SHIP_LABEL', 'shipexpresslabel.pdf');
// PDF label file. Change to file-extension .pdf for creating a PDF label (e.g. shiplabel.pdf)
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient($path_to_wsdl, array('trace' => 1));
// Refer to http://us3.php.net/manual/en/ref.soap.php for more information
$request['WebAuthenticationDetail'] = array('ParentCredential' => array('Key' => getProperty('parentkey'), 'Password' => getProperty('parentpassword')), 'UserCredential' => array('Key' => getProperty('key'), 'Password' => getProperty('password')));
$request['ClientDetail'] = array('AccountNumber' => getProperty('shipaccount'), 'MeterNumber' => getProperty('meter'));
$request['TransactionDetail'] = array('CustomerTransactionId' => '*** Express International Shipping Request using PHP ***');
$request['Version'] = array('ServiceId' => 'ship', 'Major' => '17', 'Intermediate' => '0', 'Minor' => '0');
$request['RequestedShipment'] = array('ShipTimestamp' => date('c'), 'DropoffType' => 'REGULAR_PICKUP', 'ServiceType' => 'INTERNATIONAL_PRIORITY', 'PackagingType' => 'YOUR_PACKAGING', 'Shipper' => addShipper(), 'Recipient' => addRecipient(), 'ShippingChargesPayment' => addShippingChargesPayment(), 'CustomsClearanceDetail' => addCustomClearanceDetail(), 'LabelSpecification' => addLabelSpecification(), 'CustomerSpecifiedDetail' => array('MaskedData' => 'SHIPPER_ACCOUNT_NUMBER'), 'PackageCount' => 1, 'RequestedPackageLineItems' => array('0' => addPackageLineItem1()), 'CustomerReferences' => array('0' => array('CustomerReferenceType' => 'CUSTOMER_REFERENCE', 'Value' => 'TC007_07_PT1_ST01_PK01_SNDUS_RCPCA_POS')));
try {
    if (setEndpoint('changeEndpoint')) {
        $newLocation = $client->__setLocation(setEndpoint('endpoint'));
    }
    $response = $client->processShipment($request);
    // FedEx web service invocation
    if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR') {
        printSuccess($client, $response);
        // Create PNG or PDF label
        // Set LabelSpecification.ImageType to 'PDF' for generating a PDF label
        $fp = fopen(SHIP_LABEL, 'wb');
        fwrite($fp, $response->CompletedShipmentDetail->CompletedPackageDetails->Label->Parts->Image);
        fclose($fp);
        echo 'Label <a href="./' . SHIP_LABEL . '">' . SHIP_LABEL . '</a> was generated.';
    } else {
        printError($client, $response);
    }
    writeToLog($client);
    // Write to log file
} catch (SoapFault $exception) {
 /**
  * Sends the ProcessShipmentRequest and returns the response
  *
  * @param ComplexType\ProcessShipmentRequest $processShipmentRequest 
  * @return stdClass
  */
 public function getProcessShipmentReply(ComplexType\ProcessShipmentRequest $processShipmentRequest)
 {
     return $this->_soapClient->processShipment($processShipmentRequest->toArray());
 }
Beispiel #6
0
 function retrieveLabel($sInfo)
 {
     global $messageStack;
     $fedex_results = array();
     if (in_array($sInfo->ship_method, array('I2DEam', 'I2Dam', 'I3D'))) {
         // unsupported ship methods
         $messageStack->add('The ship method requested is not supported by this tool presently. Please ship the package via a different tool.', 'error');
         return false;
     }
     if (MODULE_SHIPPING_FEDEX_V7_TEST_MODE == 'Test') {
         $client = new SoapClient(PATH_TO_TEST_SHIP_WSDL, array('trace' => 1));
     } else {
         $client = new SoapClient(PATH_TO_SHIP_WSDL, array('trace' => 1));
     }
     for ($key = 0; $key < count($sInfo->package); $key++) {
         $labels = array();
         $request = $this->FormatFedExShipRequest($sInfo, $key);
         //echo 'FedEx Express XML Label Submit String:'; print_r($request); echo '<br />';
         try {
             $response = $client->processShipment($request);
             //echo 'Request <pre>' . htmlspecialchars($client->__getLastRequest()) . '</pre>';
             //echo 'Response <pre>' . htmlspecialchars($client->__getLastResponse()) . '</pre>';
             //echo 'label response array = '; print_r($response); echo '<br />';
             if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR') {
                 if ($key == 0) {
                     $sInfo->master_tracking = $response->CompletedShipmentDetail->MasterTrackingId;
                 }
                 $net_cost = 0;
                 $book_cost = 0;
                 $del_date = '';
                 if (isset($response->CompletedShipmentDetail->OperationalDetail->DeliveryDate)) {
                     $del_code = $response->CompletedShipmentDetail->OperationalDetail->DestinationServiceArea;
                     $guar_time = $this->calculateDeliveryTime($sInfo->ship_method, $del_code, $sInfo->residential_address);
                     $del_date = $response->CompletedShipmentDetail->OperationalDetail->DeliveryDate . ' ' . $guar_time;
                 } elseif (isset($response->CompletedShipmentDetail->OperationalDetail->MaximumTransitTime)) {
                     $del_date = $this->calculateDelivery($response->CompletedShipmentDetail->OperationalDetail->MaximumTransitTime, $sInfo->residential_address);
                 } elseif (isset($response->CompletedShipmentDetail->OperationalDetail->TransitTime)) {
                     $del_date = $this->calculateDelivery($response->CompletedShipmentDetail->OperationalDetail->TransitTime, $sInfo->residential_address);
                 }
                 if (is_array($response->CompletedShipmentDetail->CompletedPackageDetails->PackageRating->PackageRateDetails)) {
                     foreach ($response->CompletedShipmentDetail->CompletedPackageDetails->PackageRating->PackageRateDetails as $rate) {
                         switch ($rate->RateType) {
                             case 'PAYOR_ACCOUNT_PACKAGE':
                             case 'PAYOR_ACCOUNT_SHIPMENT':
                                 $net_cost = $rate->NetCharge->Amount;
                                 break;
                             case 'PAYOR_LIST_SHIPMENT':
                             case 'PAYOR_LIST_PACKAGE':
                                 $book_cost = $rate->NetCharge->Amount;
                                 break;
                         }
                     }
                 }
                 if ($response->CompletedShipmentDetail->CarrierCode == 'FXFR') {
                     // LTL Freight
                     //echo 'Request <pre>' . htmlspecialchars($client->__getLastRequest()) . '</pre>';
                     $is_ltl = true;
                     // special handling for freight, hard coded label types for now
                     $tracking = $response->CompletedShipmentDetail->MasterTrackingId->TrackingNumber;
                     $zone = '';
                     foreach ($response->CompletedShipmentDetail->ShipmentDocuments as $document) {
                         $labels[] = $document->Parts->Image;
                     }
                 } else {
                     $is_ltl = false;
                     $zone = $response->CompletedShipmentDetail->ShipmentRating->ShipmentRateDetails->RateZone;
                     $labels[] = $response->CompletedShipmentDetail->CompletedPackageDetails->Label->Parts->Image;
                     if (is_array($response->CompletedShipmentDetail->CompletedPackageDetails->TrackingIds)) {
                         // Smart Post
                         foreach ($response->CompletedShipmentDetail->CompletedPackageDetails->TrackingIds as $track_num) {
                             if ($track_num->TrackingIdType == 'GROUND') {
                                 $tracking = $track_num->TrackingNumber;
                             }
                         }
                     } else {
                         $tracking = $response->CompletedShipmentDetail->CompletedPackageDetails->TrackingIds->TrackingNumber;
                     }
                 }
                 if (!$tracking) {
                     $messageStack->add('Error - No tracking found in return string.', 'error');
                     //echo 'label response array = '; print_r($response); echo '<br />';
                     return false;
                 }
                 $fedex_results[$key] = array('ref_id' => $sInfo->purchase_invoice_id . '-' . ($key + 1), 'tracking' => $tracking, 'zone' => $zone, 'book_cost' => $book_cost, 'net_cost' => $net_cost, 'delivery_date' => $del_date);
                 if (sizeof($labels) > 0) {
                     $cnt = 0;
                     $date = explode('-', $sInfo->ship_date);
                     $file_path = SHIPPING_DEFAULT_LABEL_DIR . $this->code . '/' . $date[0] . '/' . $date[1] . '/' . $date[2] . '/';
                     validate_path($file_path);
                     foreach ($labels as $label) {
                         $this->returned_label = $label;
                         // check for label to be for thermal printer or plain paper
                         if (MODULE_SHIPPING_FEDEX_V7_PRINTER_TYPE == 'Thermal') {
                             // keep the thermal label encoded for now
                             $file_name = $tracking . ($cnt > 0 ? '-' . $cnt : '') . '.lpt';
                             // thermal printer
                             if ($is_ltl && $cnt > 0) {
                                 $file_name = $tracking . '-' . $cnt . '.pdf';
                             }
                             // BOL must be PDF
                         } else {
                             $file_name = $tracking . ($cnt > 0 ? '-' . $cnt : '') . '.pdf';
                             // plain paper
                         }
                         if (!($handle = fopen($file_path . $file_name, 'w'))) {
                             $messageStack->add('Cannot open file (' . $file_path . $file_name . ')', 'error');
                             return false;
                         }
                         if (fwrite($handle, $label) === false) {
                             $messageStack->add('Cannot write to file (' . $file_path . $file_name . ')', 'error');
                             return false;
                         }
                         fclose($handle);
                         $cnt++;
                         //					$messageStack->add('Successfully retrieved the FedEx shipping label. Tracking # ' . $fedex_results[$key]['tracking'],'success');
                     }
                 } else {
                     $messageStack->add('Error - No label found in return string.', 'error');
                     return false;
                 }
             } else {
                 foreach ($response->Notifications as $notification) {
                     if (is_object($notification)) {
                         $message .= ' (' . $notification->Severity . ') ' . $notification->Message;
                     } else {
                         $message .= ' ' . $notification;
                     }
                 }
                 //echo 'Request <pre>' . htmlspecialchars($client->__getLastRequest()) . '</pre>';
                 $messageStack->add(SHIPPING_FEDEX_V7_RATE_ERROR . $message, 'error');
                 return false;
             }
         } catch (SoapFault $exception) {
             //echo 'Request <pre>' . htmlspecialchars($client->__getLastRequest()) . '</pre>';
             //echo 'Response <pre>' . htmlspecialchars($client->__getLastResponse()) . '</pre>';
             $message = " [label soap fault] ({$exception->faultcode}) {$exception->faultstring}";
             $messageStack->add(SHIPPING_FEDEX_CURL_ERROR . $message, 'error');
             return false;
         }
     }
     return $fedex_results;
 }