* Send archive order: $response->SendArchiveOrder($data[$root]
 *    ['google-order-number']['VALUE'], $message_log);
 *
 */
switch ($root) {
    case "request-received":
        break;
    case "error":
        break;
    case "diagnosis":
        break;
    case "checkout-redirect":
        break;
    case "merchant-calculation-callback":
        // Create the results and send it
        $merchant_calc = new GoogleMerchantCalculations();
        // Loop through the list of address ids from the callback
        $addresses = get_arr_result($data[$root]['calculate']['addresses']['anonymous-address']);
        foreach ($addresses as $curr_address) {
            $curr_id = $curr_address['id'];
            $country = $curr_address['country-code']['VALUE'];
            $city = $curr_address['city']['VALUE'];
            $region = $curr_address['region']['VALUE'];
            $postal_code = $curr_address['region']['VALUE'];
            // Loop through each shipping method if merchant-calculated shipping
            // support is to be provided
            if (isset($data[$root]['calculate']['shipping'])) {
                $shipping = get_arr_result($data[$root]['calculate']['shipping']['method']);
                foreach ($shipping as $curr_ship) {
                    $name = $curr_ship['name'];
                    //Compute the price for this shipping method and address id
Beispiel #2
0
 /**
  * Calculate available shipping amounts and taxes
  */
 protected function _responseMerchantCalculationCallback()
 {
     $merchantCalculations = new GoogleMerchantCalculations($this->getCurrency());
     $quoteId = $this->getData('root/shopping-cart/merchant-private-data/quote-id/VALUE');
     $storeId = $this->getData('root/shopping-cart/merchant-private-data/store-id/VALUE');
     $quote = Mage::getModel('sales/quote')->setStoreId($storeId)->load($quoteId);
     $billingAddress = $quote->getBillingAddress();
     $address = $quote->getShippingAddress();
     $googleAddress = $this->getData('root/calculate/addresses/anonymous-address');
     $googleAddresses = array();
     if (isset($googleAddress['id'])) {
         $googleAddresses[] = $googleAddress;
     } else {
         $googleAddresses = $googleAddress;
     }
     $methods = Mage::getStoreConfig('google/checkout_shipping_merchant/allowed_methods', $this->getStoreId());
     $methods = unserialize($methods);
     $limitCarrier = array();
     foreach ($methods['method'] as $method) {
         if ($method) {
             list($carrierCode, $methodCode) = explode('/', $method);
             $limitCarrier[] = $carrierCode;
         }
     }
     foreach ($googleAddresses as $googleAddress) {
         $addressId = $googleAddress['id'];
         $regionCode = $googleAddress['region']['VALUE'];
         $countryCode = $googleAddress['country-code']['VALUE'];
         $regionModel = Mage::getModel('directory/region')->loadByCode($regionCode, $countryCode);
         $regionId = $regionModel->getId();
         $address->setCountryId($countryCode)->setRegion($regionCode)->setRegionId($regionId)->setCity($googleAddress['city']['VALUE'])->setPostcode($googleAddress['postal-code']['VALUE'])->setLimitCarrier($limitCarrier);
         $billingAddress->setCountryId($countryCode)->setRegion($regionCode)->setRegionId($regionId)->setCity($googleAddress['city']['VALUE'])->setPostcode($googleAddress['postal-code']['VALUE'])->setLimitCarrier($limitCarrier);
         $address->setCollectShippingRates(true)->collectShippingRates()->collectTotals();
         $billingAddress->collectTotals();
         if ($gRequestMethods = $this->getData('root/calculate/shipping/method')) {
             $carriers = array();
             $errors = array();
             foreach (Mage::getStoreConfig('carriers', $storeId) as $carrierCode => $carrierConfig) {
                 if (!isset($carrierConfig['title'])) {
                     continue;
                 }
                 $title = $carrierConfig['title'];
                 foreach ($gRequestMethods as $method) {
                     $methodName = is_array($method) ? $method['name'] : $method;
                     if ($title && $method && strpos($methodName, $title) === 0) {
                         $carriers[$carrierCode] = $title;
                         $errors[$title] = true;
                     }
                 }
             }
             $result = Mage::getModel('shipping/shipping')->collectRatesByAddress($address, array_keys($carriers))->getResult();
             $rates = array();
             $rateCodes = array();
             foreach ($result->getAllRates() as $rate) {
                 if ($rate instanceof Mage_Shipping_Model_Rate_Result_Error) {
                     $errors[$rate->getCarrierTitle()] = 1;
                 } else {
                     $k = $rate->getCarrierTitle() . ' - ' . $rate->getMethodTitle();
                     if ($address->getFreeShipping()) {
                         $price = 0;
                     } else {
                         $price = $rate->getPrice();
                     }
                     if ($price) {
                         $price = Mage::helper('tax')->getShippingPrice($price, false, $address, null, $storeId);
                     }
                     $rates[$k] = $price;
                     $rateCodes[$k] = $rate->getCarrier() . '_' . $rate->getMethod();
                     unset($errors[$rate->getCarrierTitle()]);
                 }
             }
             foreach ($gRequestMethods as $method) {
                 $methodName = is_array($method) ? $method['name'] : $method;
                 $result = new GoogleResult($addressId);
                 if (!empty($errors)) {
                     $continue = false;
                     foreach ($errors as $carrier => $dummy) {
                         if (strpos($methodName, $carrier) === 0) {
                             $result->SetShippingDetails($methodName, 0, "false");
                             $merchantCalculations->AddResult($result);
                             $continue = true;
                             break;
                         }
                     }
                     if ($continue) {
                         continue;
                     }
                 }
                 if (isset($rates[$methodName])) {
                     if ($this->getData('root/calculate/tax/VALUE') == 'true') {
                         $address->setShippingMethod($rateCodes[$methodName]);
                         $address->collectTotals();
                         $taxAmount = $address->getBaseTaxAmount();
                         $taxAmount += $billingAddress->getBaseTaxAmount();
                         $result->setTaxDetails($taxAmount);
                     }
                     $result->SetShippingDetails($methodName, $rates[$methodName], "true");
                     $merchantCalculations->AddResult($result);
                 }
             }
         } elseif ($this->getData('root/calculate/tax/VALUE') == 'true') {
             $address->setShippingMethod(null);
             $address->setCollectShippingRates(true)->collectTotals();
             $billingAddress->setCollectShippingRates(true)->collectTotals();
             $taxAmount = $address->getBaseTaxAmount();
             $taxAmount += $billingAddress->getBaseTaxAmount();
             $result = new GoogleResult($addressId);
             $result->setTaxDetails($taxAmount);
             $merchantCalculations->addResult($result);
         }
     }
     $this->getGResponse()->ProcessMerchantCalculations($merchantCalculations);
 }
 * Send archive order: $Grequest->SendArchiveOrder($data[$root]
 *    ['google-order-number']['VALUE']);
 *
 */
switch ($root) {
    case "request-received":
        break;
    case "error":
        break;
    case "diagnosis":
        break;
    case "checkout-redirect":
        break;
    case "merchant-calculation-callback":
        // Create the results and send it
        $merchant_calc = new GoogleMerchantCalculations($currency);
        // Loop through the list of address ids from the callback
        $addresses = get_arr_result($data[$root]['calculate']['addresses']['anonymous-address']);
        foreach ($addresses as $curr_address) {
            $curr_id = $curr_address['id'];
            $country = $curr_address['country-code']['VALUE'];
            $city = $curr_address['city']['VALUE'];
            $region = $curr_address['region']['VALUE'];
            $postal_code = $curr_address['postal-code']['VALUE'];
            // Loop through each shipping method if merchant-calculated shipping
            // support is to be provided
            if (isset($data[$root]['calculate']['shipping'])) {
                $shipping = get_arr_result($data[$root]['calculate']['shipping']['method']);
                foreach ($shipping as $curr_ship) {
                    $name = $curr_ship['name'];
                    //Compute the price for this shipping method and address id
Beispiel #4
0
/**
 * Process a <merchant-calculation-callback>.
 */
function process_merchant_calculation_callback_single($google_response)
{
    global $google_checkout, $order, $cart, $total_weight, $total_count;
    list($root, $gc_data) = $google_response->GetParsedXML();
    $currencies = new currencies();
    // Get a hash array with the description of each shipping method
    $shipping_methods = $google_checkout->getMethods();
    require DIR_WS_CLASSES . 'order.php';
    $order = new order();
    $items = gc_get_arr_result($gc_data[$root]['shopping-cart']['items']['item']);
    // Get Coustoms OT
    $custom_order_totals_total = 0;
    $custom_order_totals = array();
    $order->products = array();
    foreach ($items as $item) {
        if (isset($item['merchant-private-item-data']['item']['VALUE'])) {
            $order->products[] = unserialize(base64_decode($item['merchant-private-item-data']['item']['VALUE']));
        } else {
            if ($item['merchant-private-item-data']['order_total']['VALUE']) {
                $ot = unserialize(base64_decode($item['merchant-private-item-data']['order_total']['VALUE']));
                $custom_order_totals[] = $ot;
                $order_total_value = $ot['value'] * (strrpos($ot['text'], '-') === false ? 1 : -1);
                $custom_order_totals_total += $currencies->get_value($gc_data[$root]['order-total']['currency']) * $order_total_value;
            } else {
                // For invoices.
                $order->products[] = array('qty' => $item['quantity']['VALUE'], 'name' => $item['item-name']['VALUE'], 'model' => $item['item-description']['VALUE'], 'tax' => 0, 'tax_description' => @$item['tax-table-selector']['VALUE'], 'price' => $item['unit-price']['VALUE'], 'final_price' => $item['unit-price']['VALUE'], 'onetime_charges' => 0, 'weight' => 0, 'products_priced_by_attribute' => 0, 'product_is_free' => 0, 'products_discount_type' => 0, 'products_discount_type_from' => 0, 'id' => @$item['merchant-item-id']['VALUE']);
            }
        }
    }
    $ex_cart = $cart;
    $cart = new shoppingCart();
    $prod_attr = gc_get_prattr($order->products);
    foreach ($prod_attr as $product_id => $item_data) {
        //$products_id, $qty = '1', $attributes = '
        $cart->add_cart($product_id, $item_data['qty'], $item_data['attr']);
    }
    // Register a random ID in the session to check throughout the checkout procedure
    // against alterations in the shopping cart contents.
    // TODO(eddavisson): Why is this commented out?
    //if (!tep_session_is_registered('cartID')) {
    //  tep_session_register('cartID');
    //}
    //$cartID = $cart->cartID;
    $total_weight = $cart->show_weight();
    $total_count = $cart->count_contents();
    // Create the results and send it
    $merchant_calc = new GoogleMerchantCalculations(DEFAULT_CURRENCY);
    // Loop through the list of address ids from the callback.
    $addresses = gc_get_arr_result($gc_data[$root]['calculate']['addresses']['anonymous-address']);
    // Get all the enabled shipping methods.
    require_once DIR_WS_CLASSES . 'shipping.php';
    // Required for some shipping methods (ie. USPS).
    require_once 'includes/classes/http_client.php';
    foreach ($addresses as $curr_address) {
        // Set up the order address.
        $curr_id = $curr_address['id'];
        $country = $curr_address['country-code']['VALUE'];
        $city = $curr_address['city']['VALUE'];
        $region = $curr_address['region']['VALUE'];
        $postal_code = $curr_address['postal-code']['VALUE'];
        $row = tep_db_fetch_array(tep_db_query("select * from " . TABLE_COUNTRIES . " where countries_iso_code_2 = '" . gc_make_sql_string($country) . "'"));
        $order->delivery['country'] = array('id' => $row['countries_id'], 'title' => $row['countries_name'], 'iso_code_2' => $country, 'iso_code_3' => $row['countries_iso_code_3']);
        $order->delivery['country_id'] = $row['countries_id'];
        $order->delivery['format_id'] = $row['address_format_id'];
        $row = tep_db_fetch_array(tep_db_query("select * from " . TABLE_ZONES . " where zone_code = '" . gc_make_sql_string($region) . "'"));
        $order->delivery['zone_id'] = $row['zone_id'];
        $order->delivery['state'] = $row['zone_name'];
        $order->delivery['city'] = $city;
        $order->delivery['postcode'] = $postal_code;
        //print_r($order);
        $shipping_modules = new shipping();
        // Loop through each shipping method if merchant-calculated shipping
        // support is to be provided
        //print_r($gc_data[$root]['calculate']['shipping']['method']);
        if (isset($gc_data[$root]['calculate']['shipping'])) {
            $shipping = gc_get_arr_result($gc_data[$root]['calculate']['shipping']['method']);
            // TODO(eddavisson): If we reactivate this, need to move to new configuration system.
            if (MODULE_PAYMENT_GOOGLECHECKOUT_MULTISOCKET == 'True') {
                // Single.
                // Get all the enabled shipping methods.
                $name = $shipping[0]['name'];
                // Compute the price for this shipping method and address id
                list($a, $method_name) = explode(': ', $name);
                if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY && $shipping_methods[$method_name][1] == 'domestic_types' || $order->delivery['country']['id'] != SHIPPING_ORIGIN_COUNTRY && $shipping_methods[$method_name][1] == 'international_types') {
                    // Reset the shipping class to set the new address
                    if (class_exists($shipping_methods[$method_name][2])) {
                        $GLOBALS[$shipping_methods[$method_name][2]] = new $shipping_methods[$method_name][2]();
                    }
                }
                $quotes = $shipping_modules->quote('', $shipping_methods[$method_name][2]);
            } else {
                // Standard
                foreach ($shipping as $curr_ship) {
                    $name = $curr_ship['name'];
                    // Compute the price for this shipping method and address id
                    list($a, $method_name) = explode(': ', $name);
                    if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY && $shipping_methods[$method_name][1] == 'domestic_types' || $order->delivery['country']['id'] != SHIPPING_ORIGIN_COUNTRY && $shipping_methods[$method_name][1] == 'international_types') {
                        // Reset the shipping class to set the new address.
                        if (class_exists($shipping_methods[$method_name][2])) {
                            $GLOBALS[$shipping_methods[$method_name][2]] = new $shipping_methods[$method_name][2]();
                        }
                    }
                }
                $quotes = $shipping_modules->quote();
            }
            reset($shipping);
            foreach ($shipping as $curr_ship) {
                $name = $curr_ship['name'];
                // Compute the price for this shipping method and address id
                list($a, $method_name) = explode(': ', $name);
                unset($quote_provider);
                unset($quote_method);
                if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY && $shipping_methods[$method_name][1] == 'domestic_types' || $order->delivery['country']['id'] != SHIPPING_ORIGIN_COUNTRY && $shipping_methods[$method_name][1] == 'international_types') {
                    foreach ($quotes as $key_provider => $shipping_provider) {
                        // privider name (class)
                        if ($shipping_provider['id'] == $shipping_methods[$method_name][2]) {
                            // method name
                            $quote_provider = $key_provider;
                            if (is_array($shipping_provider['methods'])) {
                                foreach ($shipping_provider['methods'] as $key_method => $shipping_method) {
                                    if ($shipping_method['id'] == $shipping_methods[$method_name][0]) {
                                        $quote_method = $key_method;
                                        break;
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
                //if there is a problem with the method, i mark it as non-shippable
                if (isset($quotes[$quote_provider]['error']) || !isset($quotes[$quote_provider]['methods'][$quote_method]['cost'])) {
                    $price = "9999.09";
                    $shippable = "false";
                } else {
                    $price = $quotes[$quote_provider]['methods'][$quote_method]['cost'];
                    $shippable = "true";
                }
                $merchant_result = new GoogleResult($curr_id);
                $merchant_result->SetShippingDetails($name, $currencies->get_value(DEFAULT_CURRENCY) * $price, $shippable);
                if ($gc_data[$root]['calculate']['tax']['VALUE'] == "true") {
                    // Compute tax for this address id and shipping type
                    $amount = 15;
                    // Modify this to the actual tax value
                    $merchant_result->SetTaxDetails($currencies->get_value(DEFAULT_CURRENCY) * $amount);
                }
                if (isset($gc_data[$root]['calculate']['merchant-code-strings']['merchant-code-string'])) {
                    $codes = gc_get_arr_result($gc_data[$root]['calculate']['merchant-code-strings']['merchant-code-string']);
                    foreach ($codes as $curr_code) {
                        // Update this data as required to set whether the coupon is valid, the code and the amount
                        $coupons = new GoogleCoupons("true", $curr_code['code'], $currencies->get_value(DEFAULT_CURRENCY) * 5, "test2");
                        $merchant_result->AddCoupons($coupons);
                    }
                }
                $merchant_calc->AddResult($merchant_result);
            }
        } else {
            $merchant_result = new GoogleResult($curr_id);
            if ($gc_data[$root]['calculate']['tax']['VALUE'] == "true") {
                // Compute tax for this address id and shipping type
                $amount = 15;
                // Modify this to the actual tax value
                $merchant_result->SetTaxDetails($currencies->get_value(DEFAULT_CURRENCY) * $amount);
            }
            //calculate_coupons($google_response, $merchant_result);
            $merchant_calc->AddResult($merchant_result);
        }
    }
    $cart = $ex_cart;
    $google_response->ProcessMerchantCalculations($merchant_calc);
}
Beispiel #5
0
 /**
  * Calculate available shipping amounts and taxes
  */
 protected function _responseMerchantCalculationCallback()
 {
     $merchantCalculations = new GoogleMerchantCalculations($this->getCurrency());
     $quote = $this->_loadQuote();
     $billingAddress = $quote->getBillingAddress();
     $address = $quote->getShippingAddress();
     $googleAddress = $this->getData('root/calculate/addresses/anonymous-address');
     $googleAddresses = array();
     if (isset($googleAddress['id'])) {
         $googleAddresses[] = $googleAddress;
     } else {
         $googleAddresses = $googleAddress;
     }
     $methods = Mage::getStoreConfig('google/checkout_shipping_merchant/allowed_methods', $this->getStoreId());
     $methods = unserialize($methods);
     $limitCarrier = array();
     foreach ($methods['method'] as $method) {
         if ($method) {
             list($carrierCode, $methodCode) = explode('/', $method);
             $limitCarrier[$carrierCode] = $carrierCode;
         }
     }
     $limitCarrier = array_values($limitCarrier);
     foreach ($googleAddresses as $googleAddress) {
         $addressId = $googleAddress['id'];
         $regionCode = $googleAddress['region']['VALUE'];
         $countryCode = $googleAddress['country-code']['VALUE'];
         $regionModel = Mage::getModel('directory/region')->loadByCode($regionCode, $countryCode);
         $regionId = $regionModel->getId();
         $address->setCountryId($countryCode)->setRegion($regionCode)->setRegionId($regionId)->setCity($googleAddress['city']['VALUE'])->setPostcode($googleAddress['postal-code']['VALUE'])->setLimitCarrier($limitCarrier);
         $billingAddress->setCountryId($countryCode)->setRegion($regionCode)->setRegionId($regionId)->setCity($googleAddress['city']['VALUE'])->setPostcode($googleAddress['postal-code']['VALUE'])->setLimitCarrier($limitCarrier);
         $billingAddress->collectTotals();
         $shippingTaxClass = $this->_getTaxClassForShipping($quote);
         $gRequestMethods = $this->getData('root/calculate/shipping/method');
         if ($gRequestMethods) {
             // Make stable format of $gRequestMethods for convenient usage
             if (array_key_exists('VALUE', $gRequestMethods)) {
                 $gRequestMethods = array($gRequestMethods);
             }
             // Form list of mapping Google method names to applicable address rates
             $rates = array();
             $address->setCollectShippingRates(true)->collectShippingRates();
             foreach ($address->getAllShippingRates() as $rate) {
                 if ($rate instanceof Mage_Shipping_Model_Rate_Result_Error) {
                     continue;
                 }
                 $methodName = sprintf('%s - %s', $rate->getCarrierTitle(), $rate->getMethodTitle());
                 $rates[$methodName] = $rate;
             }
             foreach ($gRequestMethods as $method) {
                 $result = new GoogleResult($addressId);
                 $methodName = $method['name'];
                 if (isset($rates[$methodName])) {
                     $rate = $rates[$methodName];
                     $address->setShippingMethod($rate->getCode())->setLimitCarrier($rate->getCarrier())->setCollectShippingRates(true)->collectTotals();
                     $shippingRate = $address->getBaseShippingAmount() - $address->getBaseShippingDiscountAmount();
                     $result->SetShippingDetails($methodName, $shippingRate, 'true');
                     if ($this->getData('root/calculate/tax/VALUE') == 'true') {
                         $taxAmount = $address->getBaseTaxAmount();
                         $taxAmount += $billingAddress->getBaseTaxAmount();
                         $result->setTaxDetails($taxAmount);
                     }
                 } else {
                     if ($shippingTaxClass && $this->getData('root/calculate/tax/VALUE') == 'true') {
                         $i = 1;
                         $price = Mage::getStoreConfig('google/checkout_shipping_flatrate/price_' . $i, $quote->getStoreId());
                         $price = number_format($price, 2, '.', '');
                         $price = (double) Mage::helper('tax')->getShippingPrice($price, false, false);
                         $address->setShippingMethod(null);
                         $address->setCollectShippingRates(true)->collectTotals();
                         $billingAddress->setCollectShippingRates(true)->collectTotals();
                         $address->setBaseShippingAmount($price);
                         $address->setShippingAmount($this->_reCalculateToStoreCurrency($price, $quote));
                         $this->_applyShippingTaxClass($address, $shippingTaxClass);
                         $taxAmount = $address->getBaseTaxAmount();
                         $taxAmount += $billingAddress->getBaseTaxAmount();
                         $result->SetShippingDetails($methodName, $price - $address->getBaseShippingDiscountAmount(), 'true');
                         $result->setTaxDetails($taxAmount);
                         $i++;
                     } else {
                         $result->SetShippingDetails($methodName, 0, 'false');
                     }
                 }
                 $merchantCalculations->AddResult($result);
             }
         } else {
             if ($this->getData('root/calculate/tax/VALUE') == 'true') {
                 $address->setShippingMethod(null);
                 $address->setCollectShippingRates(true)->collectTotals();
                 $billingAddress->setCollectShippingRates(true)->collectTotals();
                 if (!Mage::helper('googlecheckout')->isShippingCarrierActive($this->getStoreId())) {
                     $this->_applyShippingTaxClass($address, $shippingTaxClass);
                 }
                 $taxAmount = $address->getBaseTaxAmount();
                 $taxAmount += $billingAddress->getBaseTaxAmount();
                 $result = new GoogleResult($addressId);
                 $result->setTaxDetails($taxAmount);
                 $merchantCalculations->addResult($result);
             }
         }
     }
     $this->getGResponse()->ProcessMerchantCalculations($merchantCalculations);
 }
 /**
  * Handle the merchant-calculations-callback request from google. This is for calculating post checkout
  * adjustments to the order total such as tax, shipping , gift certificates and coupon codes
  *
  * @param Array $data The parsed array of data representing the google request
  *
  * @return void
  **/
 private function HandleMerchantCallback($data)
 {
     $root = 'merchant-calculation-callback';
     $this->LoadCart($data[$root]['shopping-cart']['merchant-private-data']['VALUE']);
     include_once dirname(__FILE__) . '/library/googlemerchantcalculations.php';
     include_once dirname(__FILE__) . '/library/googleresult.php';
     $currency = GetDefaultCurrency();
     $merchant_calc = new GoogleMerchantCalculations($currency['currencycode']);
     $addresses = $this->get_arr_result($data[$root]['calculate']['addresses']['anonymous-address']);
     foreach ($addresses as $curr_address) {
         $curr_id = $curr_address['id'];
         $country = $curr_address['country-code']['VALUE'];
         $city = $curr_address['city']['VALUE'];
         $region = $curr_address['region']['VALUE'];
         $postal_code = $curr_address['postal-code']['VALUE'];
         // Loop through each shipping method if merchant-calculated shipping
         // support is to be provided
         if (isset($data[$root]['calculate']['shipping']['method'])) {
             $shipping = $this->get_arr_result($data[$root]['calculate']['shipping']['method']);
             foreach ($shipping as $curr_ship) {
                 $costs = $this->CalculateShippingCost($curr_address);
                 $name = $curr_ship['name'];
                 $zoneInfo = $costs['zone'];
                 unset($costs['zone']);
                 $merchant_result = new GoogleResult($curr_id);
                 $costs = current($costs);
                 $found = false;
                 $price = 0;
                 foreach ($costs as $key => $cost) {
                     if ($zoneInfo['zoneid'] == 1) {
                         $shipping_name = $cost['description'];
                     } else {
                         $shipping_name = $cost['description'] . ' (' . $zoneInfo['zonename'] . ')';
                     }
                     if ($name != $shipping_name) {
                         continue;
                     }
                     //Compute the price for this shipping method and address id
                     if (isset($cost['price'])) {
                         $price = $cost['price'];
                     }
                     $merchant_result->SetShippingDetails($name, $price, 'true');
                     $found = true;
                     break;
                 }
                 if (!$found) {
                     $merchant_result->SetShippingDetails($name, $price, 'false');
                 }
                 if ($data[$root]['calculate']['tax']['VALUE'] == "true") {
                     //Compute tax for this address id and shipping type
                     $amount = $this->RecalculateTax($data, $price, $name);
                     $merchant_result->SetTaxable(true);
                     $merchant_result->SetTaxDetails($amount);
                 }
                 if (isset($data[$root]['calculate']['merchant-code-strings']['merchant-code-string'])) {
                     $codes = $this->get_arr_result($data[$root]['calculate']['merchant-code-strings']['merchant-code-string']);
                     foreach ($codes as $curr_code) {
                         $giftcert = $this->ValidateGiftCertificate($curr_code['code'], $data);
                         if ($giftcert === false) {
                             $coupons = $this->ValidateCouponCode($curr_code['code'], $data);
                             $merchant_result->AddCoupons($coupons);
                         } else {
                             $merchant_result->AddGiftCertificates($giftcert);
                         }
                     }
                 }
                 $merchant_calc->AddResult($merchant_result);
             }
         } else {
             $merchant_result = new GoogleResult($curr_id);
             if ($data[$root]['calculate']['tax']['VALUE'] == "true") {
                 //Compute tax for this address id and shipping type
                 $amount = $this->RecalculateTax($data, 0, '');
                 $merchant_result->SetTaxable(true);
                 $merchant_result->SetTaxDetails($amount);
             }
             if (isset($data[$root]['calculate']['merchant-code-strings']['merchant-code-string'])) {
                 $codes = $this->get_arr_result($data[$root]['calculate']['merchant-code-strings']['merchant-code-string']);
                 foreach ($codes as $curr_code) {
                     $giftcert = $this->ValidateGiftCertificate($curr_code['code'], $data);
                     if ($giftcert === false) {
                         $coupons = $this->ValidateCouponCode($curr_code['code'], $data);
                         $merchant_result->AddCoupons($coupons);
                     } else {
                         $merchant_result->AddGiftCertificates($giftcert);
                     }
                 }
             }
             $merchant_calc->AddResult($merchant_result);
         }
     }
     $this->module->DebugLog($merchant_calc->GetXML());
     $this->response->ProcessMerchantCalculations($merchant_calc);
 }
Beispiel #7
0
 /**
  * Handle the merchant-calculations-callback request from google. This is for calculating post checkout
  * adjustments to the order total such as tax, shipping , gift certificates and coupon codes
  *
  * @param Array $data The parsed array of data representing the google request
  *
  * @return void
  **/
 private function HandleMerchantCallback($data)
 {
     $root = 'merchant-calculation-callback';
     $this->LoadCart($data[$root]['shopping-cart']['merchant-private-data']['VALUE']);
     include_once dirname(__FILE__) . '/library/googlemerchantcalculations.php';
     include_once dirname(__FILE__) . '/library/googleresult.php';
     $currency = GetDefaultCurrency();
     $merchant_calc = new GoogleMerchantCalculations($currency['currencycode']);
     $addresses = $this->get_arr_result($data[$root]['calculate']['addresses']['anonymous-address']);
     //mysql_query("INSERT INTO isc_orderlogs(ordervalue) VALUES ( 'addresses: ".print_r(count($addresses),true)."')");
     foreach ($addresses as $curr_address) {
         $curr_id = $curr_address['id'];
         $country = $curr_address['country-code']['VALUE'];
         $city = $curr_address['city']['VALUE'];
         $region = $curr_address['region']['VALUE'];
         $postal_code = $curr_address['postal-code']['VALUE'];
         // Loop through each shipping method if merchant-calculated shipping
         // support is to be provided
         if (isset($data[$root]['calculate']['shipping']['method'])) {
             $shipping = $this->get_arr_result($data[$root]['calculate']['shipping']['method']);
             foreach ($shipping as $curr_ship) {
                 $costs = $this->CalculateShippingCost($curr_address);
                 $name = $curr_ship['name'];
                 $zoneInfo = $costs['zone'];
                 unset($costs['zone']);
                 $merchant_result = new GoogleResult($curr_id);
                 $costs = current($costs);
                 $found = false;
                 $price = 0;
                 foreach ($costs as $key => $cost) {
                     if ($zoneInfo['zoneid'] == 1) {
                         $shipping_name = $cost['description'];
                     } else {
                         $shipping_name = $cost['description'] . ' (' . $zoneInfo['zonename'] . ')';
                     }
                     if ($name != $shipping_name) {
                         continue;
                     }
                     //Compute the price for this shipping method and address id
                     if (isset($cost['price'])) {
                         $price = $cost['price'];
                     }
                     $merchant_result->SetShippingDetails($name, $price, 'true');
                     $found = true;
                     break;
                 }
                 if (!$found) {
                     $merchant_result->SetShippingDetails($name, $price, 'false');
                 }
                 if ($data[$root]['calculate']['tax']['VALUE'] == "true") {
                     //Compute tax for this address id and shipping type
                     $amount = $this->RecalculateTax($data, $price, $name);
                     $merchant_result->SetTaxable(true);
                     $merchant_result->SetTaxDetails($amount);
                 }
                 if (isset($data[$root]['calculate']['merchant-code-strings']['merchant-code-string'])) {
                     $codes = $this->get_arr_result($data[$root]['calculate']['merchant-code-strings']['merchant-code-string']);
                     foreach ($codes as $curr_code) {
                         $giftcert = $this->ValidateGiftCertificate($curr_code['code'], $data);
                         if ($giftcert === false) {
                             $coupons = $this->ValidateCouponCode($curr_code['code'], $data, $cc_count = count($codes));
                             $merchant_result->AddCoupons($coupons);
                             /*if( count($codes) > 1 )
                             		{
                             			break;
                             		}*/
                         } else {
                             $merchant_result->AddGiftCertificates($giftcert);
                         }
                     }
                 } else {
                     if (isset($data[$root]['calculate']['merchant-code-strings']) && !isset($data[$root]['calculate']['merchant-code-strings']['merchant-code-string'])) {
                         $googlecheckoutflag = 0;
                         $sescouponvalue = $GLOBALS['ISC_CLASS_CART']->api->GetAppliedCouponCodes();
                         //mysql_query("INSERT INTO isc_orderlogs(ordervalue) VALUES ( 'ses 1: ".print_r($sescouponvalue,true)."')");
                         if (!empty($sescouponvalue)) {
                             foreach ($sescouponvalue as $ccid => $ccval) {
                                 if (array_key_exists('googlecheckout', $ccval)) {
                                     $GLOBALS['ISC_CLASS_CART']->api->RemoveCouponCode($ccval['couponid']);
                                     $googlecheckoutflag = 1;
                                 }
                             }
                             if ($googlecheckoutflag == 1) {
                                 $GLOBALS['ISC_CLASS_CART']->api->UpdateCartInformation();
                             }
                             //$temp_products = $GLOBALS['ISC_CLASS_CART']->api->GetProductsInCart();
                         }
                     }
                 }
                 $merchant_calc->AddResult($merchant_result);
             }
         } else {
             $merchant_result = new GoogleResult($curr_id);
             if ($data[$root]['calculate']['tax']['VALUE'] == "true") {
                 //Compute tax for this address id and shipping type
                 $amount = $this->RecalculateTax($data, 0, '');
                 $merchant_result->SetTaxable(true);
                 $merchant_result->SetTaxDetails($amount);
             }
             if (isset($data[$root]['calculate']['merchant-code-strings']['merchant-code-string'])) {
                 $codes = $this->get_arr_result($data[$root]['calculate']['merchant-code-strings']['merchant-code-string']);
                 foreach ($codes as $curr_code) {
                     $giftcert = $this->ValidateGiftCertificate($curr_code['code'], $data);
                     if ($giftcert === false) {
                         $coupons = $this->ValidateCouponCode($curr_code['code'], $data, $cc_count = count($codes));
                         $merchant_result->AddCoupons($coupons);
                         /*if( count($codes) > 1 )
                         		{
                         			break;
                         		}*/
                     } else {
                         $merchant_result->AddGiftCertificates($giftcert);
                     }
                 }
             } else {
                 if (isset($data[$root]['calculate']['merchant-code-strings']) && !isset($data[$root]['calculate']['merchant-code-strings']['merchant-code-string'])) {
                     $sescouponvalue = $GLOBALS['ISC_CLASS_CART']->api->GetAppliedCouponCodes();
                     //mysql_query("INSERT INTO isc_orderlogs(ordervalue) VALUES ( 'ses 2: ".print_r($sescouponvalue,true)."')");
                     if (!empty($sescouponvalue)) {
                         foreach ($sescouponvalue as $ccid => $ccval) {
                             if (array_key_exists('googlecheckout', $ccval)) {
                                 $GLOBALS['ISC_CLASS_CART']->api->RemoveCouponCode($ccval['couponid']);
                                 $googlecheckoutflag = 1;
                             }
                         }
                         if ($googlecheckoutflag == 1) {
                             $GLOBALS['ISC_CLASS_CART']->api->UpdateCartInformation();
                         }
                         //$temp_products = $GLOBALS['ISC_CLASS_CART']->api->GetProductsInCart();
                     }
                 }
             }
             $merchant_calc->AddResult($merchant_result);
         }
     }
     $this->module->DebugLog($merchant_calc->GetXML());
     $this->response->ProcessMerchantCalculations($merchant_calc);
 }
Beispiel #8
0
	/**
	 * Handle the merchant-calculations-callback request from google. This is for calculating post checkout
	 * adjustments to the order total such as tax, shipping , gift certificates and coupon codes
	 *
	 * @param Array $data The parsed array of data representing the google request
	 *
	 * @return void
	 **/
	private function HandleMerchantCallback($data)
	{
		include_once(dirname(__FILE__).'/library/googlemerchantcalculations.php');
		include_once(dirname(__FILE__).'/library/googleresult.php');
		include_once(dirname(__FILE__).'/class.merchantcalculationsrequest.php');

		$request = new GOOGLE_CHECKOUT_MERCHANT_CALCULATIONS_REQUEST($data);
		$merchantCalculations = new GoogleMerchantCalculations();

		// initialize the quote
		$this->LoadCart($request->getCartSessionId());
		$this->quote->removeAllGiftCertificates();
		$this->quote->setIsSplitShipping(false);

		foreach($request->getAnonymousAddresses() as $address) {
			$this->merchantCalculationsSetAddress($address);

			if(count($shippingMethods = $request->getShippingMethods()) > 0) {
				// have shipping methods, create a result for each one

				foreach($shippingMethods as $method) {
					$result = $this->merchantCalculationResult($request, $address, $method);
					$merchantCalculations->AddResult($result);
				}
			} else {
				$result = $this->merchantCalculationResult($request, $address);
				$merchantCalculations->AddResult($result);
			}

			$this->quote->removeAllAddresses();
		}

		$this->module->DebugLog($merchantCalculations->GetXML());
		$this->response->ProcessMerchantCalculations($merchantCalculations);
	}
Beispiel #9
0
 function googlecheckoutresponsehandler()
 {
     //chdir("..");
     require_once 'library/googleresponse.php';
     require_once 'library/googlemerchantcalculations.php';
     require_once 'library/googleresult.php';
     require_once 'library/googlerequest.php';
     $this->load->model('payment_model');
     $paymentGateways_google = $this->payment_model->getGooglecheckoutsettings();
     $base_url = $base_url();
     define('RESPONSE_HANDLER_ERROR_LOG_FILE', $base_url . 'googlelog/googleerror.log');
     define('RESPONSE_HANDLER_LOG_FILE', $base_url . 'googlelog/googlemessage.log');
     /*
     		  $merchant_id = "";  // Your Merchant ID
     		  $merchant_key = "";  // Your Merchant Key
     		  $server_type = "sandbox";  // change this to go live
     */
     $merchant_id = $paymentGateways_google['googlecheckout']['merchant_id'];
     // Your Merchant ID
     $merchant_key = $paymentGateways_google['googlecheckout']['merchant_key'];
     // Your Merchant Key
     $server_type = $paymentGateways_google['googlecheckout']['server_type'];
     $currency = 'USD';
     // set to GBP if in the UK
     $Gresponse = new GoogleResponse($merchant_id, $merchant_key);
     $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency);
     //Setup the log file
     $Gresponse->SetLogFiles(RESPONSE_HANDLER_ERROR_LOG_FILE, RESPONSE_HANDLER_LOG_FILE, L_ALL);
     // Retrieve the XML sent in the HTTP POST request to the ResponseHandler
     $xml_response = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input");
     if (get_magic_quotes_gpc()) {
         $xml_response = stripslashes($xml_response);
     }
     list($root, $data) = $Gresponse->GetParsedXML($xml_response);
     $Gresponse->SetMerchantAuthentication($merchant_id, $merchant_key);
     $status = $Gresponse->HttpAuthentication();
     if (!$status) {
         die('authentication failed');
     }
     /* Commands to send the various order processing APIs
      * Send charge order : $Grequest->SendChargeOrder($data[$root]
      *    ['google-order-number']['VALUE'], <amount>);
      * Send process order : $Grequest->SendProcessOrder($data[$root]
      *    ['google-order-number']['VALUE']);
      * Send deliver order: $Grequest->SendDeliverOrder($data[$root]
      *    ['google-order-number']['VALUE'], <carrier>, <tracking-number>,
      *    <send_mail>);
      * Send archive order: $Grequest->SendArchiveOrder($data[$root]
      *    ['google-order-number']['VALUE']);
      *
      */
     switch ($root) {
         case "request-received":
             break;
         case "error":
             break;
         case "diagnosis":
             break;
         case "checkout-redirect":
             break;
         case "merchant-calculation-callback":
             // Create the results and send it
             $merchant_calc = new GoogleMerchantCalculations($currency);
             // Loop through the list of address ids from the callback
             $addresses = get_arr_result($data[$root]['calculate']['addresses']['anonymous-address']);
             foreach ($addresses as $curr_address) {
                 $curr_id = $curr_address['id'];
                 $country = $curr_address['country-code']['VALUE'];
                 $city = $curr_address['city']['VALUE'];
                 $region = $curr_address['region']['VALUE'];
                 $postal_code = $curr_address['postal-code']['VALUE'];
                 // Loop through each shipping method if merchant-calculated shipping
                 // support is to be provided
                 if (isset($data[$root]['calculate']['shipping'])) {
                     $shipping = get_arr_result($data[$root]['calculate']['shipping']['method']);
                     foreach ($shipping as $curr_ship) {
                         $name = $curr_ship['name'];
                         //Compute the price for this shipping method and address id
                         $price = 12;
                         // Modify this to get the actual price
                         $shippable = "true";
                         // Modify this as required
                         $merchant_result = new GoogleResult($curr_id);
                         $merchant_result->SetShippingDetails($name, $price, $shippable);
                         if ($data[$root]['calculate']['tax']['VALUE'] == "true") {
                             //Compute tax for this address id and shipping type
                             $amount = 15;
                             // Modify this to the actual tax value
                             $merchant_result->SetTaxDetails($amount);
                         }
                         if (isset($data[$root]['calculate']['merchant-code-strings']['merchant-code-string'])) {
                             $codes = get_arr_result($data[$root]['calculate']['merchant-code-strings']['merchant-code-string']);
                             foreach ($codes as $curr_code) {
                                 //Update this data as required to set whether the coupon is valid, the code and the amount
                                 $coupons = new GoogleCoupons("true", $curr_code['code'], 5, "test2");
                                 $merchant_result->AddCoupons($coupons);
                             }
                         }
                         $merchant_calc->AddResult($merchant_result);
                     }
                 } else {
                     $merchant_result = new GoogleResult($curr_id);
                     if ($data[$root]['calculate']['tax']['VALUE'] == "true") {
                         //Compute tax for this address id and shipping type
                         $amount = 15;
                         // Modify this to the actual tax value
                         $merchant_result->SetTaxDetails($amount);
                     }
                     $codes = get_arr_result($data[$root]['calculate']['merchant-code-strings']['merchant-code-string']);
                     foreach ($codes as $curr_code) {
                         //Update this data as required to set whether the coupon is valid, the code and the amount
                         $coupons = new GoogleCoupons("true", $curr_code['code'], 5, "test2");
                         $merchant_result->AddCoupons($coupons);
                     }
                     $merchant_calc->AddResult($merchant_result);
                 }
             }
             $Gresponse->ProcessMerchantCalculations($merchant_calc);
             break;
         case "new-order-notification":
             $Gresponse->SendAck();
             break;
         case "order-state-change-notification":
             $Gresponse->SendAck();
             $new_financial_state = $data[$root]['new-financial-order-state']['VALUE'];
             $new_fulfillment_order = $data[$root]['new-fulfillment-order-state']['VALUE'];
             $test = array('status' => $new_financial_state);
             $this->common_model->insert('test', $test);
             switch ($new_financial_state) {
                 case 'REVIEWING':
                     break;
                 case 'CHARGEABLE':
                     //$Grequest->SendProcessOrder($data[$root]['google-order-number']['VALUE']);
                     //$Grequest->SendChargeOrder($data[$root]['google-order-number']['VALUE'],'');
                     break;
                 case 'CHARGING':
                     break;
                 case 'CHARGED':
                     break;
                 case 'PAYMENT_DECLINED':
                     break;
                 case 'CANCELLED':
                     break;
                 case 'CANCELLED_BY_GOOGLE':
                     //$Grequest->SendBuyerMessage($data[$root]['google-order-number']['VALUE'],
                     //    "Sorry, your order is cancelled by Google", true);
                     break;
                 default:
                     break;
             }
             switch ($new_fulfillment_order) {
                 case 'NEW':
                     break;
                 case 'PROCESSING':
                     break;
                 case 'DELIVERED':
                     break;
                 case 'WILL_NOT_DELIVER':
                     break;
                 default:
                     break;
             }
             break;
         case "charge-amount-notification":
             //$Grequest->SendDeliverOrder($data[$root]['google-order-number']['VALUE'],
             //    <carrier>, <tracking-number>, <send-email>);
             //$Grequest->SendArchiveOrder($data[$root]['google-order-number']['VALUE'] );
             $Gresponse->SendAck();
             break;
         case "chargeback-amount-notification":
             $Gresponse->SendAck();
             break;
         case "refund-amount-notification":
             $Gresponse->SendAck();
             break;
         case "risk-information-notification":
             $Gresponse->SendAck();
             break;
         default:
             $Gresponse->SendBadRequestStatus("Invalid or not supported Message");
             break;
     }
     /* In case the XML API contains multiple open tags
     		 with the same value, then invoke this function and
     		 perform a foreach on the resultant array.
     		 This takes care of cases when there is only one unique tag
     		 or multiple tags.
     		 Examples of this are "anonymous-address", "merchant-code-string"
     		 from the merchant-calculations-callback API
     	  */
 }
Beispiel #10
0
 function callback($in, &$paymentId, &$money, &$message)
 {
     ##chdir("..");
     define('RESPONSE_HANDLER_LOG_FILE', 'googlemessage.log');
     //Setup the log file
     if (!($message_log = fopen(RESPONSE_HANDLER_LOG_FILE, "a"))) {
         $message = "Cannot open " . RESPONSE_HANDLER_LOG_FILE . " file.";
         return PAY_ERROR;
     }
     // Retrieve the XML sent in the HTTP POST request to the ResponseHandler
     $xml_response = $HTTP_RAW_POST_DATA;
     if (get_magic_quotes_gpc()) {
         $xml_response = stripslashes($xml_response);
     }
     $headers = getallheaders();
     fwrite($message_log, sprintf("\n\r%s:- %s\n", date("D M j G:i:s T Y"), $xml_response));
     $merchant_key = $this->getConf($in["M_OrderId"], 'PrivateKey');
     //todo支付号没有
     // Create new response object
     //$merchant_id = "";  //Your Merchant ID
     //$merchant_key = "";  //Your Merchant Key
     $server_type = "checkout";
     $response = new GoogleResponse($merchant_id, $merchant_key, $xml_response, $server_type);
     $root = $response->root;
     $data = $response->data;
     fwrite($message_log, sprintf("\n\r%s:- %s\n", date("D M j G:i:s T Y"), $response->root));
     //Use the following two lines to log the associative array storing the XML data
     //$result = print_r($data,true);
     //fwrite($message_log, sprintf("\n\r%s:- %s\n",date("D M j G:i:s T Y"),$result));
     //Check status and take appropriate action
     $status = $response->HttpAuthentication($headers);
     /* Commands to send the various order processing APIs
      * Send charge order : $response->SendChargeOrder($data[$root]
      *    ['google-order-number']['VALUE'], <amount>, $message_log);
      * Send proces order : $response->SendProcessOrder($data[$root]
      *    ['google-order-number']['VALUE'], $message_log);
      * Send deliver order: $response->SendDeliverOrder($data[$root]
      *    ['google-order-number']['VALUE'], <carrier>, <tracking-number>,
      *    <send_mail>, $message_log);
      * Send archive order: $response->SendArchiveOrder($data[$root]
      *    ['google-order-number']['VALUE'], $message_log);
      *
      */
     switch ($root) {
         case "request-received":
             break;
         case "error":
             break;
         case "diagnosis":
             break;
         case "checkout-redirect":
             break;
         case "merchant-calculation-callback":
             // Create the results and send it
             $merchant_calc = new GoogleMerchantCalculations();
             // Loop through the list of address ids from the callback
             $addresses = $this->get_arr_result($data[$root]['calculate']['addresses']['anonymous-address']);
             foreach ($addresses as $curr_address) {
                 $curr_id = $curr_address['id'];
                 $country = $curr_address['country-code']['VALUE'];
                 $city = $curr_address['city']['VALUE'];
                 $region = $curr_address['region']['VALUE'];
                 $postal_code = $curr_address['region']['VALUE'];
                 // Loop through each shipping method if merchant-calculated shipping
                 // support is to be provided
                 if (isset($data[$root]['calculate']['shipping'])) {
                     $shipping = $this->get_arr_result($data[$root]['calculate']['shipping']['method']);
                     foreach ($shipping as $curr_ship) {
                         $name = $curr_ship['name'];
                         //Compute the price for this shipping method and address id
                         $price = 10;
                         // Modify this to get the actual price
                         $shippable = "true";
                         // Modify this as required
                         $merchant_result = new GoogleResult($curr_id);
                         $merchant_result->SetShippingDetails($name, $price, "USD", $shippable);
                         if ($data[$root]['calculate']['tax']['VALUE'] == "true") {
                             //Compute tax for this address id and shipping type
                             $amount = 15;
                             // Modify this to the actual tax value
                             $merchant_result->SetTaxDetails($amount, "USD");
                         }
                         $codes = $this->get_arr_result($data[$root]['calculate']['merchant-code-strings']['merchant-code-string']);
                         foreach ($codes as $curr_code) {
                             //Update this data as required to set whether the coupon is valid, the code and the amount
                             $coupons = new GoogleCoupons("true", $curr_code['code'], 5, "USD", "test2");
                             $merchant_result->AddCoupons($coupons);
                         }
                         $merchant_calc->AddResult($merchant_result);
                     }
                 } else {
                     $merchant_result = new GoogleResult($curr_id);
                     if ($data[$root]['calculate']['tax']['VALUE'] == "true") {
                         //Compute tax for this address id and shipping type
                         $amount = 15;
                         // Modify this to the actual tax value
                         $merchant_result->SetTaxDetails($amount, "USD");
                     }
                     $codes = $this->get_arr_result($data[$root]['calculate']['merchant-code-strings']['merchant-code-string']);
                     foreach ($codes as $curr_code) {
                         //Update this data as required to set whether the coupon is valid, the code and the amount
                         $coupons = new GoogleCoupons("true", $curr_code['code'], 5, "USD", "test2");
                         $merchant_result->AddCoupons($coupons);
                     }
                     $merchant_calc->AddResult($merchant_result);
                 }
             }
             fwrite($message_log, sprintf("\n\r%s:- %s\n", date("D M j G:i:s T Y"), $merchant_calc->GetXML()));
             $response->ProcessMerchantCalculations($merchant_calc);
             break;
         case "new-order-notification":
             $response->SendAck();
             break;
         case "order-state-change-notification":
             $response->SendAck();
             $new_financial_state = $data[$root]['new-financial-order-state']['VALUE'];
             $new_fulfillment_order = $data[$root]['new-fulfillment-order-state']['VALUE'];
             switch ($new_financial_state) {
                 case 'REVIEWING':
                     break;
                 case 'CHARGEABLE':
                     //$response->SendProcessOrder($data[$root]['google-order-number']['VALUE'],
                     //    $message_log);
                     //$response->SendChargeOrder($data[$root]['google-order-number']['VALUE'],
                     //    '', $message_log);
                     break;
                 case 'CHARGING':
                     break;
                 case 'CHARGED':
                     break;
                 case 'PAYMENT_DECLINED':
                     break;
                 case 'CANCELLED':
                     break;
                 case 'CANCELLED_BY_GOOGLE':
                     //$response->SendBuyerMessage($data[$root]['google-order-number']['VALUE'],
                     //    "Sorry, your order is cancelled by Google", true, $message_log);
                     break;
                 default:
                     break;
             }
             switch ($new_fulfillment_order) {
                 case 'NEW':
                     break;
                 case 'PROCESSING':
                     break;
                 case 'DELIVERED':
                     break;
                 case 'WILL_NOT_DELIVER':
                     break;
                 default:
                     break;
             }
         case "charge-amount-notification":
             $response->SendAck();
             //$response->SendDeliverOrder($data[$root]['google-order-number']['VALUE'],
             //    <carrier>, <tracking-number>, <send-email>, $message_log);
             //$response->SendArchiveOrder($data[$root]['google-order-number']['VALUE'],
             //    $message_log);
             break;
         case "chargeback-amount-notification":
             $response->SendAck();
             break;
         case "refund-amount-notification":
             $response->SendAck();
             break;
         case "risk-information-notification":
             $response->SendAck();
             break;
         default:
             break;
     }
     return PAY_SUCCESS;
     ##
 }
Beispiel #11
0
function process_merchant_calculation_callback_single($Gresponse)
{
    global $googlepayment, $order, $db, $total_weight, $total_count;
    list($root, $data) = $Gresponse->GetParsedXML();
    $currencies = new currencies();
    $cart = $_SESSION['cart'];
    $methods_hash = $googlepayment->getMethods();
    require DIR_WS_CLASSES . 'order.php';
    $order = new order();
    // Register a random ID in the session to check throughout the checkout procedure
    // against alterations in the shopping cart contents.
    //  if (!tep_session_is_registered('cartID')) {
    //  tep_session_register('cartID');
    // }
    //  $cartID = $cart->cartID;
    $items = get_arr_result($data[$root]['shopping-cart']['items']['item']);
    $products = array();
    foreach ($items as $item) {
        if (isset($item['merchant-private-item-data']['item']['VALUE'])) {
            $products[] = unserialize(base64_decode($item['merchant-private-item-data']['item']['VALUE']));
        }
    }
    $order->products = $products;
    $total_weight = $cart->show_weight();
    $total_count = $cart->count_contents();
    // Create the results and send it
    $merchant_calc = new GoogleMerchantCalculations(DEFAULT_CURRENCY);
    // Loop through the list of address ids from the callback.
    $addresses = get_arr_result($data[$root]['calculate']['addresses']['anonymous-address']);
    // Get all the enabled shipping methods.
    require DIR_WS_CLASSES . 'shipping.php';
    // Required for some shipping methods (ie. USPS).
    require_once 'includes/classes/http_client.php';
    foreach ($addresses as $curr_address) {
        // Set up the order address.
        $curr_id = $curr_address['id'];
        $country = $curr_address['country-code']['VALUE'];
        $city = $curr_address['city']['VALUE'];
        $region = $curr_address['region']['VALUE'];
        $postal_code = $curr_address['postal-code']['VALUE'];
        $countr_query = $db->Execute("select * \n                     from " . TABLE_COUNTRIES . " \n                     where countries_iso_code_2 = '" . makeSqlString($country) . "'");
        $row = $countr_query->fields;
        $order->delivery['country'] = array('id' => $row['countries_id'], 'title' => $row['countries_name'], 'iso_code_2' => $country, 'iso_code_3' => $row['countries_iso_code_3']);
        $order->delivery['country_id'] = $row['countries_id'];
        $order->delivery['format_id'] = $row['address_format_id'];
        $zone_query = $db->Execute("select * \n        \t\t                               from " . TABLE_ZONES . "\n        \t\t                               where zone_code = '" . makeSqlString($region) . "'");
        $row = $zone_query->fields;
        $order->delivery['zone_id'] = $row['zone_id'];
        $order->delivery['state'] = $row['zone_name'];
        $order->delivery['city'] = $city;
        $order->delivery['postcode'] = $postal_code;
        $shipping_modules = new shipping();
        // Loop through each shipping method if merchant-calculated shipping
        // support is to be provided
        //print_r($data[$root]['calculate']['shipping']['method']);
        if (isset($data[$root]['calculate']['shipping']['method'])) {
            $shipping = get_arr_result($data[$root]['calculate']['shipping']['method']);
            //      if (MODULE_PAYMENT_GOOGLECHECKOUT_MULTISOCKET == 'True') {
            //        // Single
            //        // i get all the enabled shipping methods
            //        $name = $shipping[0]['name'];
            //        //            Compute the price for this shipping method and address id
            //        list ($a, $method_name) = explode(': ', $name);
            //        if ((($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY)
            //              && ($methods_hash[$method_name][1] == 'domestic_types'))
            //           || (($order->delivery['country']['id'] != SHIPPING_ORIGIN_COUNTRY)
            //              && ($methods_hash[$method_name][1] == 'international_types'))) {
            //          //								reset the shipping class to set the new address
            //          if (class_exists($methods_hash[$method_name][2])) {
            //            $GLOBALS[$methods_hash[$method_name][2]] = new $methods_hash[$method_name][2];
            //          }
            //        }
            //        $quotes = $shipping_modules->quote('', $methods_hash[$method_name][2]);
            //      } else {
            // Standard
            foreach ($shipping as $curr_ship) {
                $name = $curr_ship['name'];
                //            Compute the price for this shipping method and address id
                list($a, $method_name) = explode(': ', $name, 2);
                if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY && $methods_hash[$method_name][1] == 'domestic_types' || $order->delivery['country']['id'] != SHIPPING_ORIGIN_COUNTRY && $methods_hash[$method_name][1] == 'international_types') {
                    //								reset the shipping class to set the new address
                    if (class_exists($methods_hash[$method_name][2])) {
                        $GLOBALS[$methods_hash[$method_name][2]] = new $methods_hash[$method_name][2]();
                    }
                }
            }
            $quotes = $shipping_modules->quote();
            //      }
            reset($shipping);
            foreach ($shipping as $curr_ship) {
                $name = $curr_ship['name'];
                //            Compute the price for this shipping method and address id
                list($a, $method_name) = explode(': ', $name, 2);
                unset($quote_povider);
                unset($quote_method);
                if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY && $methods_hash[$method_name][1] == 'domestic_types' || $order->delivery['country']['id'] != SHIPPING_ORIGIN_COUNTRY && $methods_hash[$method_name][1] == 'international_types') {
                    foreach ($quotes as $key_provider => $shipping_provider) {
                        // privider name (class)
                        if ($shipping_provider['id'] == $methods_hash[$method_name][2]) {
                            // method name
                            $quote_povider = $key_provider;
                            if (is_array($shipping_provider['methods'])) {
                                foreach ($shipping_provider['methods'] as $key_method => $shipping_method) {
                                    if ($shipping_method['id'] == $methods_hash[$method_name][0]) {
                                        $quote_method = $key_method;
                                        break;
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
                //if there is a problem with the method, i mark it as non-shippable
                if (isset($quotes[$quote_povider]['error']) || !isset($quotes[$quote_povider]['methods'][$quote_method]['cost'])) {
                    $price = "9999.09";
                    $shippable = "false";
                } else {
                    $price = $quotes[$quote_povider]['methods'][$quote_method]['cost'];
                    $shippable = "true";
                }
                // fix for item shipping function bug if called more than once in a session.
                $price = $price >= 0 ? $price : 0;
                $merchant_result = new GoogleResult($curr_id);
                $merchant_result->SetShippingDetails($name, $currencies->get_value(DEFAULT_CURRENCY) * $price, $shippable);
                if ($data[$root]['calculate']['tax']['VALUE'] == "true") {
                    //Compute tax for this address id and shipping type
                    $amount = 15;
                    // Modify this to the actual tax value
                    $merchant_result->SetTaxDetails($currencies->get_value(DEFAULT_CURRENCY) * $amount);
                }
                ////							 start cupons and gift processing (working)
                //								// only one coupon per order is valid!
                //                $_POST['dc_redeem_code'] = 'ROPU';
                //
                ////                require(DIR_WS_CLASSES . 'order.php');
                ////                $order = new order;
                //                require_once(DIR_WS_CLASSES . 'order_total.php');
                //                $order_total_modules = new order_total;
                ////                $order_total_modules->collect_posts();
                ////                $order_total_modules->pre_confirmation_check();
                //
                ////                print_r($order_total_modules);
                //                   $order_totals = $order_total_modules->process();
                ////                print_r($order_totals);
                //
                calculate_coupons($Gresponse, $merchant_result, $price);
                // end cupons
                $merchant_calc->AddResult($merchant_result);
            }
        } else {
            $merchant_result = new GoogleResult($curr_id);
            if ($data[$root]['calculate']['tax']['VALUE'] == "true") {
                //Compute tax for this address id and shipping type
                $amount = 15;
                // Modify this to the actual tax value
                $merchant_result->SetTaxDetails($currencies->get_value(DEFAULT_CURRENCY) * $amount);
            }
            calculate_coupons($Gresponse, $merchant_result);
            $merchant_calc->AddResult($merchant_result);
        }
    }
    $Gresponse->ProcessMerchantCalculations($merchant_calc);
}
Beispiel #12
0
 protected function _responseMerchantCalculationCallback()
 {
     $quoteId = $this->getData('root/shopping-cart/merchant-private-data/quote-id/VALUE');
     $quote = Mage::getModel('sales/quote')->load($quoteId);
     $address = $quote->getShippingAddress();
     $googleAddress = $this->getData('root/calculate/addresses/anonymous-address');
     $addressId = $googleAddress['id'];
     $address->setCountryId($googleAddress['country-code']['VALUE'])->setRegion($googleAddress['region']['VALUE'])->setCity($googleAddress['city']['VALUE'])->setPostcode($googleAddress['postal-code']['VALUE']);
     $merchantCalculations = new GoogleMerchantCalculations($this->getCurrency());
     if ($gRequestMethods = $this->getData('root/calculate/shipping/method')) {
         $carriers = array();
         foreach (Mage::getStoreConfig('carriers') as $carrierCode => $carrierConfig) {
             foreach ($gRequestMethods as $method) {
                 $title = (string) $carrierConfig->title;
                 if ($title && strpos($method['name'], $title) === 0) {
                     $carriers[$carrierCode] = $title;
                 }
             }
         }
         $result = Mage::getModel('shipping/shipping')->collectRatesByAddress($address, array_keys($carriers))->getResult();
         $errors = array();
         $rates = array();
         foreach ($result->getAllRates() as $rate) {
             if ($rate instanceof Mage_Shipping_Model_Rate_Result_Error) {
                 $errors[$rate->getCarrierTitle()] = 1;
             } else {
                 $rates[$rate->getCarrierTitle() . ' - ' . $rate->getMethodTitle()] = $rate->getPrice();
             }
         }
         foreach ($gRequestMethods as $method) {
             $methodName = $method['name'];
             $result = new GoogleResult($addressId);
             if (!empty($errors)) {
                 $continue = false;
                 foreach ($errors as $carrier => $dummy) {
                     if (strpos($methodName, $carrier) === 0) {
                         $result->SetShippingDetails($methodName, 0, "false");
                         $merchantCalculations->AddResult($result);
                         $continue = true;
                         break;
                     }
                 }
                 if ($continue) {
                     continue;
                 }
             }
             if (!empty($rates[$methodName])) {
                 $result->SetShippingDetails($methodName, $rates[$methodName], "true");
                 $merchantCalculations->AddResult($result);
             }
         }
     }
     if ($this->getData('root/calculate/tax/VALUE') == 'true') {
         $address->setCollectShippingRates(false)->collectTotals();
         $taxAmount = $address->getTaxAmount();
         $result = new GoogleResult($addressId);
         $result->setTaxDetails($taxAmount);
         $merchantCalculations->addResult($result);
     }
     $this->getGResponse()->ProcessMerchantCalculations($merchantCalculations);
 }