diff --git a/Makefile b/Makefile
index be10e5151cc8fd71756b7c4ddfa1942b1788bba4..e56e84ccede201c1d3431b49b0070964e621a892 100644
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,12 @@
 BASE=downloads_for_sale
 PLUGINTYPE=vmcustom
-VERSION=1.3.1
+VERSION=1.4
 
 PLUGINFILES=$(BASE).php $(BASE).script.php $(BASE).xml index.html
 
 TRANSLATIONS=$(call wildcard,language/*/*.plg_$(PLUGINTYPE)_$(BASE).*ini) 
 INDEXFILES=$(BASE)/index.html language/index.html $(call wildcard,language/*/index.html)
+ELEMENTS=$(call wildcard,elements/*.php) elements/index.html
 TMPLFILES=$(call wildcard,$(BASE)/tmpl/*.php) $(BASE)/index.html $(BASE)/tmpl/index.html
 ASSETS=$(call wildcard,$(BASE)/assets/*.png) $(call wildcard,$(BASE)/assets/*.css) $(BASE)/assets/index.html
 ZIPFILE=plg_$(PLUGINTYPE)_$(BASE)_v$(VERSION).zip
diff --git a/downloads_for_sale.php b/downloads_for_sale.php
index 592f526c1592bc0c89c0e2f0bfe5dd161aca9acc..362ab005358246ef154274d52ccb6290706bc72e 100644
--- a/downloads_for_sale.php
+++ b/downloads_for_sale.php
@@ -27,7 +27,6 @@ if (JVM_VERSION === 2) {
 }
 
 class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
-	var $status_allowed = array ('S', 'C');
 
 	function __construct(& $subject, $config) {
 		parent::__construct($subject, $config);
@@ -38,6 +37,8 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
 			'invoice_link_type'=>array('text', 'char'),
 			'product_link_type'=>array('image','char'),
 			'download_type'=>array('free_download','char'),
+			'paid_status'=>array(array('S', 'C'), 'array'),
+			'downloaded_status'=>array('S', 'char'),
 		);
 		$this->setConfigParameterable('custom_params',$varsToPush);
 		$this->onStoreInstallPluginTable($this->_psType);
@@ -94,10 +95,10 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
 		}
 		$orderitems = array();
 		foreach ($orders as $order) {
-			if ($order && in_array($order['details']['BT']->order_status, $this->status_allowed)) {
+			if ($order && in_array($order['details']['BT']->order_status, $field->paid_status)) {
 				foreach ($order['items'] as $i) {
 					if ($i->virtuemart_product_id == $prodid) {
-						if (in_array($i->order_status, $this->status_allowed)) {
+						if (in_array($i->order_status, $field->paid_status)) {
 							$orderitems[] = $i;
 						} elseif ($show_warnings) {
 							JFactory::getApplication()->enqueueMessage(JText::_('VMCUSTOM_DLSALE_ERROR_STATUS_NOT_AUTHORIZED'), 'error');
@@ -121,7 +122,7 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
 			return ($userId>0);
 		}
 		// In all other cases, check that the orderitem has the correct state
-		if ($orderitem && in_array($orderitem->order_status, $this->status_allowed)) {
+		if ($orderitem && in_array($orderitem->order_status, $field->paid_status)) {
 			return true;
 		}
 		return false;
@@ -153,16 +154,18 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
 			}
 			header("Content-Type: " . $media->file_mimetype);
 			header("Content-Disposition: attachment; filename=\"".JFile::getName($media->file_url)."\"");
-			if (!@readfile($media->file_url)) {
+			if (@readfile($media->file_url)) {
+				return true;
+			} else { 
 				header_remove("Content-Type");
 				header_remove("Content-Disposition");
 				JFactory::getApplication()->enqueueMessage(JText::sprintf('VMCUSTOM_DLSALE_ERROR_NO_FILE_SET', $media_id, $media->file_url), 'error');
 				return false;
 			}
-			JExit();
 		} else {
 			$output = JText::_('VMCUSTOM_DLSALE_NO_FILE_FOUND');
 		}
+		return false;
 	}
 
 
@@ -192,6 +195,20 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
 		}
 
 	}
+	
+	function updateOrderStatus ($field, $orderitem) {
+		if (!$orderitem) return;
+		$orderModel = VmModel::getModel('orders');
+		
+		# Update the whole order:
+		$order = $this->orderDataFromItem ($orderitem->virtuemart_order_item_id);
+		$orderdata['order_status'] = $field->downloaded_status;
+		$orderdata['customer_notified'] = 0;
+		$orderdata['comments'] = '';
+		if ($order->order_status != $orderdata['order_status']) {
+			$orderModel->updateStatusForOneOrder($order->virtuemart_order_id, $orderdata, /*triggers=*/false);
+		}
+	}
 
 	function plgVmOnSelfCallFE($type,$name,&$render) {
 		if ($name != $this->_name || $type != 'vmcustom') return false;
@@ -206,11 +223,15 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
 			$orderitem = empty($orderitems)?null:$orderitems[0];
 			if ($field) {
 				if ($this->checkDownloadable ($field, $orderitem, true)) {
-					// TODO: Update download counter in the mysql table
-					$this->updateDownloadCounterSQL ($field, $orderitem);
 					$handled = true;
-					$this->downloadFile ($field->media_id, $render);
-					return true;
+					if ($this->downloadFile ($field->media_id, $render)) {
+						// Successful download, so set order status to shipped, then exit to prevent the normal joomla page formatting (we sent a potentially binary file already!)
+						$this->updateDownloadCounterSQL ($field, $orderitem);
+						$this->updateOrderStatus ($field, $orderitem);
+						JExit();
+					} else {
+						return true;
+					}
 				} else {
 // 					JFactory::getApplication()->enqueueMessage(JText::_('VMCUSTOM_DLSALE_ERROR_NOT_AUTHORIZED_UNKNOWN'), 'error');
 				}
@@ -259,10 +280,6 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
 			
 			$orderdownloads = array();
 			foreach ($orders as $order) {
-				if (!in_array($order['details']['BT']->order_status, $this->status_allowed)) {
-					// Order status does not allow a download in any case, so skip this order
-					continue;
-				}
 				$orderinfo = $order;
 				$orderinfo['download_products']=array();
 				foreach ($order['items'] as $i) {
@@ -270,7 +287,8 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
 					$productinfo->downloads = array();
 					$customs = (array)$customModel->getproductCustomslist ($i->virtuemart_product_id);
 					foreach ($customs as $field) {
-						if (($field->custom_element == $this->_name) && ($this->checkDownloadable ($field, $i, false))) {
+						// Order needs to be downloadable and the individiaul field, too:
+						if (($field->custom_element == $this->_name) && in_array($order['details']['BT']->order_status, $field->paid_status) && ($this->checkDownloadable ($field, $i, false))) {
 							$productinfo->downloads[] = $this->createDownloadLink ($field, 'order', $field->invoice_link_type, $i);
 						}
 					}
@@ -362,7 +380,7 @@ class plgVmCustomDownloads_for_Sale extends vmCustomPlugin {
 					foreach ($orderModel->getOrdersList($cuid, true) as $ol) {
 						$o = $orderModel->getOrder($ol->virtuemart_order_id);
 						foreach ($o['items'] as $i) {
-							if ($i->virtuemart_product_id == $field->virtuemart_product_id && in_array($i->order_status, $this->status_allowed)) {
+							if ($i->virtuemart_product_id == $field->virtuemart_product_id && in_array($i->order_status, $field->paid_status)) {
 								$order = $o['details']['BT'];
 							}
 						}
diff --git a/downloads_for_sale.xml b/downloads_for_sale.xml
index 6e0ff454e19106f6a6437bcd4b85f4310189291f..3ad3cce704c17ff6be0bf6a3caf771a1fee2803f 100644
--- a/downloads_for_sale.xml
+++ b/downloads_for_sale.xml
@@ -6,7 +6,7 @@
     <authorUrl>http://www.open-tools.net/</authorUrl>
     <copyright>Copyright (C) 2013 Reinhold Kainhofer. All rights reserved.</copyright>
     <license>http://www.gnu.org/licenses/gpl.html GNU/GPL v3+</license>
-    <version>1.3.1</version>
+    <version>1.4</version>
     <description>VMCUSTOM_DLSALE_DESC</description>
     <files>
         <filename plugin="downloads_for_sale">downloads_for_sale.php</filename>
@@ -14,6 +14,7 @@
         <folder>downloads_for_sale</folder>
         <folder>language</folder>
         <filename>index.html</filename>
+	<folder>elements</folder>
     </files>
     <languages folder="language">
         <language tag="en-GB">en-GB/en-GB.plg_vmcustom_downloads_for_sale.ini</language>
@@ -22,6 +23,7 @@
         <language tag="de-DE">de-DE/de-DE.plg_vmcustom_downloads_for_sale.sys.ini</language>
     </languages>
     <scriptfile>downloads_for_sale.script.php</scriptfile>
+    <params addpath="/plugins/vmcustom/downloads_for_sale/elements" />
     <params addpath="/administrator/components/com_virtuemart/elements">
         <param type="vmjpluginwarning" />
         <param name="invoice_link_type" type="list" default="link" label="VMCUSTOM_DLSALE_INVOICE_LINK" description="VMCUSTOM_DLSALE_INVOICE_LINK_DESC" >
@@ -39,5 +41,7 @@
             <option value="registered_download">VMCUSTOM_DLSALE_TYPE_REGISTERED</option>
             <option value="paid_download">VMCUSTOM_DLSALE_TYPE_PAID</option>
         </param>
+        <param name="paid_status" type="vmorderstates" scope="com_virtuemart" default="C" label="VMCUSTOM_DLSALE_STATUS_PAID" description="VMCUSTOM_DLSALE_STATUS_PAID_EXPLAIN" />
+        <param name="downloaded_status" type="vmorderstate" scope="com_virtuemart" default="S" label="VMCUSTOM_DLSALE_STATUS_DOWNLOADED" description="VMCUSTOM_DLSALE_STATUS_DOWNLOADED_EXPLAIN" />
     </params>
 </install>
diff --git a/elements/index.html b/elements/index.html
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/elements/vmorderstates.php b/elements/vmorderstates.php
new file mode 100644
index 0000000000000000000000000000000000000000..c55b18fd82df7eeb720714bd49deece41ef5284f
--- /dev/null
+++ b/elements/vmorderstates.php
@@ -0,0 +1,53 @@
+<?php
+defined ('_JEXEC') or die();
+/**
+ *
+ * @package    VirtueMart
+ * @subpackage Plugins  - Elements
+ * @author Valérie Isaksen
+ * @link http://www.virtuemart.net
+ * @copyright Copyright (c) 2004 - 2011 VirtueMart Team. All rights reserved.
+ * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
+ * VirtueMart is free software. This version may have been modified pursuant
+ * to the GNU General Public License, and as distributed it includes or
+ * is derivative of works licensed under the GNU General Public License or
+ * other free or open source software licenses.
+ * @version $Id:$
+ */
+/*
+ * This class is used by VirtueMart Payment or Shipment Plugins
+ * which uses JParameter
+ * So It should be an extension of JElement
+ * Those plugins cannot be configured througth the Plugin Manager anyway.
+ */
+
+class JElementVmOrderStates extends JElement {
+
+	/**
+	 * Element name
+	 *
+	 * @access    protected
+	 * @var        string
+	 */
+	var $_name = 'OrderStates';
+
+	function fetchElement ($name, $value, &$node, $control_name) {
+
+		$db = JFactory::getDBO ();
+
+		$query = 'SELECT `order_status_code` AS value, `order_status_name` AS text
+                 FROM `#__virtuemart_orderstates`
+                 WHERE `virtuemart_vendor_id` = 1
+                 ORDER BY `ordering` ASC ';
+
+		$db->setQuery ($query);
+		$fields = $db->loadObjectList ();
+		$class = 'class="inputbox" multiple="multiple" size="6" ';
+		foreach ($fields as $field) {
+			$field->text= JText::_ ($field->text);
+		}
+
+		return JHTML::_ ('select.genericlist', $fields, $control_name . '[' . $name . '][]', $class, 'value', 'text', $value, $control_name . $name);
+	}
+
+}
diff --git a/language/de-DE/de-DE.plg_vmcustom_downloads_for_sale.ini b/language/de-DE/de-DE.plg_vmcustom_downloads_for_sale.ini
index baf0cfbb058a016502f14315bb36fc4b25c47be1..e01397ce608a6355ed3c75557c135d6d0b59f09e 100644
--- a/language/de-DE/de-DE.plg_vmcustom_downloads_for_sale.ini
+++ b/language/de-DE/de-DE.plg_vmcustom_downloads_for_sale.ini
@@ -21,6 +21,11 @@ VMCUSTOM_DLSALE_TYPE_FREE="Kostenloser Download"
 VMCUSTOM_DLSALE_TYPE_REGISTERED="Download nur nach Registrierung"
 VMCUSTOM_DLSALE_TYPE_PAID="Bezahlter Download"
 
+VMCUSTOM_DLSALE_STATUS_PAID="Status um bezahlte Download verfügbar zu machen"
+VMCUSTOM_DLSALE_STATUS_PAID_EXPLAIN="Wählen sie die Liste der Statuswerte aus, wann bezahlte Downloads zur Verfügung gestellt werden."
+VMCUSTOM_DLSALE_STATUS_DOWNLOADED="Status nach Download"
+VMCUSTOM_DLSALE_STATUS_DOWNLOADED_EXPLAIN="Nach einem bezahlten Download wird der Status der Bestellung auf diesen Wert gesetzt."
+
 VMCUSTOM_DLSALE_NO_FILES="Keine Mediendatein für den Download oder Verkauf gefunden."
 VMCUSTOM_DLSALE_DOWNLOAD_FILE="Datei zum Download"
 VMCUSTOM_DLSALE_ERROR_NOT_AUTHORIZED="Nicht zum Download authorisiert. Bitte loggen Sie sich als entsprechender Benutzer ein."
diff --git a/language/en-GB/en-GB.plg_vmcustom_downloads_for_sale.ini b/language/en-GB/en-GB.plg_vmcustom_downloads_for_sale.ini
index b4019df9b7e8e4db6da9e8d8350d704529462ffd..0e9210a7a8991d27184b4272938cc396dbd4d03c 100644
--- a/language/en-GB/en-GB.plg_vmcustom_downloads_for_sale.ini
+++ b/language/en-GB/en-GB.plg_vmcustom_downloads_for_sale.ini
@@ -21,6 +21,11 @@ VMCUSTOM_DLSALE_TYPE_FREE="Free download"
 VMCUSTOM_DLSALE_TYPE_REGISTERED="Download after registration"
 VMCUSTOM_DLSALE_TYPE_PAID="Paid download"
 
+VMCUSTOM_DLSALE_STATUS_PAID="Status to enable paid download"
+VMCUSTOM_DLSALE_STATUS_PAID_EXPLAIN="Select the statuses for paid downloads that allow the buyer to download the file."
+VMCUSTOM_DLSALE_STATUS_DOWNLOADED="Status after download"
+VMCUSTOM_DLSALE_STATUS_DOWNLOADED_EXPLAIN="After a file was downloaded through this plugin, the order status will be set to this value, indication a download was initiated by the user."
+
 VMCUSTOM_DLSALE_NO_FILES="No media files found for download or sale."
 VMCUSTOM_DLSALE_DOWNLOAD_FILE="Download file"
 VMCUSTOM_DLSALE_ERROR_NOT_AUTHORIZED="Not authorized to download. Please log in."
diff --git a/releases/plg_vmcustom_downloads_for_sale_v1.4.zip b/releases/plg_vmcustom_downloads_for_sale_v1.4.zip
new file mode 100644
index 0000000000000000000000000000000000000000..ea44736fe22bf1a71bb51c9152fce3a8cc75933d
Binary files /dev/null and b/releases/plg_vmcustom_downloads_for_sale_v1.4.zip differ