Example #1
0
	function notifications () {
		if ($this->authentication()) {

			// Read incoming request data
			$data = trim(file_get_contents('php://input'));
			if(ECART_DEBUG) new EcartError($data,'google_incoming_request',ECART_DEBUG_ERR);

			// Handle notifications
			$XML = new xmlQuery($data);
			$type = $XML->context();
			if ( $type === false ) {
				if(ECART_DEBUG) new EcartError('Unable to determine context of request.','google_checkout_unknown_notification',ECART_DEBUG_ERR);
				return;
			}
			$serial = $XML->attr($type,'serial-number');

			$ack = true;
			switch($type) {
				case "new-order-notification": $this->order($XML); break;
				case "risk-information-notification": $this->risk($XML); break;
				case "order-state-change-notification": $this->state($XML); break;
				case "merchant-calculation-callback": $ack = $this->merchant_calc($XML); break;
				case "charge-amount-notification":	break;		// Not implemented
				case "refund-amount-notification":	$this->refund($XML); break;
				case "chargeback-amount-notification":		break;	// Not implemented
				case "authorization-amount-notification":	break;	// Not implemented
					break;
			}
			// Send acknowledgement
			if($ack) $this->acknowledge($serial);
		}
		exit();
	}
Example #2
0
 public function upload()
 {
     if (!isset($_FILES['ratefile'])) {
         return false;
     }
     $upload = $_FILES['ratefile'];
     $filename = $upload['tmp_name'];
     if (empty($filename) && empty($upload['name']) && !isset($_POST['upload'])) {
         return false;
     }
     $error = false;
     if ($upload['error'] != 0) {
         return $this->notice(ShoppLookup::errors('uploads', $upload['error']));
     }
     if (!is_readable($filename)) {
         return $this->notice(ShoppLookup::errors('uploadsecurity', 'is_readable'));
     }
     if (empty($upload['size'])) {
         return $this->notice(ShoppLookup::errors('uploadsecurity', 'is_empty'));
     }
     if ($upload['size'] != filesize($filename)) {
         return $this->notice(ShoppLookup::errors('uploadsecurity', 'filesize_mismatch'));
     }
     if (!is_uploaded_file($filename)) {
         return $this->notice(ShoppLookup::errors('uploadsecurity', 'is_uploaded_file'));
     }
     $data = file_get_contents($upload['tmp_name']);
     $cr = array("\r\n", "\r");
     $formats = array(0 => false, 3 => 'xml', 4 => 'tab', 5 => 'csv');
     preg_match('/((<[^>]+>.+?<\\/[^>]+>)|(.+?\\t.+?[\\n|\\r])|(.+?,.+?[\\n|\\r]))/', $data, $_);
     $format = $formats[count($_)];
     if (!$format) {
         return $this->notice(Shopp::__('The uploaded file is not properly formatted as an XML, CSV or tab-delimmited file.'));
     }
     $_ = array();
     switch ($format) {
         case 'xml':
             /*
             Example XML import file:
             	<localtaxrates>
             		<taxrate name="Kent">1</taxrate>
             		<taxrate name="New Castle">0.25</taxrate>
             		<taxrate name="Sussex">1.4</taxrate>
             	</localtaxrates>
             
             Taxrate record format:
             	<taxrate name="(Name of locality)">(Percentage of the supplemental tax)</taxrate>
             
             Tax rate percentages should be represented as percentage numbers, not decimal percentages:
             	1.25	= 1.25%	(0.0125)
             	10		= 10%	(0.1)
             */
             $XML = new xmlQuery($data);
             $taxrates = $XML->tag('taxrate');
             while ($rate = $taxrates->each()) {
                 $name = $rate->attr(false, 'name');
                 $value = $rate->content();
                 $_[$name] = $value;
             }
             break;
         case 'csv':
             ini_set('auto_detect_line_endings', true);
             if (($csv = fopen($upload['tmp_name'], 'r')) === false) {
                 return $this->notice(ShoppLookup::errors('uploadsecurity', 'is_readable'));
             }
             while (($data = fgetcsv($csv, 1000)) !== false) {
                 $_[$data[0]] = !empty($data[1]) ? $data[1] : 0;
             }
             fclose($csv);
             ini_set('auto_detect_line_endings', false);
             break;
         case 'tab':
         default:
             $data = str_replace($cr, "\n", $data);
             $lines = explode("\n", $data);
             foreach ($lines as $line) {
                 list($key, $value) = explode("\t", $line);
                 $_[$key] = $value;
             }
     }
     if (empty($_)) {
         return $this->notice(Shopp::__('No useable tax rates could be found. The uploaded file may not be properly formatted.'));
     }
     $id = $_POST['id'];
     $rates = shopp_setting('taxrates');
     $rates[$id]['locals'] = apply_filters('shopp_local_taxrates_upload', $_);
     shopp_set_setting('taxrates', $rates);
 }
Example #3
0
	function upload_local_taxes () {
		check_admin_referer('wp_ajax_ecart_upload_local_taxes');
		if (isset($_FILES['ecart']['error'])) $error = $_FILES['ecart']['error'];
		if ($error) die(json_encode(array("error" => $this->uploadErrors[$error])));

		if (!is_uploaded_file($_FILES['ecart']['tmp_name']))
			die(json_encode(array("error" => __('The file could not be saved because the upload was not found on the server.','Ecart'))));

		if (!is_readable($_FILES['ecart']['tmp_name']))
			die(json_encode(array("error" => __('The file could not be saved because the web server does not have permission to read the upload.','Ecart'))));

		if ($_FILES['ecart']['size'] == 0)
			die(json_encode(array("error" => __('The file could not be saved because the uploaded file is empty.','Ecart'))));

		$data = file_get_contents($_FILES['ecart']['tmp_name']);

		$formats = array(0=>false,3=>"xml",4=>"tab",5=>"csv");
		preg_match('/((<[^>]+>.+?<\/[^>]+>)|(.+?\t.+?\n)|(.+?,.+?\n))/',$data,$_);
		$format = $formats[count($_)];
		if (!$format) die(json_encode(array("error" => __('The file format could not be detected.','Ecart'))));

		$_ = array();
		switch ($format) {
			case "xml":
				/*
				Example XML import file:
					<localtaxrates>
						<taxrate name="Kent">1</taxrate>
						<taxrate name="New Castle">0.25</taxrate>
						<taxrate name="Sussex">1.4</taxrate>
					</localtaxrates>
				*/
				require_once(ECART_MODEL_PATH."/XML.php");
				$XML = new xmlQuery($data);
				$taxrates = $XML->tag('taxrate');
				while($rate = $taxrates->each()) {
					$name = $rate->attr(false,'name');
					$value = $rate->content();
					$_[$name] = $value;
				}
				break;
			case "csv":
				if (($csv = fopen($_FILES['ecart']['tmp_name'], "r")) === false) die('');
				while (($data = fgetcsv($csv, 1000, ",")) !== false)
					$_[$data[0]] = !empty($data[1])?$data[1]:0;
				fclose($csv);
				break;
			case "tab":
			default:
				$lines = explode("\n",$data);
				foreach ($lines as $line) {
					list($key,$value) = explode("\t",$line);
					$_[$key] = $value;
				}
		}

		echo json_encode($_);
		exit();

	}