Exemple #1
0
 // end of function addPackageLineItem
 $newline = "<br />";
 //The WSDL is not included with the sample code.
 //Please include and reference in $path_to_wsdl variable.
 $path_to_wsdl = "wsdl/ShipService_v17.wsdl";
 $pdf_file = "shipexpresslabel" . rand(1, 50000) . ".pdf";
 define('SHIP_LABEL', $pdf_file);
 // 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' => $_POST['ServiceType'], 'PackagingType' => 'YOUR_PACKAGING', 'Shipper' => addShipper($_POST), 'Recipient' => addRecipient($_POST), 'ShippingChargesPayment' => addShippingChargesPayment($_POST), 'CustomsClearanceDetail' => addCustomClearanceDetail($_POST), 'LabelSpecification' => addLabelSpecification($_POST), 'CustomerSpecifiedDetail' => array('MaskedData' => 'SHIPPER_ACCOUNT_NUMBER'), 'PackageCount' => 1, 'RequestedPackageLineItems' => array('0' => addPackageLineItem($_POST)), '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') {
         // add into database
         $address = $_POST['StreetLines'] . '<br>' . $_POST['City'] . '<br>' . $_POST['StateOrProvinceCode'] . '<br>' . $_POST['PostalCode'] . '<br>' . $_POST['CountryCode'];
         $token = $response->CompletedShipmentDetail->CompletedPackageDetails->TrackingIds->TrackingNumber;
         $sql = "INSERT INTO shipments (length, width, height, weight, receiver, receiver_company, receiver_phone, receiver_address, service_type, token, status)\n\t\t\t\tVALUES ('" . $_POST['Length'] . "', '" . $_POST['Width'] . "', '" . $_POST['Height'] . "', '" . $_POST['Weight'] . "', '" . $_POST['PersonName'] . "', '" . $_POST['CompanyName'] . "', '" . $_POST['PhoneNumber'] . "', '" . $address . "', '" . $_POST['ServiceType'] . "', '" . $token . "', '1')";
         $conn->query($sql);
         echo 'Shipment created successfully! <br> Tracking Number: ' . $token . '<br>';
         // printSuccess($client, $response);
         // Create PNG or PDF label
Exemple #2
0
 $request['TransactionDetail'] = array('CustomerTransactionId' => ' *** SmartPost Rate Request using PHP ***');
 $request['Version'] = array('ServiceId' => 'crs', 'Major' => '18', 'Intermediate' => '0', 'Minor' => '0');
 $request['ReturnTransitAndCommit'] = true;
 $request['RequestedShipment']['DropoffType'] = 'REGULAR_PICKUP';
 // valid values REGULAR_PICKUP, REQUEST_COURIER, ...
 $request['RequestedShipment']['ShipTimestamp'] = date('c');
 $request['RequestedShipment']['ServiceType'] = $_POST['ServiceType'];
 // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
 $request['RequestedShipment']['PackagingType'] = 'YOUR_PACKAGING';
 // valid values FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
 $request['RequestedShipment']['Shipper'] = addShipper($_POST);
 $request['RequestedShipment']['Recipient'] = addRecipient($_POST);
 $request['RequestedShipment']['ShippingChargesPayment'] = addShippingChargesPayment($_POST);
 $request['RequestedShipment']['SmartPostDetail'] = addSmartPostDetail($_POST);
 $request['RequestedShipment']['PackageCount'] = '1';
 $request['RequestedShipment']['RequestedPackageLineItems'] = addPackageLineItem($_POST);
 try {
     if (setEndpoint('changeEndpoint')) {
         $newLocation = $client->__setLocation(setEndpoint('endpoint'));
     }
     $response = $client->getRates($request);
     if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR') {
         $rateReply = $response->RateReplyDetails;
         echo '<table border="1">';
         echo '<tr><td>Service Type</td><td>Amount</td><td>Transit Time</td><td>Max Transit Time</td><td>Ship</td></tr><tr>';
         $serviceType = '<td>' . $rateReply->ServiceType . '</td>';
         if ($rateReply->RatedShipmentDetails && is_array($rateReply->RatedShipmentDetails)) {
             $amount = '<td>$' . number_format($rateReply->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount, 2, ".", ",") . '</td>';
         } elseif ($rateReply->RatedShipmentDetails && !is_array($rateReply->RatedShipmentDetails)) {
             $amount = '<td>$' . number_format($rateReply->RatedShipmentDetails->ShipmentRateDetail->TotalNetCharge->Amount, 2, ".", ",") . '</td>';
         }