PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Mubashir Ali   PHP DHL Paperless API   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example relating DHL paperless functionality
Class: PHP DHL Paperless API
Submit shipment documents DHL paperless clearance
Author: By
Last change:
Date: 11 years ago
Size: 5,401 bytes
 

Contents

Class file image Download
<?php
   
require_once('class.dhl-paperless.php');
   
   
$objPL = new DHLPaperless();
   
   
$file_name = 'test.pdf';
    if(!
file_exists($file_name))
        exit(
"<h1>File does not exist.</h1>");

   
$doc_id_sequence = strtotime('now')."000000000000000";

   
$aryParam['Hdr']['Id'] = "123456"; //Unique Request Identifier
   
$aryParam['Hdr']['AppCd'] = "99951"; //Requesting Application Code - Unit ID = Each customer receives one or more unit
   
$aryParam['Bd']['Shp']['Id'] = "5556667001"; //Waybill number assigned to shipment
   
$aryParam['Bd']['Shp']['ShpTr']['CstValCurCd'] = "USD"; //Shipment Customs Value currency code. For US origin shipments, the currency code will be 'USD'
   
$aryParam['Bd']['Shp']['ShpTr']['CstVal'] = "10.000"; //Shipment Custom Value, it should have 3 decimal places

    /**
     * @MgNProdCd
     * Product Valid values:
     * EXPRESS WORLDWIDE = "P"
     * EXPRESS 9:00 "E"
     * EXPRESS 10:30 = "M"
     * EXPRESS 12:00 = "Y"
     */
   
$aryParam['Bd']['Shp']['ShpTr']['MgNProdCd'] = "P";
   
$aryParam['Bd']['Shp']['ShpTr']['OrgSrvaCd'] = "LGB";
   
$aryParam['Bd']['Shp']['ShpTr']['OrgFcCd'] = "LGB";

   
$aryParam['Bd']['Shp']['ShpTr']['SCDtl'][0]['CRlTyCd'] = "SP"; //Shipper Country [From]
   
$aryParam['Bd']['Shp']['ShpTr']['SCDtl'][0]['CtryCd'] = "US"; //Source Country Name [US - United States]
   
$aryParam['Bd']['Shp']['ShpTr']['SCDtl'][1]['CRlTyCd'] = "RV"; //Receiver Country [To]
   
$aryParam['Bd']['Shp']['ShpTr']['SCDtl'][1]['CtryCd'] = "AU"; //Destination Country Name - [AU - Australia]

    /**
     * Document Type codes used in the request
     * CIN = Commercial Invoice and other customs document images.
     * HWB - Archive Dod label image
     */
   
$aryParam['Bd']['Shp']['ShpInDoc'][0]['SDoc']['DocTyCd'] = "HWB";
   
$aryParam['Bd']['Shp']['ShpInDoc'][0]['SDoc']['DocId'] = bcadd($doc_id_sequence,'1'); //Shipment Documentation Identifier, that must be unique within shipment elements
   
$aryParam['Bd']['Shp']['ShpInDoc'][0]['SDoc']['Img']['ImgID'] = "1"; //image identifier that uniquely idenfies an image
   
$aryParam['Bd']['Shp']['ShpInDoc'][0]['SDoc']['Img']['SrcAppNm'] = "eXtremeShipping"; //Source Application Name
    /**
     * @ImgEncdTy
     * Image Encoded types used in the request to identify document image types. Valid values are:
     * PDF - Portable Document Format
     * TIF - Tag Image File Format
     * JPG - Joint Photographic Experts Group
     * PNG - Portable Network Graphics
     * GIF - Graphics Interchange Format
     */
   
$aryParam['Bd']['Shp']['ShpInDoc'][0]['SDoc']['Img']['ImgEncdTy'] = "PDF";
   
/**
     * @ImgMimeTy
     * Image encoded type used in the request to identify document image types. Valid values are:
     * application/pdf = Portable Document format
     * image/tiff
     * image/jpeg
     * image/png
     * image/gif
     */
   
$aryParam['Bd']['Shp']['ShpInDoc'][0]['SDoc']['Img']['ImgMimeTy'] = "application/pdf";

   
$aryParam['Bd']['Shp']['ShpInDoc'][1]['SDoc']['DocTyCd'] = "CIN";
   
$aryParam['Bd']['Shp']['ShpInDoc'][1]['SDoc']['DocId'] = bcadd($doc_id_sequence,'2'); //Shipment Documentation Identifier, that must be unique within shipment elements
   
$aryParam['Bd']['Shp']['ShpInDoc'][1]['SDoc']['Img']['ImgID'] = "2"; //image identifier that uniquely idenfies an image
   
$aryParam['Bd']['Shp']['ShpInDoc'][1]['SDoc']['Img']['SrcAppNm'] = "eXtremeShipping"; //Source Application Name
   
$aryParam['Bd']['Shp']['ShpInDoc'][1]['SDoc']['Img']['ImgEncdTy'] = "PDF";
   
$aryParam['Bd']['Shp']['ShpInDoc'][1]['SDoc']['Img']['ImgMimeTy'] = "application/pdf";

   
$aryParam['Bd']['Shp']['ShpInDoc'][2]['SDoc']['DocTyCd'] = "CIN";
   
$aryParam['Bd']['Shp']['ShpInDoc'][2]['SDoc']['DocId'] = bcadd($doc_id_sequence,'3');
   
$aryParam['Bd']['Shp']['ShpInDoc'][2]['SDoc']['Img']['ImgID'] = "3";
   
$aryParam['Bd']['Shp']['ShpInDoc'][2]['SDoc']['Img']['SrcAppNm'] = "eXtremeShipping";
   
$aryParam['Bd']['Shp']['ShpInDoc'][2]['SDoc']['Img']['ImgEncdTy'] = "PDF";
   
$aryParam['Bd']['Shp']['ShpInDoc'][2]['SDoc']['Img']['ImgMimeTy'] = "application/pdf";

   
/**
     * @TyCd
     * Generic request type code. Valid value: SHP_VAL_TY 'Shipment Validation Type'
     */
   
$aryParam['Bd']['GenrcRq']['GenrcRqCritr']['TyCd'] = "SHP_VAL_TY";

   
/**
     * @Val
     * Request Type. Valid Value:
     * ECO = Validates whether shipment is allowed for Paperless Clearance
     */
   
$aryParam['Bd']['GenrcRq']['GenrcRqCritr']['Val'] = "ECO";

   
$req = $objPL->generateXMLRequest($file_name, $aryParam);
   
$response = $objPL->processCurlRequest($req);

   
$objPL->loadXml($response);
   
$aryResponse = $objPL->toArray();
   
$res = $objPL->processResponseArray($aryResponse);

// echo "<h1>Actual Response</h1>";
// echo "<pre>";
// print_r($response);
// echo "</pre>";

   
echo "<h1>Response [In Array]</h1>";
    echo
"<pre>";
   
print_r($aryResponse);
    echo
"</pre>";

    echo
"<h1>Formated Response</h1>";
    if(
$res[1])
        echo
"<h3>Success: </h3>";
    else
        echo
"<h3>Error: </h3>";
    echo
"<pre>";
   
print_r($res);
    echo
"</pre>";
?>