Edit file File name : CourierService.php.bk Content :<?php class CourierService extends Courrier { //Configuration const AccessLicenseNumber = "ED58E56438B88ECC"; const UserID = "MyValue365"; const Password = "hPawha365$"; const Operation = "ProcessRate"; const EndPointTracking="https://wwwcie.ups.com/rest/Track"; /* * Production */ //const EndPointURL = 'https://wwwcie.ups.com/rest/Rate'; //const EndPointShippingURL = 'https://onlinetools.ups.com/rest/Ship'; /* * Test */ const EndPointURL = 'https://wwwcie.ups.com/rest/Rate'; //const EndPointURL = 'https://onlinetools.ups.com/rest/Track'; const EndPointShippingURL = 'https://wwwcie.ups.com/ship/v1807/shipments?additionaladdressvalidation=city'; public function __construct() { /** * ounce, pound, gram **/ $this->setRequestOption("Rate"); $this->setPickupTypeCode("01"); $this->setPickupTypeDescription("Daily Pickup"); $this->setCustomerClassificationCode("01"); $this->setCustomerClassificationDescription("Classfication"); $this->setValidateAddress('no_validation'); /** * Shipper Address */ $this->setShipperNumber("222006"); $this->setShipperName("MyValue365"); $this->setShipperCity("Chicago"); $this->setShipperCountryCode("US"); $this->setShipperStateProvinceCode("IL"); $this->setShipperPostalCode("60610"); $this->setShipperAddressLine("1400 N Lakeshore Drive"); //small medium large $this->setDimensionsUnit("inches"); $this->setDimensionsUnitCode("IN"); $this->setServiceCode("03"); $this->setServiceDesciption("UPS Ground"); $this->setUnit("pounds"); $this->setUnitCode("Lbs"); $this->setPackagingCode("02"); $this->setPackagingDescription("Package"); } public function getRates() { try { $this->ValidateRequest(); if ($this->getCarrier() === 'UPS') { $jsonData = $this->BuildRateRequest(); $header = array( 'Content-type: application/json', 'Content-Length: ' . strlen($jsonData) ); $carrierResponse = $this->CurlRquest($this::EndPointURL, $jsonData, $header); $carrierResponse_array = (json_decode($carrierResponse, true)); $status = false; if (isset($carrierResponse_array['RateResponse']['Response']['ResponseStatus']['Description']) && $carrierResponse_array['RateResponse']['Response']['ResponseStatus']['Description'] == 'Success') $status = true; echo json_encode(Array( 'Status' => array( "result" => $status, "message" => '', "CarrierResponse" => json_decode($carrierResponse) ) )); } } catch (Exception $ex) { $this->setError($ex->getMessage()); } } public function getShippingLabel() { try { $this->ValidateRequest(); if ($this->getCarrier() === 'UPS') { $jsonData = $this->BuildLabelRequest(); //echo $jsonData ; // exit; $header = array( 'AccessLicenseNumber: ED58E56438B88ECC', 'Password: hPawha365$', 'transId: Transaction123', 'transactionSrc: GG', 'Username: MyValue365', 'Content-type: application/json', 'Content-Length: ' . strlen($jsonData) ); $carrierResponse = $this->CurlRquest($this::EndPointShippingURL, $jsonData, $header); $carrierResponse_array = (json_decode($carrierResponse, true)); $status = false; if (isset($carrierResponse_array['ShipmentResponse']['Response']['ResponseStatus']['Description']) && $carrierResponse_array['ShipmentResponse']['Response']['ResponseStatus']['Description'] == 'Success') $status = true; return json_encode(Array( 'Status' => array( "result" => $status, "message" => '', "CarrierResponse" => json_decode($carrierResponse) ) )); } } catch (Exception $ex) { $this->setError($ex->getMessage()); } } public function getTrackingDetail() { // echo 'Start'; try { $bodyContent = array( "Security" => array( "UsernameToken" => array( "Username" => $this::UserID, "Password" => $this::Password ), "UPSServiceAccessToken" => array( "AccessLicenseNumber" => $this::AccessLicenseNumber ) ), "TrackRequest" => array( "Request" => array( "RequestOption" => 1, "TransactionReference" => array( "CustomerContext" => "Test 002" ) ), "InquiryNumber" => $this->getTrackingNumber() ) ); $params = json_encode($bodyContent); $headers = array(); $headers[] = 'Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept'; $headers[] = 'Access-Control-Allow-Methods: POST'; $headers[] = 'Access-Control-Allow-Origin: *'; $headers[] = 'Content-Type: application/json'; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_TIMEOUT, 45); curl_setopt($ch, CURLOPT_URL, self::EndPointTracking); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); $response = curl_exec($ch); return $response; } catch (Exception $ex) { //echo $ex->getMessage(); $this->setError($ex->getMessage()); } } } class Courrier { /*********** Variables ************************/ const Error_101 = 'Invalid or empty Ship To Name'; const Error_102 = 'Invalid or empty Ship To Phone'; const Error_103 = 'Invalid or empty Ship To Company Name'; const Error_104 = 'Invalid or empty Ship To Address line'; const Error_105 = 'Invalid or empty Ship To City'; const Error_106 = 'Invalid or empty Ship To State'; const Error_107 = 'Invalid or empty Ship To Postal Code'; const Error_108 = 'Invalid or empty Ship From Name'; const Error_109 = 'Invalid or empty Ship From Phone'; const Error_110 = 'Invalid or empty Ship From Company Name'; const Error_111 = 'Invalid or empty Ship From Address line'; const Error_112 = 'Invalid or empty Ship From City'; const Error_113 = 'Invalid or empty Ship From State'; const Error_114 = 'Invalid or empty Ship From Postal Code'; const Error_115 = 'Invalid or empty Weight'; const Error_116 = 'Invalid or empty Carrier'; const Error_117 = 'Request is not well formated'; const Error_118 = 'Method Not Allowed'; const Error_119 = 'Error in Request'; const Error_120 = 'Validate Address is not valid'; private $Error = ''; private $is_Error = false; private $Validate_Address = ""; private $Ship_To_Name = ""; private $Ship_To_Phone = ""; private $Ship_To_Company_Name = ""; private $Ship_To_Address_Line1 = ""; private $Ship_To_Address_Line2 = ""; private $Ship_To_City_Locality = ""; private $Ship_To_State_Province = ""; private $Ship_To_Postal_Code = ""; private $Ship_To_Country_Code = ""; private $Ship_From_Name = ""; private $Ship_From_Phone = ""; private $Ship_From_Company_Name = ""; private $Ship_From_Address_Line1 = ""; private $Ship_From_Address_Line2 = ""; private $Ship_From_City_Locality = ""; private $Ship_From_State_Province = ""; private $Ship_From_Postal_Code = ""; private $Ship_From_Country_Code = ""; private $Ship_From__Tax_Identification_Number = ""; private $Weight = ""; private $Unit = ""; private $DimensionsUnit = ""; private $Dimensions_Length = ""; private $Dimensions_Width = ""; private $Dimensions_Height = ""; private $Carrier = ""; private $Service_Code = ""; private $Service_Desciption = ""; private $ShipperNumber = ""; private $Shipper_AddressLine = ""; private $Shipper_City = ""; private $Shipper_StateProvinceCode = ""; private $Shipper_PostalCode = ""; private $Shipper_CountryCode = ""; /** * @var string */ private $Shipper_Name = ""; private $Request_Option = ""; private $Pickup_Type_Code = ""; private $Pickup_Type_Description = ""; private $Customer_Classification_Code = ""; private $Customer_Classification_Description = ""; private $Dimensions_Unit_Code = ""; private $Unit_Code = ""; private $Packaging_Code = ""; private $Packaging_Description = ""; private $Transaction_Reference = ""; private $Box_Type = ""; private $Shipper_Attention_Name = ""; private $Shipper_Tax_Identification_Number = ""; private $Shipper_Phone_Number = ""; private $Shipper_Fax_Number = ""; private $trackingNumber=""; /** * @return string */ public function getShipFromTaxIdentificationNumber() { return $this->Ship_From__Tax_Identification_Number; } /*********** Variables ************************/ /** * @return string */ public function getTrackingNumber() { return $this->trackingNumber; } /** * @param string $trackingNumber */ public function setTrackingNumber($trackingNumber) { $this->trackingNumber = $trackingNumber; } /** * @param string $Ship_From__Tax_Identification_Number */ public function setShipFromTaxIdentificationNumber($Ship_From__Tax_Identification_Number) { $this->Ship_From__Tax_Identification_Number = $Ship_From__Tax_Identification_Number; } /** * @return string */ public function getShipperFaxNumber() { return $this->Shipper_Fax_Number; } /** * @param string $Shipper_Fax_Number */ public function setShipperFaxNumber($Shipper_Fax_Number) { $this->Shipper_Fax_Number = $Shipper_Fax_Number; } /** * @return string */ public function getBoxType() { return $this->Box_Type; } /** * @param string $Box_Type */ public function setBoxType($Box_Type) { $this->Box_Type = $Box_Type; if ($Box_Type == "Small") { $this->setDimensionsHeight("10"); $this->setDimensionsLength("10"); $this->setDimensionsWidth("12"); } if ($Box_Type == "Medium") { $this->setDimensionsHeight("16"); $this->setDimensionsLength("18"); $this->setDimensionsWidth("18"); } if ($Box_Type == "Large") { $this->setDimensionsHeight("24"); $this->setDimensionsLength("18"); $this->setDimensionsWidth("18"); } } /** * @param string $Dimensions_Height */ private function setDimensionsHeight($Dimensions_Height) { $this->Dimensions_Height = $Dimensions_Height; } /** * @param string $Dimensions_Length */ private function setDimensionsLength($Dimensions_Length) { $this->Dimensions_Length = $Dimensions_Length; } /** * @param string $Dimensions_Width */ private function setDimensionsWidth($Dimensions_Width) { $this->Dimensions_Width = $Dimensions_Width; } /** * @return string */ public function getPickupTypeCode() { return $this->Pickup_Type_Code; } /** * @param string $Pickup_Type_Code */ public function setPickupTypeCode($Pickup_Type_Code) { $this->Pickup_Type_Code = $Pickup_Type_Code; } /** * @return string */ public function getPickupTypeDescription() { return $this->Pickup_Type_Description; } /** * @param string $Pickup_Type_Description */ public function setPickupTypeDescription($Pickup_Type_Description) { $this->Pickup_Type_Description = $Pickup_Type_Description; } /** * @return string */ public function getCustomerClassificationCode() { return $this->Customer_Classification_Code; } /** * @param string $Customer_Classification_Code */ public function setCustomerClassificationCode($Customer_Classification_Code) { $this->Customer_Classification_Code = $Customer_Classification_Code; } /** * @return string */ public function getCustomerClassificationDescription() { return $this->Customer_Classification_Description; } /** * @param string $Customer_Classification_Description */ public function setCustomerClassificationDescription($Customer_Classification_Description) { $this->Customer_Classification_Description = $Customer_Classification_Description; } /** * @return string */ public function getError() { return $this->Error; } /** * @param string $Error */ public function setError($Error) { $this->is_Error = true; $this->Error = json_encode(Array( 'Status' => array( "result" => false, "message" => $Error ) )); } /** * @return string */ public function getShipToAddressLine2() { return $this->Ship_To_Address_Line2; } /** * @param string $Ship_To_Address_Line2 */ public function setShipToAddressLine2($Ship_To_Address_Line2) { $this->Ship_To_Address_Line2 = $Ship_To_Address_Line2; } /** * @return string */ public function getShipFromAddressLine2() { return $this->Ship_From_Address_Line2; } /** * @param string $Ship_From_Address_Line2 */ public function setShipFromAddressLine2($Ship_From_Address_Line2) { $this->Ship_From_Address_Line2 = $Ship_From_Address_Line2; } public function ValidateRequest() { if ($this->getValidateAddress() === "" || ($this->getValidateAddress() !== "no_validation" && $this->getValidateAddress() !== "validate_only" && $this->getValidateAddress() !== "validate_and_clean")) { // $this->setError(self::Error_120); throw new Exception(self::Error_120); } elseif ($this->getShipToName() === "") { //$this->setError(self::Error_101); throw new Exception(self::Error_101); } /*elseif ($this->getShipToPhone() === "") { $this->setError(self::Error_102); } elseif ($this->getShipToCompanyName() === "") { $this->setError(self::Error_103); } */ elseif ($this->getShipToAddressLine1() === "") { // $this->setError(self::Error_104); throw new Exception(self::Error_104); } elseif ($this->getShipToCityLocality() === "") { throw new Exception(self::Error_105); //$this->setError(self::Error_105); } elseif ($this->getShipToStateProvince() === "") { //$this->setError(self::Error_106); throw new Exception(self::Error_106); } elseif ($this->getShipToPostalCode() === "") { //$this->setError(self::Error_107); throw new Exception(self::Error_107); } elseif ($this->getShipFromName() === "") { //$this->setError(self::Error_108); throw new Exception(self::Error_108); } /*elseif ($this->getShipFromPhone() === "") { $this->setError(self::Error_109); } elseif ($this->getShipFromCompanyName() === "") { $this->setError(self::Error_110); }*/ elseif ($this->getShipFromAddressLine1() === "") { //$this->setError(self::Error_111); throw new Exception(self::Error_111); } elseif ($this->getShipFromCityLocality() === "") { //$this->setError(self::Error_112); throw new Exception(self::Error_112); } elseif ($this->getShipFromStateProvince() === "") { //$this->setError(self::Error_113); throw new Exception(self::Error_113); } elseif ($this->getShipFromPostalCode() === "") { //$this->setError(self::Error_114); throw new Exception(self::Error_114); } elseif ($this->getWeight() === "") { //$this->setError(self::Error_115); throw new Exception(self::Error_115); } elseif ($this->getCarrier() === "") { //$this->setError(self::Error_116); throw new Exception(self::Error_116); } } /** * @return string */ public function getValidateAddress() { return $this->Validate_Address; } /** * @param string $Validate_Address */ public function setValidateAddress($Validate_Address) { $this->Validate_Address = $Validate_Address; } /** * @return string */ public function getShipToName() { return $this->Ship_To_Name; } /** * @param string $Ship_To_Name */ public function setShipToName($Ship_To_Name) { $this->Ship_To_Name = $Ship_To_Name; } /** * @return string */ public function getShipToAddressLine1() { return $this->Ship_To_Address_Line1; } /** * @param string $Ship_To_Address_Line1 */ public function setShipToAddressLine1($Ship_To_Address_Line1) { $this->Ship_To_Address_Line1 = $Ship_To_Address_Line1; } /** * @return string */ public function getShipToCityLocality() { return $this->Ship_To_City_Locality; } /** * @param string $Ship_To_City_Locality */ public function setShipToCityLocality($Ship_To_City_Locality) { $this->Ship_To_City_Locality = $Ship_To_City_Locality; } /** * @return string */ public function getShipToStateProvince() { return $this->Ship_To_State_Province; } /** * @param string $Ship_To_State_Province */ public function setShipToStateProvince($Ship_To_State_Province) { $this->Ship_To_State_Province = $Ship_To_State_Province; } /** * @return string */ public function getShipToPostalCode() { return $this->Ship_To_Postal_Code; } /** * @param string $Ship_To_Postal_Code */ public function setShipToPostalCode($Ship_To_Postal_Code) { $this->Ship_To_Postal_Code = $Ship_To_Postal_Code; } /** * @return string */ public function getShipFromName() { return $this->Ship_From_Name; } /** * @param string $Ship_From_Name */ public function setShipFromName($Ship_From_Name) { $this->Ship_From_Name = $Ship_From_Name; } /** * @return string */ public function getShipFromAddressLine1() { return $this->Ship_From_Address_Line1; } /** * @param string $Ship_From_Address_Line1 */ public function setShipFromAddressLine1($Ship_From_Address_Line1) { $this->Ship_From_Address_Line1 = $Ship_From_Address_Line1; } /** * @return string */ public function getShipFromCityLocality() { return $this->Ship_From_City_Locality; } /** * @param string $Ship_From_City_Locality */ public function setShipFromCityLocality($Ship_From_City_Locality) { $this->Ship_From_City_Locality = $Ship_From_City_Locality; } /** * @return string */ public function getShipFromStateProvince() { return $this->Ship_From_State_Province; } /** * @param string $Ship_From_State_Province */ public function setShipFromStateProvince($Ship_From_State_Province) { $this->Ship_From_State_Province = $Ship_From_State_Province; } /** * @return string */ public function getShipFromPostalCode() { return $this->Ship_From_Postal_Code; } /** * @param string $Ship_From_Postal_Code */ public function setShipFromPostalCode($Ship_From_Postal_Code) { $this->Ship_From_Postal_Code = $Ship_From_Postal_Code; } /** * @return string */ public function getWeight() { return $this->Weight; } /** * @param string $Weight */ public function setWeight($Weight) { $this->Weight = $Weight; } /** * @return string */ public function getCarrier() { return $this->Carrier; } /** * @param string $Carrier */ public function setCarrier($Carrier) { $this->Carrier = $Carrier; } public function BuildLabelRequest() { //create soap request $Shipper['Name'] = $this->getShipperName(); $Shipper['AttentionName'] = $this->getShipperAttentionName(); $Shipper['TaxIdentificationNumber'] = $this->getShipper_Tax_Identification_Number(); $Shipper['Phone'] = array('Number' => $this->getShipperPhoneNumber()); $Shipper['ShipperNumber'] = $this->getShipperNumber(); $Address['AddressLine'] = $this->getShipperAddressLine(); $Address['City'] = $this->getShipperCity(); $Address['StateProvinceCode'] = $this->getShipperStateProvinceCode(); $Address['PostalCode'] = $this->getShipperPostalCode(); $Address['CountryCode'] = $this->getShipperCountryCode(); $Shipper['Address'] = $Address; $Shipment['Description'] = 'MyValue365 Grocery'; $Shipment['Shipper'] = $Shipper; $ShipTo['Name'] = $this->getShipToName(); $ShipTo['Phone'] = array('Number' => $this->getShipToPhone()); $AddressTo['AddressLine'] = $this->getShipToAddressLine1(); $AddressTo['City'] = $this->getShipToCityLocality(); $AddressTo['StateProvinceCode'] = $this->getShipToStateProvince(); $AddressTo['PostalCode'] = $this->getShipToPostalCode(); $AddressTo['CountryCode'] = $this->getShipToCountryCode(); $AddressTo['ResidentialAddressIndicator'] = ''; $ShipTo['Address'] = $AddressTo; $Shipment['ShipTo'] = $ShipTo; $ShipFrom['Name'] = $this->getShipFromName(); $ShipFrom['TaxIdentificationNumber'] = $this->getShipper_Tax_Identification_Number(); $ShipFrom['Phone'] = array('Number' => $this->getShipFromPhone()); $AddressFrom['AddressLine'] = $this->getShipFromAddressLine1(); $AddressFrom['City'] = $this->getShipFromCityLocality(); $AddressFrom['StateProvinceCode'] = $this->getShipFromStateProvince(); $AddressFrom['PostalCode'] = $this->getShipFromPostalCode(); $AddressFrom['CountryCode'] = $this->getShipFromCountryCode(); $ShipFrom['Address'] = $AddressFrom; $Shipment['ShipFrom'] = $ShipFrom; $Shipment['PaymentInformation'] = array('ShipmentCharge' => array('Type' => '01', 'BillShipper' => array('AccountNumber' => $this->getShipperNumber()))); $service['Code'] = $this->getServiceCode(); $service['Description'] = $this->getServiceDesciption(); $Shipment['Service'] = $service; $packaging1['Code'] = $this->getPackagingCode(); //$packaging1['Description'] = $this->getPackagingDescription(); $package1['Packaging'] = $packaging1; $dunit1['Code'] = $this->getDimensionsUnitCode(); $dunit1['Description'] = $this->getDimensionsUnit(); $dimensions1['UnitOfMeasurement'] = $dunit1; $dimensions1['Length'] = $this->getDimensionsLength(); $dimensions1['Width'] = $this->getDimensionsWidth(); $dimensions1['Height'] = $this->getDimensionsHeight(); //$package1['Dimensions'] = $dimensions1; $punit1['Code'] = $this->getUnitCode(); //$punit1['Description'] = $this->getUnit(); $packageweight1['Weight'] = $this->getWeight(); $packageweight1['UnitOfMeasurement'] = $punit1; $package1['PackageWeight'] = $packageweight1; $Shipment['Package'] = array($package1); $Shipment['ShipmentServiceOptions'] = ''; $Shipment['LargePackageIndicator'] = ''; $Request['Shipment'] = $Shipment; $Request['LabelSpecification'] = array('LabelImageFormat' => array('Code' => 'GIF')); $RateRequest["ShipmentRequest"] = $Request; //echo "Request.......\n"; //print_r(json_encode($RateRequest)); //echo "\n\n"; return json_encode($RateRequest); } /** * @return string */ public function getShipperName() { return $this->Shipper_Name; } /** * @param string $Shipper_Name */ public function setShipperName($Shipper_Name) { $this->Shipper_Name = $Shipper_Name; } /** * @return string */ public function getShipperAttentionName() { return $this->Shipper_Attention_Name; } /** * @param string $Shipper_Attention_Name */ public function setShipperAttentionName($Shipper_Attention_Name) { $this->Shipper_Attention_Name = $Shipper_Attention_Name; } /** * @return string */ public function getShipper_Tax_Identification_Number() { return $this->Shipper_Tax_Identification_Number; } /** * @param string $Shipper_Tax_Identification_Number */ public function setShipper_Tax_Identification_Number($Shipper_Tax_Identification_Number) { $this->Shipper_Tax_Identification_Number = $Shipper_Tax_Identification_Number; } /** * @return string */ public function getShipperPhoneNumber() { return $this->Shipper_Phone_Number; } /** * @param string $Shipper_Phone_Number */ public function setShipperPhoneNumber($Shipper_Phone_Number) { $this->Shipper_Phone_Number = $Shipper_Phone_Number; } /** * @return string */ public function getShipperNumber() { return $this->ShipperNumber; } /** * @param string $ShipperNumber */ public function setShipperNumber($ShipperNumber) { $this->ShipperNumber = $ShipperNumber; } /** * @return string */ public function getShipperAddressLine() { return $this->Shipper_AddressLine; } /** * @param string $Shipper_AddressLine */ public function setShipperAddressLine($Shipper_AddressLine) { $this->Shipper_AddressLine = $Shipper_AddressLine; } /** * @return string */ public function getShipperCity() { return $this->Shipper_City; } /** * @param string $Shipper_City */ public function setShipperCity($Shipper_City) { $this->Shipper_City = $Shipper_City; } /** * @return string */ public function getShipperStateProvinceCode() { return $this->Shipper_StateProvinceCode; } /** * @param string $Shipper_StateProvinceCode */ public function setShipperStateProvinceCode($Shipper_StateProvinceCode) { $this->Shipper_StateProvinceCode = $Shipper_StateProvinceCode; } /** * @return string */ public function getShipperPostalCode() { return $this->Shipper_PostalCode; } /** * @param string $Shipper_PostalCode */ public function setShipperPostalCode($Shipper_PostalCode) { $this->Shipper_PostalCode = $Shipper_PostalCode; } /** * @return string */ public function getShipperCountryCode() { return $this->Shipper_CountryCode; } /** * @param string $Shipper_CountryCode */ public function setShipperCountryCode($Shipper_CountryCode) { $this->Shipper_CountryCode = $Shipper_CountryCode; } /** * @return string */ public function getShipToPhone() { return $this->Ship_To_Phone; } /** * @param string $Ship_To_Phone */ public function setShipToPhone($Ship_To_Phone) { $this->Ship_To_Phone = $Ship_To_Phone; } /** * @return string */ public function getShipToCountryCode() { return $this->Ship_To_Country_Code; } /** * @param string $Ship_To_Country_Code */ public function setShipToCountryCode($Ship_To_Country_Code) { $this->Ship_To_Country_Code = $Ship_To_Country_Code; } /** * @return string */ public function getShipFromPhone() { return $this->Ship_From_Phone; } /** * @param string $Ship_From_Phone */ public function setShipFromPhone($Ship_From_Phone) { $this->Ship_From_Phone = $Ship_From_Phone; } /** * @return string */ public function getShipFromCountryCode() { return $this->Ship_From_Country_Code; } /** * @param string $Ship_From_Country_Code */ public function setShipFromCountryCode($Ship_From_Country_Code) { $this->Ship_From_Country_Code = $Ship_From_Country_Code; } /** * @return string */ public function getServiceCode() { return $this->Service_Code; } /** * @param string $Service_Code */ public function setServiceCode($Service_Code) { $this->Service_Code = $Service_Code; } /** * @return string */ public function getServiceDesciption() { return $this->Service_Desciption; } /** * @param string $Service_Desciption */ public function setServiceDesciption($Service_Desciption) { $this->Service_Desciption = $Service_Desciption; } /** * @return string */ public function getPackagingCode() { return $this->Packaging_Code; } /** * @param string $Packaging_Code */ public function setPackagingCode($Packaging_Code) { $this->Packaging_Code = $Packaging_Code; } /** * @return string */ public function getDimensionsUnitCode() { return $this->Dimensions_Unit_Code; } /** * @param string $Dimensions_Unit_Code */ public function setDimensionsUnitCode($Dimensions_Unit_Code) { $this->Dimensions_Unit_Code = $Dimensions_Unit_Code; } /** * @return string */ public function getDimensionsUnit() { return $this->DimensionsUnit; } /** * @param string $DimensionsUnit */ public function setDimensionsUnit($DimensionsUnit) { $this->DimensionsUnit = $DimensionsUnit; } /** * @return string */ public function getDimensionsLength() { return $this->Dimensions_Length; } /** * @return string */ public function getDimensionsWidth() { return $this->Dimensions_Width; } /** * @return string */ public function getDimensionsHeight() { return $this->Dimensions_Height; } /** * @return string */ public function getUnitCode() { return $this->Unit_Code; } /** * @param string $Unit_Code */ public function setUnitCode($Unit_Code) { $this->Unit_Code = $Unit_Code; } public function BuildRateRequest() { //create soap request $UsernameToken['Username'] = $this::UserID; $UsernameToken['Password'] = $this::Password; $ServiceAccessToken['AccessLicenseNumber'] = $this::AccessLicenseNumber; $UPSSecurity['UsernameToken'] = $UsernameToken; $UPSSecurity['ServiceAccessToken'] = $ServiceAccessToken; $Option['RequestOption'] = $this->getRequestOption(); $TransactionReference['CustomerContext'] = $this->getTransactionReference(); $Option['TransactionReference'] = $TransactionReference; $Request['Request'] = $Option; // $PickupType['Code'] = $this->getPickupTypeCode(); // $PickupType['Description'] = $this->getPickupTypeDescription(); // $Request['PickupType'] = $PickupType; //$CustomerClassification['Code'] = $this->getCustomerClassificationCode(); //$CustomerClassification['Description'] = $this->getCustomerClassificationDescription(); //$Request['CustomerClassification'] = $CustomerClassification; $Shipper['Name'] = $this->getShipperName(); $Shipper['ShipperNumber'] = $this->getShipperNumber(); $Address['AddressLine'] = array($this->getShipperAddressLine()); $Address['City'] = $this->getShipperCity(); $Address['StateProvinceCode'] = $this->getShipperStateProvinceCode(); $Address['PostalCode'] = $this->getShipperPostalCode(); $Address['CountryCode'] = $this->getShipperCountryCode(); $Shipper['Address'] = $Address; $Shipment['Shipper'] = $Shipper; $ShipFrom['Name'] = $this->getShipFromName(); $AddressFrom['AddressLine'] = array($this->getShipFromAddressLine1()); $AddressFrom['City'] = $this->getShipFromCityLocality(); $AddressFrom['StateProvinceCode'] = $this->getShipFromStateProvince(); $AddressFrom['PostalCode'] = $this->getShipFromPostalCode(); $AddressFrom['CountryCode'] = $this->getShipFromCountryCode(); $ShipFrom['Address'] = $AddressFrom; $Shipment['ShipFrom'] = $ShipFrom; $ShipTo['Name'] = $this->getShipToName(); $AddressTo['AddressLine'] = array($this->getShipToAddressLine1()); $AddressTo['City'] = $this->getShipToCityLocality(); $AddressTo['StateProvinceCode'] = $this->getShipToStateProvince(); $AddressTo['PostalCode'] = $this->getShipToPostalCode(); $AddressTo['CountryCode'] = $this->getShipToCountryCode(); $AddressTo['ResidentialAddressIndicator'] = ''; $ShipTo['Address'] = $AddressTo; $Shipment['ShipTo'] = $ShipTo; $service['Code'] = $this->getServiceCode(); $service['Description'] = $this->getServiceDesciption(); $Shipment['Service'] = $service; $packaging1['Code'] = $this->getPackagingCode(); $packaging1['Description'] = $this->getPackagingDescription(); $package1['PackagingType'] = $packaging1; $dunit1['Code'] = $this->getDimensionsUnitCode(); $dunit1['Description'] = $this->getDimensionsUnit(); $dimensions1['UnitOfMeasurement'] = $dunit1; $dimensions1['Length'] = $this->getDimensionsLength(); $dimensions1['Width'] = $this->getDimensionsWidth(); $dimensions1['Height'] = $this->getDimensionsHeight(); $package1['Dimensions'] = $dimensions1; $punit1['Code'] = $this->getUnitCode(); $punit1['Description'] = $this->getUnit(); $packageweight1['Weight'] = $this->getWeight(); $packageweight1['UnitOfMeasurement'] = $punit1; $package1['PackageWeight'] = $packageweight1; $Shipment['Package'] = array($package1); $Shipment['ShipmentServiceOptions'] = ''; $Shipment['LargePackageIndicator'] = ''; $Request['Shipment'] = $Shipment; $RateRequest["UPSSecurity"] = $UPSSecurity; $RateRequest["RateRequest"] = $Request; //echo "Request.......\n"; //print_r(json_encode($RateRequest)); // echo "\n\n"; return json_encode($RateRequest); } /** * @return string */ public function getRequestOption() { return $this->Request_Option; } /** * @param string $Request_Option */ public function setRequestOption($Request_Option) { $this->Request_Option = $Request_Option; } /** * @return string */ public function getTransactionReference() { return $this->Transaction_Reference; } /** * @param string $Transaction_Reference */ public function setTransactionReference($Transaction_Reference) { $this->Transaction_Reference = $Transaction_Reference; } /** * @return string */ public function getPackagingDescription() { return $this->Packaging_Description; } /** * @param string $Packaging_Description */ public function setPackagingDescription($Packaging_Description) { $this->Packaging_Description = $Packaging_Description; } /** * @return string */ public function getUnit() { return $this->Unit; } /** * @param string $Unit */ public function setUnit($Unit) { $this->Unit = $Unit; } public function CurlRquest($urlEndpoint, $jsonData, $header) { $curl_options = array( CURLOPT_URL => $urlEndpoint, CURLOPT_SSL_VERIFYPEER => false, //implemented to perform a TRUST on the server certificate CURLOPT_FRESH_CONNECT => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => $header, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $jsonData ); //print_r($curl_options); $ch = curl_init(); curl_setopt_array($ch, $curl_options); $result = curl_exec($ch); //Log Response or Error if ($result !== false) { // Error; } else { // Error; } //Close the handle curl_close($ch); //echo "<pre>"; //print_r($result); return ($result); } /** * @return string */ public function getShipToCompanyName() { return $this->Ship_To_Company_Name; } /** * @param string $Ship_To_Company_Name */ public function setShipToCompanyName($Ship_To_Company_Name) { $this->Ship_To_Company_Name = $Ship_To_Company_Name; } /** * @return string */ public function getShipFromCompanyName() { return $this->Ship_From_Company_Name; } /** * @param string $Ship_From_Company_Name */ public function setShipFromCompanyName($Ship_From_Company_Name) { $this->Ship_From_Company_Name = $Ship_From_Company_Name; } /** * @return bool */ public function isError() { return $this->is_Error; } } ?> Save