コード例 #1
0
 /**
  * Builds the merchant calculation response xml to be sent to
  * Google Checkout.
  *
  * @return string the response xml
  */
 function GetXML()
 {
     require_once 'xml/google_xml_builder.php';
     $xml_data = new GoogleXmlBuilder();
     $xml_data->Push('merchant-calculation-results', array('xmlns' => $this->schema_url));
     $xml_data->Push('results');
     foreach ($this->results_arr as $result) {
         if ($result->shipping_name != "") {
             $xml_data->Push('result', array('shipping-name' => $result->shipping_name, 'address-id' => $result->address_id));
             $xml_data->Element('shipping-rate', $result->ship_price, array('currency' => $this->currency));
             $xml_data->Element('shippable', $result->shippable);
         } else {
             $xml_data->Push('result', array('address-id' => $result->address_id));
         }
         if ($result->tax_amount != "") {
             $xml_data->Element('total-tax', $result->tax_amount, array('currency' => $this->currency));
         }
         if (count($result->coupon_arr) != 0 || count($result->giftcert_arr) != 0) {
             $xml_data->Push('merchant-code-results');
             foreach ($result->coupon_arr as $curr_coupon) {
                 $xml_data->Push('coupon-result');
                 $xml_data->Element('valid', $curr_coupon->coupon_valid);
                 $xml_data->Element('code', $curr_coupon->coupon_code);
                 $xml_data->Element('calculated-amount', $curr_coupon->coupon_amount, array('currency' => $this->currency));
                 $xml_data->Element('message', $curr_coupon->coupon_message);
                 $xml_data->Pop('coupon-result');
             }
             foreach ($result->giftcert_arr as $curr_gift) {
                 $xml_data->Push('gift-result');
                 $xml_data->Element('valid', $curr_gift->gift_valid);
                 $xml_data->Element('code', $curr_gift->gift_code);
                 $xml_data->Element('calculated-amount', $curr_gift->gift_amount, array('currency' => $this->currency));
                 $xml_data->Element('message', $curr_gift->gift_message);
                 $xml_data->Pop('gift-result');
             }
             $xml_data->Pop('merchant-code-results');
         }
         $xml_data->Pop('result');
     }
     $xml_data->Pop('results');
     $xml_data->Pop('merchant-calculation-results');
     return $xml_data->GetXML();
 }
コード例 #2
0
ファイル: googlecart.php プロジェクト: digideskio/oscmax2
 /**
  * Builds the cart's xml to be sent to Google Checkout.
  *
  * @return string the cart's xml
  */
 function GetXML()
 {
     require_once 'xml/google_xml_builder.php';
     $xml_data = new GoogleXmlBuilder();
     $xml_data->Push('checkout-shopping-cart', array('xmlns' => $this->schema_url));
     $xml_data->Push('shopping-cart');
     // Add cart expiration if set
     if ($this->cart_expiration != "") {
         $xml_data->Push('cart-expiration');
         $xml_data->Element('good-until-date', $this->cart_expiration);
         $xml_data->Pop('cart-expiration');
     }
     // Add XML data for each of the items
     $xml_data->Push('items');
     foreach ($this->item_arr as $item) {
         $xml_data->Push('item');
         $xml_data->Element('item-name', $item->item_name);
         $xml_data->Element('item-description', $item->item_description);
         $xml_data->Element('unit-price', $item->unit_price, array('currency' => $this->currency));
         $xml_data->Element('quantity', $item->quantity);
         if ($item->merchant_private_item_data != '') {
             //echo get_class($item->merchant_private_item_data);
             if (is_a($item->merchant_private_item_data, 'merchantprivate')) {
                 $item->merchant_private_item_data->AddMerchantPrivateToXML($xml_data);
             } else {
                 $xml_data->Element('merchant-private-item-data', $item->merchant_private_item_data);
             }
         }
         if ($item->merchant_item_id != '') {
             $xml_data->Element('merchant-item-id', $item->merchant_item_id);
         }
         if ($item->tax_table_selector != '') {
             $xml_data->Element('tax-table-selector', $item->tax_table_selector);
         }
         // Carrier calculation
         if ($item->item_weight != '' && $item->numeric_weight !== '') {
             $xml_data->EmptyElement('item-weight', array('unit' => $item->item_weight, 'value' => $item->numeric_weight));
         }
         // New Digital Delivery Tags
         if ($item->digital_content) {
             $xml_data->push('digital-content');
             if (!empty($item->digital_url)) {
                 $xml_data->element('description', substr($item->digital_description, 0, MAX_DIGITAL_DESC));
                 $xml_data->element('url', $item->digital_url);
                 // To avoid NULL key message in GC confirmation Page
                 if (!empty($item->digital_key)) {
                     $xml_data->element('key', $item->digital_key);
                 }
             } else {
                 $xml_data->element('email-delivery', $this->_GetBooleanValue($item->email_delivery, "true"));
             }
             $xml_data->pop('digital-content');
         }
         $xml_data->Pop('item');
     }
     $xml_data->Pop('items');
     if ($this->merchant_private_data != '') {
         if (is_a($this->merchant_private_data, 'merchantprivate')) {
             $this->merchant_private_data->AddMerchantPrivateToXML($xml_data);
         } else {
             $xml_data->Element('merchant-private-data', $this->merchant_private_data);
         }
     }
     $xml_data->Pop('shopping-cart');
     $xml_data->Push('checkout-flow-support');
     $xml_data->Push('merchant-checkout-flow-support');
     if ($this->edit_cart_url != '') {
         $xml_data->Element('edit-cart-url', $this->edit_cart_url);
     }
     if ($this->continue_shopping_url != '') {
         $xml_data->Element('continue-shopping-url', $this->continue_shopping_url);
     }
     if (count($this->shipping_arr) > 0) {
         $xml_data->Push('shipping-methods');
     }
     // Add the shipping methods
     foreach ($this->shipping_arr as $ship) {
         // Pickup shipping handled in else part
         if ($ship->type == "flat-rate-shipping" || $ship->type == "merchant-calculated-shipping") {
             $xml_data->Push($ship->type, array('name' => $ship->name));
             $xml_data->Element('price', $ship->price, array('currency' => $this->currency));
             $shipping_restrictions = $ship->shipping_restrictions;
             if (isset($shipping_restrictions)) {
                 $xml_data->Push('shipping-restrictions');
                 if ($shipping_restrictions->allow_us_po_box === true) {
                     $xml_data->Element('allow-us-po-box', "true");
                 } else {
                     $xml_data->Element('allow-us-po-box', "false");
                 }
                 //Check if allowed restrictions specified
                 if ($shipping_restrictions->allowed_restrictions) {
                     $xml_data->Push('allowed-areas');
                     if ($shipping_restrictions->allowed_country_area != "") {
                         $xml_data->EmptyElement('us-country-area', array('country-area' => $shipping_restrictions->allowed_country_area));
                     }
                     foreach ($shipping_restrictions->allowed_state_areas_arr as $current) {
                         $xml_data->Push('us-state-area');
                         $xml_data->Element('state', $current);
                         $xml_data->Pop('us-state-area');
                     }
                     foreach ($shipping_restrictions->allowed_zip_patterns_arr as $current) {
                         $xml_data->Push('us-zip-area');
                         $xml_data->Element('zip-pattern', $current);
                         $xml_data->Pop('us-zip-area');
                     }
                     if ($shipping_restrictions->allowed_world_area === true) {
                         $xml_data->EmptyElement('world-area');
                     }
                     for ($i = 0; $i < count($shipping_restrictions->allowed_country_codes_arr); $i++) {
                         $xml_data->Push('postal-area');
                         $country_code = $shipping_restrictions->allowed_country_codes_arr[$i];
                         $postal_pattern = $shipping_restrictions->allowed_postal_patterns_arr[$i];
                         $xml_data->Element('country-code', $country_code);
                         if ($postal_pattern != "") {
                             $xml_data->Element('postal-code-pattern', $postal_pattern);
                         }
                         $xml_data->Pop('postal-area');
                     }
                     $xml_data->Pop('allowed-areas');
                 }
                 if ($shipping_restrictions->excluded_restrictions) {
                     if (!$shipping_restrictions->allowed_restrictions) {
                         $xml_data->EmptyElement('allowed-areas');
                     }
                     $xml_data->Push('excluded-areas');
                     if ($shipping_restrictions->excluded_country_area != "") {
                         $xml_data->EmptyElement('us-country-area', array('country-area' => $shipping_restrictions->excluded_country_area));
                     }
                     foreach ($shipping_restrictions->excluded_state_areas_arr as $current) {
                         $xml_data->Push('us-state-area');
                         $xml_data->Element('state', $current);
                         $xml_data->Pop('us-state-area');
                     }
                     foreach ($shipping_restrictions->excluded_zip_patterns_arr as $current) {
                         $xml_data->Push('us-zip-area');
                         $xml_data->Element('zip-pattern', $current);
                         $xml_data->Pop('us-zip-area');
                     }
                     for ($i = 0; $i < count($shipping_restrictions->excluded_country_codes_arr); $i++) {
                         $xml_data->Push('postal-area');
                         $country_code = $shipping_restrictions->excluded_country_codes_arr[$i];
                         $postal_pattern = $shipping_restrictions->excluded_postal_patterns_arr[$i];
                         $xml_data->Element('country-code', $country_code);
                         if ($postal_pattern != "") {
                             $xml_data->Element('postal-code-pattern', $postal_pattern);
                         }
                         $xml_data->Pop('postal-area');
                     }
                     $xml_data->Pop('excluded-areas');
                 }
                 $xml_data->Pop('shipping-restrictions');
             }
             if ($ship->type == "merchant-calculated-shipping") {
                 $address_filters = $ship->address_filters;
                 if (isset($address_filters)) {
                     $xml_data->Push('address-filters');
                     if ($address_filters->allow_us_po_box === true) {
                         $xml_data->Element('allow-us-po-box', "true");
                     } else {
                         $xml_data->Element('allow-us-po-box', "false");
                     }
                     //Check if allowed restrictions specified
                     if ($address_filters->allowed_restrictions) {
                         $xml_data->Push('allowed-areas');
                         if ($address_filters->allowed_country_area != "") {
                             $xml_data->EmptyElement('us-country-area', array('country-area' => $address_filters->allowed_country_area));
                         }
                         foreach ($address_filters->allowed_state_areas_arr as $current) {
                             $xml_data->Push('us-state-area');
                             $xml_data->Element('state', $current);
                             $xml_data->Pop('us-state-area');
                         }
                         foreach ($address_filters->allowed_zip_patterns_arr as $current) {
                             $xml_data->Push('us-zip-area');
                             $xml_data->Element('zip-pattern', $current);
                             $xml_data->Pop('us-zip-area');
                         }
                         if ($address_filters->allowed_world_area === true) {
                             $xml_data->EmptyElement('world-area');
                         }
                         for ($i = 0; $i < count($address_filters->allowed_country_codes_arr); $i++) {
                             $xml_data->Push('postal-area');
                             $country_code = $address_filters->allowed_country_codes_arr[$i];
                             $postal_pattern = $address_filters->allowed_postal_patterns_arr[$i];
                             $xml_data->Element('country-code', $country_code);
                             if ($postal_pattern != "") {
                                 $xml_data->Element('postal-code-pattern', $postal_pattern);
                             }
                             $xml_data->Pop('postal-area');
                         }
                         $xml_data->Pop('allowed-areas');
                     }
                     if ($address_filters->excluded_restrictions) {
                         if (!$address_filters->allowed_restrictions) {
                             $xml_data->EmptyElement('allowed-areas');
                         }
                         $xml_data->Push('excluded-areas');
                         if ($address_filters->excluded_country_area != "") {
                             $xml_data->EmptyElement('us-country-area', array('country-area' => $address_filters->excluded_country_area));
                         }
                         foreach ($address_filters->excluded_state_areas_arr as $current) {
                             $xml_data->Push('us-state-area');
                             $xml_data->Element('state', $current);
                             $xml_data->Pop('us-state-area');
                         }
                         foreach ($address_filters->excluded_zip_patterns_arr as $current) {
                             $xml_data->Push('us-zip-area');
                             $xml_data->Element('zip-pattern', $current);
                             $xml_data->Pop('us-zip-area');
                         }
                         for ($i = 0; $i < count($address_filters->excluded_country_codes_arr); $i++) {
                             $xml_data->Push('postal-area');
                             $country_code = $address_filters->excluded_country_codes_arr[$i];
                             $postal_pattern = $address_filters->excluded_postal_patterns_arr[$i];
                             $xml_data->Element('country-code', $country_code);
                             if ($postal_pattern != "") {
                                 $xml_data->Element('postal-code-pattern', $postal_pattern);
                             }
                             $xml_data->Pop('postal-area');
                         }
                         $xml_data->Pop('excluded-areas');
                     }
                     $xml_data->Pop('address-filters');
                 }
             }
             $xml_data->Pop($ship->type);
         } else {
             if ($ship->type == "carrier-calculated-shipping") {
                 //$xml_data->Push($ship->type, array('name' => $ship->name));
                 $xml_data->Push($ship->type);
                 $xml_data->Push('carrier-calculated-shipping-options');
                 $CCSoptions = $ship->CarrierCalculatedShippingOptions;
                 foreach ($CCSoptions as $CCSoption) {
                     $xml_data->Push('carrier-calculated-shipping-option');
                     $xml_data->Element('price', $CCSoption->price, array('currency' => $this->currency));
                     $xml_data->Element('shipping-company', $CCSoption->shipping_company);
                     $xml_data->Element('shipping-type', $CCSoption->shipping_type);
                     $xml_data->Element('carrier-pickup', $CCSoption->carrier_pickup);
                     if (!empty($CCSoption->additional_fixed_charge)) {
                         $xml_data->Element('additional-fixed-charge', $CCSoption->additional_fixed_charge, array('currency' => $this->currency));
                     }
                     if (!empty($CCSoption->additional_variable_charge_percent)) {
                         $xml_data->Element('additional-variable-charge-percent', $CCSoption->additional_variable_charge_percent);
                     }
                     $xml_data->Pop('carrier-calculated-shipping-option');
                 }
                 $xml_data->Pop('carrier-calculated-shipping-options');
                 //$ShippingPackage = $ship->ShippingPackage;
                 $xml_data->Push('shipping-packages');
                 $xml_data->Push('shipping-package');
                 $xml_data->Push('ship-from', array('id' => $ship->ShippingPackage->ship_from->id));
                 $xml_data->Element('city', $ship->ShippingPackage->ship_from->city);
                 $xml_data->Element('region', $ship->ShippingPackage->ship_from->region);
                 $xml_data->Element('postal-code', $ship->ShippingPackage->ship_from->postal_code);
                 $xml_data->Element('country-code', $ship->ShippingPackage->ship_from->country_code);
                 $xml_data->Pop('ship-from');
                 $xml_data->EmptyElement('width', array('unit' => $ship->ShippingPackage->unit, 'value' => $ship->ShippingPackage->width));
                 $xml_data->EmptyElement('length', array('unit' => $ship->ShippingPackage->unit, 'value' => $ship->ShippingPackage->length));
                 $xml_data->EmptyElement('height', array('unit' => $ship->ShippingPackage->unit, 'value' => $ship->ShippingPackage->height));
                 $xml_data->Element('delivery-address-category', $ship->ShippingPackage->delivery_address_category);
                 $xml_data->Pop('shipping-package');
                 $xml_data->Pop('shipping-packages');
                 $xml_data->Pop($ship->type);
             } else {
                 if ($ship->type == "pickup") {
                     $xml_data->Push('pickup', array('name' => $ship->name));
                     $xml_data->Element('price', $ship->price, array('currency' => $this->currency));
                     $xml_data->Pop('pickup');
                 }
             }
         }
     }
     if (count($this->shipping_arr) > 0) {
         $xml_data->Pop('shipping-methods');
     }
     if ($this->request_buyer_phone != "") {
         $xml_data->Element('request-buyer-phone-number', $this->request_buyer_phone);
     }
     if ($this->merchant_calculations_url != "") {
         $xml_data->Push('merchant-calculations');
         $xml_data->Element('merchant-calculations-url', $this->merchant_calculations_url);
         if ($this->accept_merchant_coupons != "") {
             $xml_data->Element('accept-merchant-coupons', $this->accept_merchant_coupons);
         }
         if ($this->accept_gift_certificates != "") {
             $xml_data->Element('accept-gift-certificates', $this->accept_gift_certificates);
         }
         $xml_data->Pop('merchant-calculations');
     }
     //Set Third party Tracking
     if ($this->thirdPartyTackingUrl) {
         $xml_data->push('parameterized-urls');
         $xml_data->push('parameterized-url', array('url' => $this->thirdPartyTackingUrl));
         if (is_array($this->thirdPartyTackingParams) && count($this->thirdPartyTackingParams) > 0) {
             $xml_data->push('parameters');
             foreach ($this->thirdPartyTackingParams as $tracking_param_name => $tracking_param_type) {
                 $xml_data->emptyElement('url-parameter', array('name' => $tracking_param_name, 'type' => $tracking_param_type));
             }
             $xml_data->pop('parameters');
         }
         $xml_data->pop('parameterized-url');
         $xml_data->pop('parameterized-urls');
     }
     //Set Default and Alternate tax tables
     if (count($this->alternate_tax_tables_arr) != 0 || count($this->default_tax_rules_arr) != 0) {
         if ($this->merchant_calculated_tax != "") {
             $xml_data->Push('tax-tables', array('merchant-calculated' => $this->merchant_calculated_tax));
         } else {
             $xml_data->Push('tax-tables');
         }
         if (count($this->default_tax_rules_arr) != 0) {
             $xml_data->Push('default-tax-table');
             $xml_data->Push('tax-rules');
             foreach ($this->default_tax_rules_arr as $curr_rule) {
                 if ($curr_rule->country_area != "") {
                     $xml_data->Push('default-tax-rule');
                     $xml_data->Element('shipping-taxed', $curr_rule->shipping_taxed);
                     $xml_data->Element('rate', $curr_rule->tax_rate);
                     $xml_data->Push('tax-area');
                     $xml_data->EmptyElement('us-country-area', array('country-area' => $curr_rule->country_area));
                     $xml_data->Pop('tax-area');
                     $xml_data->Pop('default-tax-rule');
                 }
                 foreach ($curr_rule->state_areas_arr as $current) {
                     $xml_data->Push('default-tax-rule');
                     $xml_data->Element('shipping-taxed', $curr_rule->shipping_taxed);
                     $xml_data->Element('rate', $curr_rule->tax_rate);
                     $xml_data->Push('tax-area');
                     $xml_data->Push('us-state-area');
                     $xml_data->Element('state', $current);
                     $xml_data->Pop('us-state-area');
                     $xml_data->Pop('tax-area');
                     $xml_data->Pop('default-tax-rule');
                 }
                 foreach ($curr_rule->zip_patterns_arr as $current) {
                     $xml_data->Push('default-tax-rule');
                     $xml_data->Element('shipping-taxed', $curr_rule->shipping_taxed);
                     $xml_data->Element('rate', $curr_rule->tax_rate);
                     $xml_data->Push('tax-area');
                     $xml_data->Push('us-zip-area');
                     $xml_data->Element('zip-pattern', $current);
                     $xml_data->Pop('us-zip-area');
                     $xml_data->Pop('tax-area');
                     $xml_data->Pop('default-tax-rule');
                 }
                 for ($i = 0; $i < count($curr_rule->country_codes_arr); $i++) {
                     $xml_data->Push('default-tax-rule');
                     $xml_data->Element('shipping-taxed', $curr_rule->shipping_taxed);
                     $xml_data->Element('rate', $curr_rule->tax_rate);
                     $xml_data->Push('tax-area');
                     $xml_data->Push('postal-area');
                     $country_code = $curr_rule->country_codes_arr[$i];
                     $postal_pattern = $curr_rule->postal_patterns_arr[$i];
                     $xml_data->Element('country-code', $country_code);
                     if ($postal_pattern != "") {
                         $xml_data->Element('postal-code-pattern', $postal_pattern);
                     }
                     $xml_data->Pop('postal-area');
                     $xml_data->Pop('tax-area');
                     $xml_data->Pop('default-tax-rule');
                 }
                 if ($curr_rule->world_area === true) {
                     $xml_data->Push('default-tax-rule');
                     $xml_data->Element('shipping-taxed', $curr_rule->shipping_taxed);
                     $xml_data->Element('rate', $curr_rule->tax_rate);
                     $xml_data->Push('tax-area');
                     $xml_data->EmptyElement('world-area');
                     $xml_data->Pop('tax-area');
                     $xml_data->Pop('default-tax-rule');
                 }
             }
             $xml_data->Pop('tax-rules');
             $xml_data->Pop('default-tax-table');
         }
         if (count($this->alternate_tax_tables_arr) != 0) {
             $xml_data->Push('alternate-tax-tables');
             foreach ($this->alternate_tax_tables_arr as $curr_table) {
                 $xml_data->Push('alternate-tax-table', array('standalone' => $curr_table->standalone, 'name' => $curr_table->name));
                 $xml_data->Push('alternate-tax-rules');
                 foreach ($curr_table->tax_rules_arr as $curr_rule) {
                     if ($curr_rule->country_area != "") {
                         $xml_data->Push('alternate-tax-rule');
                         $xml_data->Element('rate', $curr_rule->tax_rate);
                         $xml_data->Push('tax-area');
                         $xml_data->EmptyElement('us-country-area', array('country-area' => $curr_rule->country_area));
                         $xml_data->Pop('tax-area');
                         $xml_data->Pop('alternate-tax-rule');
                     }
                     foreach ($curr_rule->state_areas_arr as $current) {
                         $xml_data->Push('alternate-tax-rule');
                         $xml_data->Element('rate', $curr_rule->tax_rate);
                         $xml_data->Push('tax-area');
                         $xml_data->Push('us-state-area');
                         $xml_data->Element('state', $current);
                         $xml_data->Pop('us-state-area');
                         $xml_data->Pop('tax-area');
                         $xml_data->Pop('alternate-tax-rule');
                     }
                     foreach ($curr_rule->zip_patterns_arr as $current) {
                         $xml_data->Push('alternate-tax-rule');
                         $xml_data->Element('rate', $curr_rule->tax_rate);
                         $xml_data->Push('tax-area');
                         $xml_data->Push('us-zip-area');
                         $xml_data->Element('zip-pattern', $current);
                         $xml_data->Pop('us-zip-area');
                         $xml_data->Pop('tax-area');
                         $xml_data->Pop('alternate-tax-rule');
                     }
                     for ($i = 0; $i < count($curr_rule->country_codes_arr); $i++) {
                         $xml_data->Push('alternate-tax-rule');
                         $xml_data->Element('rate', $curr_rule->tax_rate);
                         $xml_data->Push('tax-area');
                         $xml_data->Push('postal-area');
                         $country_code = $curr_rule->country_codes_arr[$i];
                         $postal_pattern = $curr_rule->postal_patterns_arr[$i];
                         $xml_data->Element('country-code', $country_code);
                         if ($postal_pattern != "") {
                             $xml_data->Element('postal-code-pattern', $postal_pattern);
                         }
                         $xml_data->Pop('postal-area');
                         $xml_data->Pop('tax-area');
                         $xml_data->Pop('alternate-tax-rule');
                     }
                     if ($curr_rule->world_area === true) {
                         $xml_data->Push('alternate-tax-rule');
                         $xml_data->Element('rate', $curr_rule->tax_rate);
                         $xml_data->Push('tax-area');
                         $xml_data->EmptyElement('world-area');
                         $xml_data->Pop('tax-area');
                         $xml_data->Pop('alternate-tax-rule');
                     }
                 }
                 $xml_data->Pop('alternate-tax-rules');
                 $xml_data->Pop('alternate-tax-table');
             }
             $xml_data->Pop('alternate-tax-tables');
         }
         $xml_data->Pop('tax-tables');
     }
     if ($this->rounding_mode != "" && $this->rounding_rule != "") {
         $xml_data->Push('rounding-policy');
         $xml_data->Element('mode', $this->rounding_mode);
         $xml_data->Element('rule', $this->rounding_rule);
         $xml_data->Pop('rounding-policy');
     }
     if ($this->analytics_data != '') {
         $xml_data->Element('analytics-data', $this->analytics_data);
     }
     // Platform ID. This allows the use of osCommerce to be tracked.
     // NOTE(eddavisson): Don't change this number unless you know
     // exactly what you're doing. It is not meant to have the same
     // value as your own merchant ID.
     $xml_data->Element('platform-id', '352459354768565');
     $xml_data->Pop('merchant-checkout-flow-support');
     $xml_data->Pop('checkout-flow-support');
     $xml_data->Pop('checkout-shopping-cart');
     return $xml_data->GetXML();
 }