/**
  * Builds the XML used to make the request
  * 
  * If $customer_context is an array it should be in the format:
  * $customer_context = array('Element' => 'Value');
  * 
  * @access public
  * @param array|string $cutomer_context customer data
  * @return string $return_value request XML
  */
 public function buildRequest($customer_context = null)
 {
     // create the new dom document
     $xml = new DOMDocument('1.0', 'utf-8');
     /** create the AddressValidationRequest element **/
     $rate = $xml->appendChild(new DOMElement('RatingServiceSelectionRequest'));
     $rate->setAttributeNode(new DOMAttr('xml:lang', 'en-US'));
     // create the child elements
     $requst = $this->buildRequest_RequestElement($rate, 'Rate', 'Rate', $customer_context);
     /** build the pickup type node **/
     $pickup_type = $rate->appendChild(new DOMElement('PickupType'));
     $pickup_type->appendChild(new DOMElement('Code', $this->shipment['pickup_type']['code']));
     $pickup_type->appendChild(new DOMElement('Description', $this->shipment['pickup_type']['description']));
     $shipment = $rate->appendChild(new DOMElement('Shipment'));
     $this->buildRequest_Shipper($shipment);
     $this->buildRequest_Destination($shipment);
     $this->buildRequest_ShipFrom($shipment);
     $shipment = $this->buildRequest_Shipment($shipment);
     return parent::buildRequest() . $xml->saveXML();
 }
 /**
  * Builds the XML used to make the request
  * 
  * If $customer_context is an array it should be in the format:
  * $customer_context = array('Element' => 'Value');
  * 
  * @access public
  * @param array|string $cutomer_context customer data
  * @return string $return_value request XML
  */
 public function buildRequest($customer_context = null)
 {
     /** create DOMDocument objects **/
     $address_dom = new DOMDocument('1.0');
     /** create the AddressValidationRequest element **/
     $address_element = $address_dom->appendChild(new DOMElement('AddressValidationRequest'));
     $address_element->setAttributeNode(new DOMAttr('xml:lang', 'en-US'));
     // create the child elements
     $request_element = $this->buildRequest_RequestElement($address_element, 'AV', null, $customer_context);
     $address_element = $address_element->appendChild(new DOMElement('Address'));
     /** create the children of the Address Element **/
     // check if a city was entered
     $create = !empty($this->address['city']) ? $address_element->appendChild(new DOMElement('City', $this->address['city'])) : false;
     $create = !empty($this->address['state']) ? $address_element->appendChild(new DOMElement('StateProvinceCode', $this->address['state'])) : false;
     $create = !empty($this->address['zip_code']) ? $address_element->appendChild(new DOMElement('PostalCode', $this->address['zip_code'])) : false;
     unset($create);
     return parent::buildRequest() . $address_dom->saveXML();
 }
Esempio n. 3
0
 /**
  * Builds the XML used to make the request
  * 
  * If $customer_context is an array it should be in the format:
  * $customer_context = array('Element' => 'Value');
  * 
  * @access public
  * @param array|string $cutomer_context customer data
  * @return string $return_value request XML
  */
 public function buildRequest($customer_context = null)
 {
     /** create DOMDocument objects **/
     $transit_dom = new DOMDocument('1.0');
     /** create the TimeInTransitRequest element **/
     $transit_element = $transit_dom->appendChild(new DOMElement('TimeInTransitRequest'));
     $transit_element->setAttributeNode(new DOMAttr('xml:lang', 'en-US'));
     // create the child elements
     $request_element = $this->buildRequest_RequestElement($transit_element, 'TimeInTransit', null, $customer_context);
     $transit_from_element = $transit_element->appendChild(new DOMElement('TransitFrom'));
     $transit_to_element = $transit_element->appendChild(new DOMElement('TransitTo'));
     /** create the children of the TransitFrom Element **/
     // check if a city was entered
     $from_address_element = $transit_from_element->appendChild(new DOMElement('AddressArtifactFormat'));
     $create = !empty($this->origin['name']) ? $from_address_element->appendChild(new DOMElement('Consignee', $this->origin['name'])) : false;
     $create = !empty($this->origin['street_number']) ? $from_address_element->appendChild(new DOMElement('StreetNumberLow', $this->origin['street_number'])) : false;
     $create = !empty($this->origin['street']) ? $from_address_element->appendChild(new DOMElement('StreetName', $this->origin['street'])) : false;
     $create = !empty($this->origin['street_type']) ? $from_address_element->appendChild(new DOMElement('StreetType', $this->origin['street_type'])) : false;
     $create = !empty($this->origin['city']) ? $from_address_element->appendChild(new DOMElement('PoliticalDivision2', $this->origin['city'])) : false;
     $create = !empty($this->origin['state']) ? $from_address_element->appendChild(new DOMElement('PoliticalDivision1', $this->origin['state'])) : false;
     $create = !empty($this->origin['zip_code']) ? $from_address_element->appendChild(new DOMElement('PostcodePrimaryLow', $this->origin['zip_code'])) : false;
     $create = !empty($this->origin['country']) ? $from_address_element->appendChild(new DOMElement('CountryCode', $this->origin['country'])) : false;
     unset($create);
     /** create the children of the TransitTo Element **/
     // check if a city was entered
     $to_address_element = $transit_to_element->appendChild(new DOMElement('AddressArtifactFormat'));
     $create = !empty($this->destination['name']) ? $to_address_element->appendChild(new DOMElement('Consignee', $this->destination['name'])) : false;
     $create = !empty($this->destination['street_number']) ? $to_address_element->appendChild(new DOMElement('StreetNumberLow', $this->destination['street_number'])) : false;
     $create = !empty($this->destination['street']) ? $to_address_element->appendChild(new DOMElement('StreetName', $this->destination['street'])) : false;
     $create = !empty($this->destination['street_type']) ? $to_address_element->appendChild(new DOMElement('StreetType', $this->destination['street_type'])) : false;
     $create = !empty($this->destination['city']) ? $to_address_element->appendChild(new DOMElement('PoliticalDivision2', $this->destination['city'])) : false;
     $create = !empty($this->destination['state']) ? $to_address_element->appendChild(new DOMElement('PoliticalDivision1', $this->destination['state'])) : false;
     $create = !empty($this->destination['zip_code']) ? $to_address_element->appendChild(new DOMElement('PostcodePrimaryLow', $this->destination['zip_code'])) : false;
     $create = !empty($this->destination['country']) ? $to_address_element->appendChild(new DOMElement('CountryCode', $this->destination['country'])) : false;
     unset($create);
     /** create the rest of the child elements **/
     // create the PickupDate element
     $transit_element->appendChild(new DOMElement('PickupDate', $this->data['pickup_date']));
     // create the MaximumListSize element if a value was passd in
     if (!empty($this->data['max_list_size'])) {
         $transit_element->appendChild(new DOMElement('MaximumListSize', $this->data['max_list_size']));
     }
     // end if a maximum list size was set
     // create the InvoiceLineTotal element if a value was passed in
     if (!empty($this->data['invoice'])) {
         $invoice_element = $transit_element->appendChild(new DOMElement('InvoiceLineTotal'));
         // check if a currency code was passed in
         if (!empty($this->data['invoice']['currency_code'])) {
             $invoice_element->appendChild(new DOMElement('CurrencyCode', $this->data['invoice']['currency_code']));
         }
         // end if a currency code was passed in
         // check if a monetary value was passed in
         if (!empty($this->data['invoice']['monetary_value'])) {
             $invoice_element->appendChild(new DOMElement('MonetaryValue', $this->data['invoice']['monetary_value']));
         }
         // end if a monetary value was passed in
     }
     // end if invoice values were set
     // create the ShipmentWeight element if a value was passed in
     if (!empty($this->data['weight'])) {
         $weight_element = $transit_element->appendChild(new DOMElement('ShipmentWeight'));
         // check if unit of measure data was passed in
         if (!empty($this->data['weight']['unit_of_measure'])) {
             $um_element = $weight_element->appendChild(new DOMElement('UnitOfMeasurement'));
         }
         // end if unit of measure was passed in
         // check if a unit of measure code was passed in
         if (!empty($this->data['weight']['unit_of_measure']['code'])) {
             $um_element->appendChild(new DOMElement('Code', $this->data['weight']['unit_of_measure']['code']));
         }
         // end if a unit of measure code was passed in
         // check if a monetary value was passed in
         if (!empty($this->data['weight']['unit_of_measure'])) {
             $um_element->appendChild(new DOMElement('Description', $this->data['weight']['unit_of_measure']['code']));
         }
         // end if a monetary value was passed in
         // check if a monetary value was passed in
         if (!empty($this->data['weight']['weight'])) {
             $weight_element->appendChild(new DOMElement('Weight', $this->data['weight']['weight']));
         }
         // end if a monetary value was passed in
     }
     // end if invoice values were set
     return parent::buildRequest() . $transit_dom->saveXML();
 }
 /**
  * Builds the XML used to make the request
  * 
  * If $customer_context is an array it should be in the format:
  * $customer_context = array('Element' => 'Value');
  * 
  * @access public
  * @param array|string $cutomer_context customer data
  * @return string $return_value request XML
  */
 public function buildRequest($customer_context = null)
 {
     /** create DOMDocument objects **/
     $address_dom = new DOMDocument('1.0');
     /** create the AddressValidationRequest element **/
     $address_element = $address_dom->appendChild(new DOMElement('AddressValidationRequest'));
     $address_element->setAttributeNode(new DOMAttr('xml:lang', 'en-US'));
     // create the child elements
     $request_element = $this->buildRequest_RequestElement($address_element, 'XAV', 3, $customer_context);
     $address_element->appendChild(new DOMElement('MaximumListSize', 3));
     $address_element = $address_element->appendChild(new DOMElement('AddressKeyFormat'));
     $create = !empty($this->address['street']) ? $address_element->appendChild(new DOMElement('AddressLine', $this->address['street'])) : false;
     $create = !empty($this->address['city']) ? $address_element->appendChild(new DOMElement('PoliticalDivision2', $this->address['city'])) : false;
     $create = !empty($this->address['state']) ? $address_element->appendChild(new DOMElement('PoliticalDivision1', $this->address['state'])) : false;
     $create = !empty($this->address['zip_code']) ? $address_element->appendChild(new DOMElement('PostcodePrimaryLow', $this->address['zip_code'])) : false;
     $create = !empty($this->address['zip_code4']) ? $address_element->appendChild(new DOMElement('PostcodeExtendedLow', $this->address['zip_code4'])) : false;
     $create = !empty($this->address['country']) ? $address_element->appendChild(new DOMElement('CountryCode', $this->address['country'])) : false;
     unset($create);
     return parent::buildRequest() . $address_dom->saveXML();
 }
Esempio n. 5
0
	/**
	 * Returns a list of available variants
	 * The structure is:
	 * array(
	 *     stdclass(
	 *         'name' => 'ups'
	 *         , 'display_name' => 'UPS'
	 *         , 'variant' => '01'
	 *         , 'variant_display_name' => 'Domestic'
	 *         ,  price => 12
	 * ))
	 *
	 * @param Cart $cart
	 * @internal param \Address $shipping_address
	 * @return array
	 */
	public function getAvailableVariants(Cart $cart)
	{
		$shipping_address = $cart->getShippingAddress();
		if(!$shipping_address)
		{
			$variant = new stdClass();
			$variant->name = $this->getName();
			$variant->display_name = $this->getDisplayName();
			$variant->variant = NULL;
			$variant->variant_display_name = 'Rates and available UPS services will show up after you enter your shipping address.';
			$variant->price = NULL;
			return array($variant);
		}

		$ups_api = new UpsAPI($this);
		try
		{
			$available_rates = $ups_api->getAvailableRates($cart);
		}
		catch(APIException $exception)
		{
			$available_rates = array();
		}


		$available_variants = array();
		foreach($available_rates as $rate)
		{
			$service_code = $rate['service'];
			$price = $rate['price'];
			// Even though UPS supports a certain service for the current Cart,
			// if the admin didn't enable it, we skip it
			if(!in_array($service_code, $this->enabled_services)) continue;
			$variant = new stdClass();
			$variant->name = $this->getName();
			$variant->display_name = $this->getDisplayName();
			$variant->variant = $service_code;
			$variant->variant_display_name = UPS::$service_names[$service_code];
			$variant->price = $price;
			$available_variants[] = $variant;
		}
		return $available_variants;
	}
Esempio n. 6
0
 /**
  * Builds the XML used to make the request
  * 
  * If $customer_context is an array it should be in the format:
  * $customer_context = array('Element' => 'Value');
  * 
  * @access public
  * @param array|string $cutomer_context customer data
  * @return string $return_value request XML
  */
 public function buildRequest($customer_context = null)
 {
     /** create DOMDocument objects **/
     $xml = new DOMDocument('1.0');
     /** create the TrackRequest element **/
     $track_element = $xml->appendChild(new DOMElement('TrackRequest'));
     $track_element->setAttributeNode(new DOMAttr('xml:lang', 'en-US'));
     // create the child elements
     $request_element = $this->buildRequest_RequestElement($track_element, 'Track', 'activity', $customer_context);
     if (!empty($this->tracking_number)) {
         $track_element->appendChild(new DOMElement('TrackingNumber', $this->tracking_number));
     }
     // end if we have a tracking number
     // check to see if we have inquiry data
     if (!empty($this->inquiry_array)) {
         $reference_numer = $this->buildRequest_Inquiry($track_element);
     }
     // end if we have inquiry data
     return parent::buildRequest() . $xml->saveXML();
 }