JeremyDunn / php-fedex-api-wrapper

This library provides a fluid interface for constructing requests to the FedEx web service API.
269 stars 184 forks source link

how to get pdf label after ship.php #77

Closed kruegge82 closed 5 years ago

kruegge82 commented 6 years ago

hello, i have tested with example/ship.php if i output the result, the object is protected... how can i output the label?

`[Label] => FedEx\ShipService\ComplexType\ShippingDocument Object ( [name:protected] => ShippingDocument [values:protected] => Array ( [Type] => OUTBOUND_LABEL [ShippingDocumentDisposition] => RETURNED [ImageType] => PDF [Resolution] => 200 [CopiesToPrint] => 1 [Parts] => Array ( [0] => FedEx\ShipService\ComplexType\ShippingDocumentPart Object ( [name:protected] => ShippingDocumentPart [values:protected] => Array ( [DocumentPartSequenceNumber] => 1 [Image] => %PDF-1.4 1 0 obj << /Type /Catalog /Pages 3 0 R

endobj 2 0 obj << /Type /Outlines /Count 0

endobj 3 0 obj << /Type /Pages /Count 4 /Kids [18 0 R 19 0 R 20 0 R 21 0 R]

endobj 4 0 obj [/PDF /Text /ImageB /ImageC /ImageI] endobj 5 0 obj << /Type /Font......`

syedMSohaib commented 6 years ago

hey @kruegge82 are you able to get shipping rates. I am trying to run example1.php in examples folder, have updated the credentials.php but still i am unable to get complete response.

AbhayLodhi commented 6 years ago

Try this settings for label generation

try{
    if(setEndpoint('changeEndpoint')){
        $newLocation = $client->__setLocation(setEndpoint('endpoint'));
    }
    $response = $client->processShipment($request);
    if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR'){
        // Create PNG or PDF label
        // Set LabelSpecification.ImageType to 'PDF' for generating a PDF label
        $fp = fopen($shippingLabel."_".$fetch['orderID'].".pdf", 'wb');   
        fwrite($fp, ($response->CompletedShipmentDetail->CompletedPackageDetails->Label->Parts->Image));
        fclose($fp);
        echo 'Label <a  href="./'.$shippingLabel."_".$fetch['orderID'].".pdf".'">'.$shippingLabel."_".$fetch['orderID'].".pdf".'</a> was generated.';            
    }else{
       printError($client, $response);
    }
writeToLog($client);    // Write to log file
} catch (SoapFault $exception) {
    printFault($exception, $client);
}

function addLabelSpecification(){
    $labelSpecification = array(
        'LabelFormatType' => 'COMMON2D', // valid values COMMON2D, LABEL_DATA_ONLY
        'ImageType' => 'PDF',  // valid values DPL, EPL2, PDF, ZPLII and PNG
        'LabelStockType' => 'PAPER_8.5X11_TOP_HALF_LABEL'
    );
    return $labelSpecification;
}
JeremyDunn commented 5 years ago

The ship.php example has been updated to demonstrate how to save the label to a file.

https://github.com/JeremyDunn/php-fedex-api-wrapper/blob/master/examples/ship.php#L130-L131