コード例 #1
0
ファイル: UpsShipping.php プロジェクト: saiber/www
 public function getRate($service)
 {
     include_once dirname(__FILE__) . '/../library/ups/upsRate.php';
     $weight = $this->weight * 1000;
     $pounds = round($weight / 453.59237, 3);
     $ups = new upsRate();
     $ups->setCredentials($this->getConfigValue('accessKey'), $this->getConfigValue('user'), $this->getConfigValue('password'), '');
     return $ups->getRate($this->sourceZip, $this->destZip, substr($service, 3), $pounds, $this->sourceCountry, $this->destCountry);
 }
コード例 #2
0
ファイル: cart_model_wfl.php プロジェクト: Gninety/Microweber
 function ups_ship_confirm($ship_to, $ship_from, $shipment)
 {
     /////////////////////////////////////////////////////////////////////////////////////////////
     ////////////////////////////////| UPS Ship Confirm Function |////////////////////////////////
     /////////////////////////////////////////////////////////////////////////////////////////////
     // NOTE: The XML request docment contains some static values that can be changed for the
     // requirements of your specific application.  Examples include LabelPrintMethod,
     // LabelImageFormat, and LabelStockSize.  Please refer to the UPS Developer's Guide for
     // allowed values for these fields.
     //
     // ALSO: Characters such as "&" "<" ">" """ "'" have to be replaced in regard of the W3C
     // definition of XML.  These characters will break the XML document if they are not replaced.
     /////////////////////////////////////////////////////////////////////////////////////////////
     global $cms_db_tables, $CFG;
     //var_dump($CFG);
     include_once BASEPATH . '/libraries/upsRate.php';
     // UPS will not allow a weight value of anything less than 0lbs
     if ($shipment["weight"] < 1) {
         $shipment["weight"] = 1;
     }
     // define some required values
     $access_license_number = $CFG->ups_xml_access_key;
     $user_id = $CFG->ups_userid;
     $password = $CFG->ups_password;
     $label_height = "4";
     $label_width = "6";
     $shipper_name = $CFG->companyname;
     $shipper_attn_name = "Shipping Department";
     $shipper_phone_dial_plan_number = "123456";
     $shipper_phone_line_number = "7890";
     $shipper_phone_extension = "001";
     $shipper_number = $CFG->ups_shipper_number;
     $shipper_address_1 = $CFG->companystreetaddress1;
     $shipper_address_2 = $CFG->companystreetaddress2;
     $shipper_address_3 = "";
     $shipper_city = $CFG->companycity;
     $shipper_state_province_code = $CFG->companystate;
     $shipper_postal_code = $CFG->companyzipcode;
     $upsRate = new upsRate();
     $upsRate->setCredentials($access_license_number, $user_id, $password, $shipper_number);
     $rate = $upsRate->getRate($shipper_postal_code, $ship_to['postal_code'], $shipment['service_code'], $shipment['length'], $shipment['width'], $shipment['height'], $shipment['weight']);
     //var_dump($rate);
     return number_format($rate, 2);
     /*//$ship_from[state_province_code] = $ship_from['from_zip'];
     		
     		     	<Length>$shipment[length]</Length>
              	<Width>$shipment[width]</Width>
              	<Height>$shipment[height]</Height>
              </Dimensions>
          
              <PackageWeight>
                 <UnitOfMeasurement>
                    <Code>LBS</Code>
                 </UnitOfMeasurement>
                 <Weight>$shipment[weight]</Weight>
                 
                 
                 
     		$shipper_country_code = "US";
     		if ($CFG->ups_testmode == "FALSE") {
     			$post_url = "https://www.ups.com/ups.app/xml/ShipConfirm";
     		} else {
     			$post_url = "https://wwwcie.ups.com/ups.app/xml/ShipConfirm";
     		}
     		
     		// construct the xml query document
     		$xml_request = "<?xml version=\"1.0\"?>
     <AccessRequest xml:lang=\"en-US\">
     	<AccessLicenseNumber>
     		$access_license_number
     	</AccessLicenseNumber>
     	<UserId>
     		$user_id
     	</UserId>
     	<Password>
     		$password
     	</Password>
     </AccessRequest>
     <?xml version=\"1.0\"?>
     <ShipmentConfirmRequest xml:lang=\"en-US\">
        <Request>
           <TransactionReference>
              <CustomerContext>ShipConfirmUS</CustomerContext>
              <XpciVersion>1.0001</XpciVersion>
           </TransactionReference>
           <RequestAction>ShipConfirm</RequestAction>
           <RequestOption>nonvalidate</RequestOption>
        </Request>
        <LabelSpecification>
           <LabelPrintMethod>
              <Code>EPL</Code>
           </LabelPrintMethod>
           <LabelImageFormat>
           	<Code>EPL</Code>
           </LabelImageFormat>
           <LabelStockSize>
           	<Height>4</Height>
           	<Width>6</Width>
           </LabelStockSize>
        </LabelSpecification>
        <Shipment>
           <Shipper>
              <Name>$shipper_name</Name>
              <AttentionName>$shipper_attn_name</AttentionName>
              <PhoneNumber>
                 <StructuredPhoneNumber>
                    <PhoneDialPlanNumber>$shipper_phone_dial_plan_number</PhoneDialPlanNumber>
                    <PhoneLineNumber>$shipper_phone_line_number</PhoneLineNumber>
                    <PhoneExtension>$shipper_phone_extension</PhoneExtension>
                 </StructuredPhoneNumber>
              </PhoneNumber>
              <ShipperNumber>$shipper_number</ShipperNumber>
              <Address>
                 <AddressLine1>$shipper_address_1</AddressLine1>
                 <AddressLine2>$shipper_address_2</AddressLine2>
                 <AddressLine3>$shipper_address_3</AddressLine3>
                 <City>$shipper_city</City>
                 <StateProvinceCode>$shipper_state_province_code</StateProvinceCode>
                 <PostalCode>$shipper_postal_code</PostalCode>
                 <CountryCode>$shipper_country_code</CountryCode>
              </Address>
           </Shipper>
           <ShipTo>
              <CompanyName>$ship_to[company_name]</CompanyName>
              <AttentionName>$ship_to[attn_name]</AttentionName>
              <PhoneNumber>
                 <StructuredPhoneNumber>
                    <PhoneDialPlanNumber>$ship_to[phone_dial_plan_number]</PhoneDialPlanNumber>
                    <PhoneLineNumber>$ship_to[phone_line_number]</PhoneLineNumber>
                    <PhoneExtension>$ship_to[phone_extension]</PhoneExtension>
                 </StructuredPhoneNumber>
              </PhoneNumber>
              <Address>
                 <AddressLine1>$ship_to[address_1]</AddressLine1>
                 <AddressLine2>$ship_to[address_2]</AddressLine2>
                 <AddressLine3>$ship_to[address_3]</AddressLine3>
                 <City>$ship_to[city]</City>
                 <StateProvinceCode>$ship_to[state_province_code]</StateProvinceCode>
                 <PostalCode>$ship_to[postal_code]</PostalCode>
                 <CountryCode>$ship_to[country_code]</CountryCode>
                 <ResidentialAddress/>
              </Address>
           </ShipTo>
           <ShipFrom>
              <CompanyName>$ship_from[company_name]</CompanyName>
              <AttentionName>$ship_from[attn_name]</AttentionName>
              <PhoneNumber>
                 <StructuredPhoneNumber>
                    <PhoneDialPlanNumber>$ship_from[phone_dial_plan_number]</PhoneDialPlanNumber>
                    <PhoneLineNumber>$ship_from[phone_line_number]</PhoneLineNumber>
                    <PhoneExtension>$ship_from[phone_extension]</PhoneExtension>
                 </StructuredPhoneNumber>
              </PhoneNumber>
              <Address>
                 <AddressLine1>$ship_from[address_1]</AddressLine1>
                 <AddressLine2>$ship_from[address_2]</AddressLine2>
                 <AddressLine3>$ship_from[address_3]</AddressLine3>
                 <City>$ship_from[city]</City>
                 <StateProvinceCode>$ship_from[state_province_code]</StateProvinceCode>
                 <PostalCode>$ship_from[postal_code]</PostalCode>
                 <CountryCode>$ship_from[country_code]</CountryCode>
              </Address>
           </ShipFrom>
           <PaymentInformation>
              <Prepaid>
                 <BillShipper>
                    <AccountNumber>$shipment[bill_shipper_account_number]</AccountNumber>
                 </BillShipper>
              </Prepaid>
           </PaymentInformation>
           <Service>
              <Code>$shipment[service_code]</Code>
           </Service>
           <Package>
              <PackagingType>
                 <Code>$shipment[packaging_type]</Code>
              </PackagingType>
              <Dimensions>
              	<UnitOfMeasurement>
              		<Code>IN</Code>
              	</UnitOfMeasurement>
              	<Length>$shipment[length]</Length>
              	<Width>$shipment[width]</Width>
              	<Height>$shipment[height]</Height>
              </Dimensions>
          
              <PackageWeight>
                 <UnitOfMeasurement>
                    <Code>LBS</Code>
                 </UnitOfMeasurement>
                 <Weight>$shipment[weight]</Weight>
              </PackageWeight>
       
           </Package>
        </Shipment>
     </ShipmentConfirmRequest>";
     		
     		//		p($xml_request);die;
     		
     
     		// execute the curl function and return the result document to $result
     		$ch = curl_init ();
     		curl_setopt ( $ch, CURLOPT_URL, $post_url );
     		curl_setopt ( $ch, CURLOPT_HEADER, 0 );
     		curl_setopt ( $ch, CURLOPT_POST, 1 );
     		curl_setopt ( $ch, CURLOPT_POSTFIELDS, "$xml_request" );
     		curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
     		$xml_result = curl_exec ( $ch );
     		curl_close ( $ch );
     		
     		$data = $this->parse_xml ( $xml_result );
     		
     		$result = array ();
     		if ($data ["ShipmentConfirmResponse"] ["#"] ["Response"] [0] ["#"] ["ResponseStatusCode"] [0] ["#"] == 1) {
     			$result ["total_charges"] = $data ["ShipmentConfirmResponse"] ["#"] ["ShipmentCharges"] [0] ["#"] ["TotalCharges"] [0] ["#"] ["MonetaryValue"] [0] ["#"];
     		} else {
     			$result ["error_description"] = $data ["ShipmentConfirmResponse"] ["#"] ["Response"] [0] ["#"] ["Error"] [0] ["#"] ["ErrorDescription"] [0] ["#"];
     		
     		}
     		if (! array_key_exists ( 'error_description', $result )) {
     			//echo number_format($result["total_charges"],2);
     			return number_format ( $result ["total_charges"], 2 );
     		} else {
     			echo "<div style='color:red'>{$result["error_description"]}</div>";
     			exit ();
     		}*/
 }