}
                 $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 GoogleGiftcerts("true", $curr_code['code'], 10, "debugtest");
                 $merchant_result->AddGiftCertificates($coupons);
             }
             $merchant_calc->AddResult($merchant_result);
         }
     }
     $Gresponse->ProcessMerchantCalculations($merchant_calc);
     break;
 case "new-order-notification":
     $email = $data[$root]['buyer-billing-address']['email']['VALUE'];
     $date = $data[$root]['timestamp']['VALUE'];
     $ordernumber = $data[$root]['google-order-number']['VALUE'];
     $financialstate = $data[$root]['financial-order-state']['VALUE'];
     $fulfillmentstate = $data[$root]['fulfillment-order-state']['VALUE'];
     $total = $data[$root]['order-total']['VALUE'];
     $purchasedate = date(DATE_ATOM, strtotime($date));
     $Gresponse->log->LogResponse("Default timezone " . date_default_timezone_get());
 /**
  * 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);
 }
Example #3
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);
 }
Example #4
0
	/**
	 * Set correct data on the Google Checkout page
	 *
	 * 1. Applied coupons and gift certificates
	 * 2. Shipping rates for each available shipping method, affected by
	 *      coupon - Dollar amount off the shipping total
	 *      coupon - Free shipping
	 * 3. Tax
	 *
	 * @param object $request GOOGLE_CHECKOUT_MERCHANT_CALCULATIONS_REQUEST
	 * @param array  $address Shipping address info
	 * @param array  $method  Shipping method info
	 *
	 * @return object Google result
	 */
	private function merchantCalculationResult($request, $address, $method=null)
	{
		$result = new GoogleResult($address['id']);
		$shippingAddress = $this->quote->getShippingAddress();

		$rates = $this->getShippingRates($address);
		$methodDisabled = false;
		if (isset($method['name'])) {
			$methodName = $method['name'];

			if (isset($rates[$methodName])) {
				// shipping discount from coupon entered on cart.php
				$rate = $rates[$methodName];
				$shippingAddress->setShippingMethod($rate['price'], $methodName, $rate['module']);
				$this->quote->reapplyCoupons();
				$rate['price'] -= $shippingAddress->getDiscountAmount();
			} else {
				// this shipping method is not available
				$result->SetShippingDetails($methodName, 0, 'false');
				$methodDisabled = true;
			}
		}

		// Coupons (normal or discounted shipping)
		$shippingDiscount = 0;
		foreach($request->couponCodes as $code) {
			$discountBefore = $shippingAddress->getDiscountAmount();
			$coupon = $this->applyCouponCode($code);
			$discountAfter = $shippingAddress->getDiscountAmount();
			if ($discountAfter > $discountBefore) {
				// a shipping discount coupon
				$shippingDiscount += ($discountAfter - $discountBefore);
				$googleCoupon = new GoogleCoupons('true', $code, 0, getLang('GoogleCheckoutDiscountShipping'));
				$result->AddCoupons($googleCoupon);
			} else {
				$result->AddCoupons($coupon);
			}
		}

		if (!$methodDisabled) {
			$result->SetShippingDetails(
				$methodName,
				($rate['price'] - $shippingDiscount),
				'true'
			);
		}

		// Gift certificates
		foreach($request->certificateCodes as $code) {
			$certificate = $this->applyGiftCertificateCode($code);
			$result->AddGiftCertificates($certificate);
		}

		// Tax details
		if($request->getTax()) {
			$result->SetTaxDetails($this->quote->getTaxTotal());
		}

		// Cleanup
		$this->removeAppliedCouponsAndGiftCertificates();
		$shippingAddress->invalidateCachedTotals();

		return $result;
	}