Index: /controller/wpsg_OrderController.class.php
===================================================================
--- /controller/wpsg_OrderController.class.php	(revision 7717)
+++ /controller/wpsg_OrderController.class.php	(revision 7719)
@@ -988,5 +988,6 @@
 					wpsg_sinput("key", $_REQUEST['edit_id']),
 					wpsg_sinput("key", $_REQUEST['status']),
-					(($_REQUEST['sendMail'] == '1')?true:false)
+					(($_REQUEST['sendMail'] == '1')?true:false),
+                    wpsg_isSizedInt($_REQUEST['attachInvoice'])
 				);
 
Index: /controller/wpsg_ShopController.class.php
===================================================================
--- /controller/wpsg_ShopController.class.php	(revision 7717)
+++ /controller/wpsg_ShopController.class.php	(revision 7719)
@@ -2516,6 +2516,7 @@
 		 * @param int $status_id ID des Status
 		 * @param bool $inform Kunde per Mail informieren
-		 */
-		public function setOrderStatus($order_id, $status_id, $inform)
+         * @param bool $bInvoice Rechnung anhÃ€ngen, wenn mÃ¶glich
+		 */
+		public function setOrderStatus($order_id, $status_id, $inform, $bInvoice = false)
 		{
 		    
@@ -2610,5 +2611,19 @@
 				));
 
-				$this->sendMail($mail_text, $this->view['kunde']['email'], 'status', array(), $order_id, false, $mail_html);
+				$arAttachment = [];
+
+				if ($bInvoice && $this->hasMod('wpsg_mod_rechnungen')) {
+
+				    $db_invoice = $this->callMod('wpsg_mod_rechnungen', 'getOrderInvoice', [$order_id]);
+
+				    if (wpsg_isSizedInt($db_invoice['id'])) {
+
+                        $arAttachment[] = $this->callMod('wpsg_mod_rechnungen', 'getDownloadFile', [intval($db_invoice['id'])]);
+
+                    }
+
+                }
+
+				$this->sendMail($mail_text, $this->view['kunde']['email'], 'status', $arAttachment, $order_id, false, $mail_html);
 
 			}
@@ -4161,10 +4176,11 @@
 		 *
 		 */
-		public function setPayMent($order_id, $pay_amount)
-		{
+		public function setPayMent($order_id, $pay_amount) {
 
 			$order_data = $this->cache->loadOrder($order_id);
 
-			if (round(doubleval($order_data['price_gesamt']), 2) == round(doubleval($pay_amount), 2))
+			$oOrder = wpsg_order::getInstance(intval($order_id));
+
+			if (round(doubleval($oOrder->getToPay(WPSG_BRUTTO)), 2) == round(doubleval($pay_amount), 2))
 			{
 
Index: /controller/wpsg_SystemController.class.php
===================================================================
--- /controller/wpsg_SystemController.class.php	(revision 7717)
+++ /controller/wpsg_SystemController.class.php	(revision 7719)
@@ -154,5 +154,5 @@
             if (is_object($result) && get_class($result) == 'WP_Error') {
 
-                throw new \wpsg\Exception($result->errors);
+                throw new \wpsg\Exception($result->get_error_message());
 
             } else return $result['body'];
@@ -169,5 +169,5 @@
 
 			if (is_array($result)) return $result['body'];
-			else throw new Exception($result->errors);
+			else throw new Exception($result->errors, 0);
 			 			
 		} // public function get_url_content($url)
Index: /mods/wpsg_mod_packagetracking.class.php
===================================================================
--- /mods/wpsg_mod_packagetracking.class.php	(revision 7717)
+++ /mods/wpsg_mod_packagetracking.class.php	(revision 7719)
@@ -298,6 +298,10 @@
 			
 			$oOrder = wpsg_order::getInstance($order['id'], true);
-						 
-			if ($_REQUEST['status'] != 250 || !wpsg_isSizedInt($oOrder->__get('wpsg_mod_packagetracking_provider')) || !wpsg_isSizedString($oOrder->__get('wpsg_mod_packagetracking_code'))) return;
+
+
+            $wpsg_mod_packagetracking_provider = $oOrder->__get('wpsg_mod_packagetracking_provider');
+            $wpsg_mod_packagetracking_code = $oOrder->__get('wpsg_mod_packagetracking_code');
+
+			if ($_REQUEST['status'] != 250 || !wpsg_isSizedInt($wpsg_mod_packagetracking_provider) || !wpsg_isSizedString($wpsg_mod_packagetracking_code)) return;
 			
 			$this->shop->view['wpsg_mod_packagetracking']['trackingURL'] = $this->getTrackingURL($order['id']);
Index: /mods/wpsg_mod_rechnungen.class.php
===================================================================
--- /mods/wpsg_mod_rechnungen.class.php	(revision 7717)
+++ /mods/wpsg_mod_rechnungen.class.php	(revision 7719)
@@ -1187,5 +1187,5 @@
 								
 				// Url Benachrichtigung
-				if ($_REQUEST['wpsg_rechnungen_url'] == '1')
+				if (wpsg_isSizedString($_REQUEST['wpsg_rechnungen_url'], '1'))
 				{
 					
@@ -1389,9 +1389,5 @@
 		} // private function copyTemp($file, $r_id)
 
-        /**
-         * Startet den Download einer Rechnung wird im Frontend wie im Backend verwendet
-         */
-        private function doDownload($r_id)
-        {
+        public function getDownloadFile($r_id) {
 
             $rechnung = $this->db->fetchRow("SELECT * FROM `".WPSG_TBL_RECHNUNGEN."` WHERE `id` = '".wpsg_q($r_id)."'");
@@ -1463,6 +1459,5 @@
 
             }
-            else
-            {
+            else {
 
                 /**
@@ -1527,4 +1522,15 @@
 
             }
+
+            return $file;
+
+        }
+
+        /**
+         * Startet den Download einer Rechnung wird im Frontend wie im Backend verwendet
+         */
+        private function doDownload($r_id) {
+
+            $file = $this->getDownloadFile($r_id);
 
             header("Cache-Control: no-cache, must-revalidate");
Index: /views/order/view_general.phtml
===================================================================
--- /views/order/view_general.phtml	(revision 7717)
+++ /views/order/view_general.phtml	(revision 7719)
@@ -35,4 +35,29 @@
     <?php echo wpsg_drawForm_Checkbox('sendMail', __('Kunden informieren', 'wpsg'), 0); ?>
 
+    <?php if ($this->hasMod('wpsg_mod_rechnungen')) { $db_invoice = $this->callMod('wpsg_mod_rechnungen', 'getOrderInvoice', [$this->view['oOrder']->id]); ?>
+        <?php if (wpsg_isSizedInt($db_invoice['id'])) { ?>
+            <script>
+
+                jQuery('#sendMail').on('click', function() {
+
+                    if (jQuery(this).prop('checked')) {
+
+                        jQuery('#layer_attachInvoice').show();
+
+                    } else {
+
+                        jQuery('#layer_attachInvoice').hide();
+
+                    }
+
+                }).click();
+
+            </script>
+            <div id="layer_attachInvoice">
+                <?php echo wpsg_drawForm_Checkbox('attachInvoice', __('Rechnung anhÃ€ngen', 'wpsg'), 0); ?>
+            </div>
+        <?php } ?>
+    <?php } ?>
+
     <br />
 	<?php $this->callMods('order_view_switchStatus', array(&$this->view['data']['id'])); ?>						
