Index: /changelog
===================================================================
--- /changelog	(revision 7734)
+++ /changelog	(revision 7735)
@@ -368,3 +368,4 @@
 - Bugfix: Durch den Fix in 4.2.3. ("Zuordnung Produkt zu Artikel") wurden die Kategorien nicht mehr gespeichert. Dies ist korrigiert
 - Bugfix: Eigene Kundenvariablen erzeugen bei bestehenden Kunden nicht mehr das Problem das man die Kundenverwaltung nicht Ã¶ffnen kann
+- Bugfix: Probleme mit "Bezahlen ÃŒber Amazon" wurden behoben
 - Warnungen im Code aufgelÃ¶st
Index: /mods/wpsg_mod_amazon.class.php
===================================================================
--- /mods/wpsg_mod_amazon.class.php	(revision 7734)
+++ /mods/wpsg_mod_amazon.class.php	(revision 7735)
@@ -1,706 +1,710 @@
 <?php
-	
-	/**
-	 * Modul fÃŒr "Bezahlen mit Amazon"
-	 * @author Daschmi (12.03.2016)
-	 */
-	class wpsg_mod_amazon extends wpsg_mod_basic
-	{
-		
-		var $lizenz = 1;
-		var $id = 3140;
-		var $hilfeURL = 'http://wpshopgermany.de/?p=3462587';
-		var $version = "9.9.9";
-		var $free = false;
-		
-		const ORDER_DONE_START = 0; // Zahlung starten lassen mit Pay with Amazon
-		const ORDER_DONE_GO = 1; // Zahlung gestartet, Wallet aneigen
-		const ORDER_DONE_PAST = 9; // Zahlung bereits durchgefÃŒhrt
-		const ORDER_DONE = 10; // Zahlung wurde gerade durchgefÃŒhrt
-		
-		/**
-		 * Kostruktor
-		 */
-		public function __construct()
-		{
-				
-			parent::__construct();
-				
-			$this->name = __('AmazonPay', 'wpsg');
-			$this->group = __('Zahlungsarten', 'wpsg');
-			$this->desc = __('ErmÃ¶glicht die Anmeldung / Zahlung mit Amazon.', 'wpsg');
-		
-		} // public function __construct()
-		
-		public function install()
-		{
-			 
-			$this->shop->checkDefault('wpsg_mod_amazon_aktiv', '1');
-			$this->shop->checkDefault('wpsg_mod_amazon_basket', '1');
-			$this->shop->checkDefault('wpsg_mod_amazon_name', __('AmazonPay', 'wpsg'), false, true);
-			$this->shop->checkDefault('wpsg_mod_amazon_hint', __('Bezahlen Sie ihre Bestellung einfach mit ihrem Amazon Konto.', 'wpsg'), false, true);
-			$this->shop->checkDefault('wpsg_mod_amazon_subject', __('O%order_id% - K%kunde_id%', 'wpsg'), false, true);
-						
-			
-		} // public function install()
-		
-		public function settings_edit()
-		{
-			
-			$this->shop->view['ipnURL'] = $this->shop->getUrl(wpsg_ShopController::URL_BASKET, 'wpsg_mod_amazon', 'ipn');
-			$this->shop->view['jsOrigin'] = preg_replace('/^http:\/\//i', 'https://', $this->shop->get_option('siteurl')); 
-			
-			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_amazon/settings_edit.phtml');
-			
-		} // public function settings_edit()
-		
-		public function settings_save()
-		{
-			
-		    $this->shop->update_option('wpsg_mod_amazon_sandbox', $_REQUEST['wpsg_mod_amazon_sandbox'], false, false, WPSG_SANITIZE_CHECKBOX);
-						
-		    $this->shop->update_option('wpsg_mod_amazon_seller_id', $_REQUEST['wpsg_mod_amazon_seller_id'], false, false, WPSG_SANITIZE_APIKEY);
-		    $this->shop->update_option('wpsg_mod_amazon_mws_access_key_id', $_REQUEST['wpsg_mod_amazon_mws_access_key_id'], false, false, WPSG_SANITIZE_APIKEY);
-		    $this->shop->update_option('wpsg_mod_amazon_mws_access_key', $_REQUEST['wpsg_mod_amazon_mws_access_key'], false, false, WPSG_SANITIZE_APIKEY);
-		    $this->shop->update_option('wpsg_mod_amazon_lwa_client_id', $_REQUEST['wpsg_mod_amazon_lwa_client_id'], false, false, WPSG_SANITIZE_APIKEY);
-		    $this->shop->update_option('wpsg_mod_amazon_lwa_client_secret', $_REQUEST['wpsg_mod_amazon_lwa_client_secret'], false, false, WPSG_SANITIZE_APIKEY);
-			$this->shop->update_option('wpsg_mod_amazon_sandbox', $_REQUEST['wpsg_mod_amazon_sandbox'], false, false, WPSG_SANITIZE_CHECKBOX);
-			
-			$this->shop->update_option('wpsg_mod_amazon_aktiv', $_REQUEST['wpsg_mod_amazon_aktiv'], false, false, WPSG_SANITIZE_CHECKBOX);
-			$this->shop->update_option('wpsg_mod_amazon_name', $_REQUEST['wpsg_mod_amazon_name'], false, true, WPSG_SANITIZE_TEXTFIELD);
-			$this->shop->update_option('wpsg_mod_amazon_subject', $_REQUEST['wpsg_mod_amazon_subject'], false, true, WPSG_SANITIZE_TEXTFIELD);
-			$this->shop->update_option('wpsg_mod_amazon_hint', $_REQUEST['wpsg_mod_amazon_hint'], false, true, WPSG_SANITIZE_TEXTFIELD);
-			$this->shop->update_option('wpsg_mod_amazon_basket', $_REQUEST['wpsg_mod_amazon_basket'], false, false, WPSG_SANITIZE_CHECKBOX);
-						
-			$this->shop->update_option('wpsg_mod_amazon_gebuehr', $_REQUEST['wpsg_mod_amazon_gebuehr'], false, false, WPSG_SANITIZE_FLOAT);
-			$this->shop->update_option('wpsg_mod_amazon_mwst', $_REQUEST['wpsg_mod_amazon_mwst'], false, false, WPSG_SANITIZE_TAXKEY);
-			$this->shop->update_option('wpsg_mod_amazon_mwstland', $_REQUEST['wpsg_mod_amazon_mwstland'], false, false, WPSG_SANITIZE_CHECKBOX);
-						
-		} // public function settings_save()
-		
-		public function basket_inner_prebutton(&$basket_view) 
-		{ 
-			
-			// Amazon ÃŒberhaupt mÃ¶glich
-			if (!array_key_exists($this->id, $this->shop->arPayment)) return;
-			
-			if (!wpsg_isSizedInt($this->shop->get_option('wpsg_mod_amazon_aktiv')) || !wpsg_isSizedInt($this->shop->get_option('wpsg_mod_amazon_basket'))) return;
-			
-			$oOrder = wpsg_order::getInstance($_SESSION['wpsg']['order_id']);
-			
-			$this->shop->view['wpsg_mod_amazon']['redirectURL'] = $this->shop->getUrl(wpsg_ShopController::URL_BASKET, 'wpsg_mod_amazon', 'return');
-			$this->shop->view['wpsg_mod_amazon']['logoutURL'] = $this->shop->getUrl(wpsg_ShopController::URL_BASKET, 'wpsg_mod_amazon', 'logout');
-			
-			$this->shop->view['wpsg_mod_amazon']['amazon_last_authorization_reference_id'] = $oOrder->getMeta('amazon_last_authorization_reference_id');
-		
-			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_amazon/basket_inner_prebutton.phtml');
-			
-		} // public function basket_inner_prebutton(&$basket_view)
-		
-		public function setOrderStatus($order_id, $status_id, $inform)
-		{
-		 
-			$oOrder = wpsg_order::getInstance($order_id);
-				
-			if ($oOrder->getPaymentID() == $this->id && in_array($status_id, array(wpsg_ShopController::STATUS_STORNIERT, wpsg_ShopController::STATUS_ZURUECKGEZAHLT)))
-			{
-				
-				$capture_id = $oOrder->getMeta('amazon_capture_id');
-		
-				if (wpsg_isSizedString($capture_id))
-				{
-					
-					$arReturn = $this->api_refund($oOrder->id);
-					
-					if (wpsg_isSizedString($arReturn['RefundResult']['RefundDetails']['AmazonRefundId']))
-					{
-						
-						$this->shop->addBackendMessage(__('Der Betrag wurde erfolgreich zurÃŒckerstattet.', 'wpsg'));
-						
-					}
-					else
-					{
-						
-						$this->shop->addBackendError(__('Es gab technische Probleme beim zurÃŒckerstatten des Betrages.', 'wpsg'));
-						
-						$oOrder->log(__('Fehler beim zurÃŒckerstatten des Bestellbetrages', 'wpsg'), print_r($arReturn, 1));
-						
-					}
-					
-				}
-				else
-				{
-					
-					$this->shop->addBackendError(__('RÃŒckzahlung nicht mÃ¶glich, da keine Capture/Authorize ID gesetzt wurde', 'wpsg'));
-					
-				}
-				
-			} 
-		
-		} // public function setOrderStatus($order_id, $status_id, $inform)
-		
-		public function wp_head()
-		{
-			
-			if (!wpsg_isSizedInt($this->shop->get_option('wpsg_mod_amazon_aktiv'))) return;
-			
-			echo '<script type="text/javascript"> window.onAmazonLoginReady = function() { amazon.Login.setClientId("'.$this->shop->get_option('wpsg_mod_amazon_lwa_client_id').'"); }; </script>';
-			
-			if (wpsg_isSizedInt($this->shop->get_option('wpsg_mod_amazon_sandbox')))
-			{
-			
-				echo '<script type="text/javascript" src="https://static-eu.payments-amazon.com/OffAmazonPayments/de/sandbox/lpa/js/Widgets.js"></script>';
-				
-			}
-			else
-			{
-				
-				echo '<script type="text/javascript" src="https://static-eu.payments-amazon.com/OffAmazonPayments/de/lpa/js/Widgets.js"></script>';
-				
-			}
-			
-		} // public function wp_head()
-		
-		public function order_done(&$order_id, &$done_view) 
-		{
-						
-			$oOrder = wpsg_order::getInstance($order_id);
-			
-			if ($oOrder->getToPay() <= 0 || $oOrder->getPaymentID() != $this->id) return;
-					 
-			if (wpsg_isSizedString($oOrder->getMeta('amazon_order_reference_id')) && !wpsg_isSizedString($oOrder->getMeta('amazon_order_done')))
-			{
-	 
-				// Zahlung durchfÃŒhren				 
-				$this->api_setPayment($order_id);
-				$this->api_finishPayment($order_id);
-							
-				$capture_return = $this->api_capturePayment($order_id);
-				
-				$this->api_closePayment($order_id);
-				
-				if (wpsg_isSizedString($capture_return['AuthorizeResult']['AuthorizationDetails']['AuthorizationAmount']['Amount']))
-				{
-				
-					$amount_captured = wpsg_tf($capture_return['AuthorizeResult']['AuthorizationDetails']['AuthorizationAmount']['Amount']);
-					
-					if ($this->shop->setPayMent($oOrder->id, $amount_captured))
-					{
-							
-						//$this->shop->setOrderStatus($oOrder->id, 100, true);
-						$oOrder->setMeta('amazon_order_done', serialize($capture_return));
-											
-						$this->shop->view['wpsg_mod_amazon']['state'] = self::ORDER_DONE;
-						return $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_amazon/order_done.phtml');
-						
-					}
-					
-				}
-			 
-			}
-			else if (wpsg_isSizedString($oOrder->getMeta('amazon_order_done')))
-			{
-				 
-				$this->shop->view['wpsg_mod_amazon']['state'] = self::ORDER_DONE_PAST;
-				return $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_amazon/order_done.phtml');
-				
-			}
-		 
-			if (wpsg_isSizedString($oOrder->getMeta('amazon_order_reference_id')))
-			{
-						
-				$oOrder->setMeta('amazon_order_reference_id', null);
-				$oOrder->setMeta('amazon_last_authorization_reference_id', null);
-			
-			}
-			
-			if (wpsg_isSizedString($_REQUEST['access_token']))
-			{
-				
-				$this->shop->view['wpsg_mod_amazon']['state'] = self::ORDER_DONE_GO;
-				
-			}
-			else
-			{
-			
-				$this->shop->view['wpsg_mod_amazon']['state'] = self::ORDER_DONE_START;
-								
-			}
-			
-			$this->shop->view['wpsg_mod_amazon']['redirectURL'] = $this->shop->getDoneURL($order_id);
-			
-			return $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_amazon/order_done.phtml');
-			
-		} // public function order_done($order_id, $done_view)
-		
-		public function basket_checkoutAction(&$basketController)
-		{
-			
-			if ($_SESSION['wpsg']['checkout']['payment'] != $this->id || !wpsg_isSizedInt($this->shop->get_option('wpsg_mod_amazon_basket'))) return;
-			
-			if (wpsg_isSizedString($_REQUEST['amazon']['OrderReference']))
-			{
-		 					
-				$oOrder = wpsg_order::getInstance($_SESSION['wpsg']['order_id']);
-							 	
-				$oOrder->setMeta('amazon_order_reference_id', $_REQUEST['amazon']['OrderReference']);
-												
-				$res = $this->api_getPayment($_SESSION['wpsg']['order_id']);
-				 			 		 
-				$res = $res['GetOrderReferenceDetailsResult']['OrderReferenceDetails'];
-				
-				list($vname, $name) = wpsg_explodeName($res['Destination']['PhysicalDestination']['Name']);
-					
-				if (wpsg_isSizedString($res['Buyer']['Email']) && !wpsg_isSizedString($_SESSION['wpsg']['checkout']['email']))
-				{
-					
-					$_SESSION['wpsg']['checkout']['email'] = $res['Buyer']['Email'];
-					$_SESSION['wpsg']['checkout']['email2'] = $res['Buyer']['Email'];
-					
-				}
-				
-				if (wpsg_isSizedString($res['Buyer']['Phone'])) $_SESSION['wpsg']['checkout']['tel'] = $res['Buyer']['Phone'];
-				 
-				// Vereinfacht auf die Ãbernahme der Lieferadresse
-				if (wpsg_isSizedArray($res['Destination']['PhysicalDestination']))
-				{
-			 
-					if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['vname'])) $_SESSION['wpsg']['checkout']['vname'] = $vname;
-					if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['name'])) $_SESSION['wpsg']['checkout']['name'] = $name;
-				
-					if (wpsg_isSizedArray($res['Destination']['PhysicalDestination']['AddressLine1'])) $res['Destination']['PhysicalDestination']['AddressLine1'] = implode(' ', $res['Destination']['PhysicalDestination']['AddressLine1']);
-					if (wpsg_isSizedArray($res['Destination']['PhysicalDestination']['AddressLine2'])) $res['Destination']['PhysicalDestination']['AddressLine1'] = implode(' ', $res['Destination']['PhysicalDestination']['AddressLine2']);
-						
-					if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['strasse'])) $_SESSION['wpsg']['checkout']['strasse'] = ltrim(implode(', ', array(
-							wpsg_getStr($res['Destination']['PhysicalDestination']['AddressLine1']),
-							wpsg_getStr($res['Destination']['PhysicalDestination']['AddressLine2']),
-					)), ', ');
-					if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['plz'])) $_SESSION['wpsg']['checkout']['plz'] = $res['Destination']['PhysicalDestination']['PostalCode'];
-					if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['ort'])) $_SESSION['wpsg']['checkout']['ort'] = $res['Destination']['PhysicalDestination']['City'];
-						
-					// Land wenn gefunden
-					$country_id = wpsg_country::getCountryIDFromCode($res['Destination']['PhysicalDestination']['CountryCode']);
-					if (!wpsg_isSizedInt($_SESSION['wpsg']['checkout']['land']) && wpsg_isSizedString($country_id)) $_SESSION['wpsg']['checkout']['land'] = $country_id;
-						
-				}
-				
-				/*
-				if ($this->shop->hasMod('wpsg_mod_shippingadress'))
-				{
-					
-					// Lieferadresse ist aktiv
-					// Lieferadresse aus Amazon -> Lieferadresse
-					// Recnungsadresse aus Amazon -> Rechnungsadresse
-					// Eventuell schauen ob gleich ist :?
-				
-					if (wpsg_isSizedArray($res['BillingAddress']['PhysicalAddress']))
-					{
-						
-						if (wpsg_isSizedArray($res['BillingAddress']['PhysicalAddress']['AddressLine1'])) $res['BillingAddress']['PhysicalAddress']['AddressLine1'] = implode(' ', $res['Destination']['PhysicalDestination']['AddressLine1']);
-						if (wpsg_isSizedArray($res['BillingAddress']['PhysicalAddress']['AddressLine2'])) $res['BillingAddress']['PhysicalAddress']['AddressLine1'] = implode(' ', $res['Destination']['PhysicalDestination']['AddressLine2']);
-					
-						if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['shipping_vname'])) $_SESSION['wpsg']['checkout']['shipping_vname'] = $vname;
-						if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['shipping_name'])) $_SESSION['wpsg']['checkout']['shipping_name'] = $name;
-						if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['strasse'])) $_SESSION['wpsg']['checkout']['strasse'] = ltrim(implode(', ', array(
-								wpsg_getStr($res['BillingAddress']['PhysicalAddress']['AddressLine1']),
-								wpsg_getStr($res['BillingAddress']['PhysicalAddress']['AddressLine2']),
-						)), ', ');
-						
-						if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['plz'])) $_SESSION['wpsg']['checkout']['plz'] = $res['BillingAddress']['PhysicalAddress']['PostalCode'];
-						if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['ort'])) $_SESSION['wpsg']['checkout']['ort'] = $res['BillingAddress']['PhysicalAddress']['City'];
-						
-						// Land wenn gefunden
-						$country_id = wpsg_country::getCountryIDFromCode($res['BillingAddress']['PhysicalAddress']['CountryCode']);
-						if (!wpsg_isSizedInt($_SESSION['wpsg']['checkout']['land']) && wpsg_isSizedString($country_id)) $_SESSION['wpsg']['checkout']['land'] = $country_id;
-						
-					}
-					
-					if (wpsg_isSizedArray($res['Destination']['PhysicalDestination']))
-					{
-						 						
-						if (wpsg_isSizedArray($res['Destination']['PhysicalDestination']['AddressLine1'])) $res['Destination']['PhysicalDestination']['AddressLine1'] = implode(' ', $res['Destination']['PhysicalDestination']['AddressLine1']);
-						if (wpsg_isSizedArray($res['Destination']['PhysicalDestination']['AddressLine2'])) $res['Destination']['PhysicalDestination']['AddressLine1'] = implode(' ', $res['Destination']['PhysicalDestination']['AddressLine2']);
-						
-						if (!isset($_SESSION['wpsg']['checkout']['diff_shippingadress'])) $_SESSION['wpsg']['checkout']['diff_shippingadress'] = '1';
-						if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['shipping_vname'])) $_SESSION['wpsg']['checkout']['shipping_vname'] = $vname;
-						if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['shipping_name'])) $_SESSION['wpsg']['checkout']['shipping_name'] = $name;
-						if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['shipping_strasse'])) $_SESSION['wpsg']['checkout']['shipping_strasse'] = ltrim(implode(', ', array(
-							wpsg_getStr($res['Destination']['PhysicalDestination']['AddressLine1']),
-							wpsg_getStr($res['Destination']['PhysicalDestination']['AddressLine2']),
-						)), ', ');
-						if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['shipping_plz'])) $_SESSION['wpsg']['checkout']['shipping_plz'] = $res['Destination']['PhysicalDestination']['PostalCode'];
-						if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['shipping_ort'])) $_SESSION['wpsg']['checkout']['shipping_ort'] = $res['Destination']['PhysicalDestination']['City'];
-						
-						// Land wenn gefunden
-						$country_id = wpsg_country::getCountryIDFromCode($res['Destination']['PhysicalDestination']['CountryCode']);
-						if (!wpsg_isSizedInt($_SESSION['wpsg']['checkout']['shipping_land']) && wpsg_isSizedString($country_id)) $_SESSION['wpsg']['checkout']['shipping_land'] = $country_id;
-											
-					}
-					
-				}
-				else
-				{
-				
-					// Modul "Lieferanschrift" ist deaktiviert
-					// Ich nehme hier als Liefer- und Rechnungsanschrift die Daten aus Amazon Lieferanschrift
-					if (wpsg_isSizedArray($res['Destination']['PhysicalDestination']))
-					{
-										
-						if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['vname'])) $_SESSION['wpsg']['checkout']['vname'] = $vname;
-						if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['name'])) $_SESSION['wpsg']['checkout']['name'] = $name;
-						
-						if (wpsg_isSizedArray($res['Destination']['PhysicalDestination']['AddressLine1'])) $res['Destination']['PhysicalDestination']['AddressLine1'] = implode(' ', $res['Destination']['PhysicalDestination']['AddressLine1']);
-						if (wpsg_isSizedArray($res['Destination']['PhysicalDestination']['AddressLine2'])) $res['Destination']['PhysicalDestination']['AddressLine1'] = implode(' ', $res['Destination']['PhysicalDestination']['AddressLine2']);
-					
-						if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['strasse'])) $_SESSION['wpsg']['checkout']['strasse'] = ltrim(implode(', ', array(
-								wpsg_getStr($res['Destination']['PhysicalDestination']['AddressLine1']),
-								wpsg_getStr($res['Destination']['PhysicalDestination']['AddressLine2']),
-						)), ', ');
-						if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['plz'])) $_SESSION['wpsg']['checkout']['plz'] = $res['Destination']['PhysicalDestination']['PostalCode'];
-						if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['ort'])) $_SESSION['wpsg']['checkout']['ort'] = $res['Destination']['PhysicalDestination']['City'];
-					
-						// Land wenn gefunden
-						$country_id = wpsg_country::getCountryIDFromCode($res['Destination']['PhysicalDestination']['CountryCode']);
-						if (!wpsg_isSizedInt($_SESSION['wpsg']['checkout']['land']) && wpsg_isSizedString($country_id)) $_SESSION['wpsg']['checkout']['land'] = $country_id;
-							
-					}
-					
-				}
-				*/
-						
-				$this->shop->basket->initFromSession(true);
-				$check1 = $this->shop->basket->checkCheckout(1);
-										
-				if ($check1 === true)
-				{
-				
-					$check2 = $this->shop->basket->checkCheckout(2);
-					
-					if ($check2 === true)
-					{
-						
-						$this->shop->redirect($this->shop->getUrl(wpsg_ShopController::URL_OVERVIEW));
-						
-					}
-					else
-					{
-						
-						$this->shop->redirect($this->shop->getUrl(wpsg_ShopController::URL_CHECKOUT2));
-						
-					}
-					
-				}
-				else
-				{
-					
-					$this->shop->redirect($this->shop->getUrl(wpsg_ShopController::URL_CHECKOUT));
-					
-				}
-				 
-			}
-			
-			if ($bError) return -2;
-			
-		} // public function basket_checkoutAction(&$basketController)
-		
-		public function addPayment(&$arPayment)
-		{
-		
-			if (is_admin() || $this->shop->get_option('wpsg_mod_amazon_aktiv') == '1') {
-					
-				$arPayment[$this->id] = array(
-					'id' => $this->id,
-					'name' => __($this->shop->get_option('wpsg_mod_amazon_name'), 'wpsg'),
-					'price' => $this->shop->get_option('wpsg_mod_amazon_gebuehr'),
-					'tax_key' => $this->shop->get_option('wpsg_mod_amazon_mwst'),
-					'mwst_null' => $this->shop->get_option('wpsg_mod_amazon_mwstland'),
-					'hint' => __($this->shop->get_option('wpsg_mod_amazon_hint'), 'wpsg'),
-					'logo' => $this->shop->getRessourceURL('mods/mod_amazon/gfx/logo_100x25.png')
-				);
-					 					
-			}
-				
-		} // public function addPayment(&$arPayment)
-				 
-		/* Redirect */
-		 
-		public function ipnRedirect()
-		{
-			 
-			require_once WPSG_PATH_MOD.'mod_amazon/PayWithAmazon/IpnHandler.php';
-			
-			$headers = getallheaders();
-			$body = file_get_contents('php://input');
-			
-			$ipnHandler = new \PayWithAmazon\IpnHandler($headers, $body);
-			$ipnData = $ipnHandler->toArray();
-			
-			if (wpsg_isSizedArray($ipnData) && wpsg_isSizedString($ipnData['NotificationType'], 'PaymentCapture'))
-			{
-				
-				$order_id = $ipnData['CaptureDetails']['CaptureReferenceId'];
-				$oOrder = wpsg_order::getInstance($order_id); 
-								
-				if (wpsg_isSizedInt($this->shop->get_option('wpsg_debugModus'))) $oOrder->log('Amazon:notification:PaymentCapture', print_r($ipnData, 1));
-				
-				if ($this->shop->setPayMent($order_id, $ipnData['CaptureDetails']['CaptureAmount']['Amount']) && wpsg_isSizedString($ipnData['CaptureDetails']['CaptureStatus']['State'], 'Completed'))
-				{
-				
-					$oOrder->setMeta('amazon_capture_id', $ipnData['CaptureDetails']['AmazonCaptureId']);
-					
-					$this->shop->setOrderStatus($order_id, 100, true);
-						
-				}
-				
-			}
-			  			
-		} // public function ipnRedirect()
-		
-		public function logoutRedirect()
-		{
-			
-			$this->shop->redirect($this->shop->getUrl(wpsg_ShopController::URL_BASKET));
-			
-		} // public function logoutRedirect()
-		 
-		public function returnRedirect()
-		{
-			  
-			if (wpsg_isSizedInt($_REQUEST['order_id']) && wpsg_isSizedString($_REQUEST['wpsg_done']))
-			{
-
-				$_REQUEST['order_id'] = wpsg_sinput("key", $_REQUEST['order_id']);
-			
-				if (wpsg_isSizedString($_REQUEST['amazon']['OrderReference']))
-				{
-				
-					$hash = preg_replace('/(\+)|(\=)/', 'A', base64_encode(md5('wpShopGermany'.$_REQUEST['order_id'], $this->shop->get_option("wpsg_salt"))));
-						
-					if ($hash != $_REQUEST['wpsg_done']) die(__('Aufrufsfehler!!', 'wpsg'));
-					
-					$oOrder = wpsg_order::getInstance($_REQUEST['order_id']);
-					$oOrder->setMeta('amazon_order_reference_id', $_REQUEST['amazon']['OrderReference']);
-					
-				}
-				
-				$this->shop->redirect($this->shop->getDoneURL($_REQUEST['order_id']));
-				
-			}
-			
-			$oOrder = wpsg_order::getInstance($_SESSION['wpsg']['order_id']);
-			$oOrder->setMeta('amazon_last_authorization_reference_id', $_REQUEST['access_token']);
-						
-			$_SESSION['wpsg']['checkout']['payment'] = $this->id;
-					
-			if (wpsg_isSizedInt($this->shop->get_option('wpsg_mod_amazon_sandbox'))) $c = curl_init('https://api.sandbox.amazon.com/auth/o2/tokeninfo?access_token='. urlencode($_REQUEST['access_token']));
-			else $c = curl_init('https://api.amazon.com/auth/o2/tokeninfo?access_token='. urlencode($_REQUEST['access_token']));
-			
-			curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
-			curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
-			
-			$r = curl_exec($c); curl_close($c); $d = json_decode($r);
-			
-			if ($d->aud != $this->shop->get_option('wpsg_mod_amazon_lwa_client_id')) 
-			{
-				
-				die("Amazon API Fehler!");
-				exit;
-				
-			}
-
-			if (wpsg_isSizedInt($this->shop->get_option('wpsg_mod_amazon_sandbox'))) $c = curl_init('https://api.sandbox.amazon.com/user/profile');
-			else $c = curl_init('https://api.amazon.com/user/profile');
-			
-			curl_setopt($c, CURLOPT_HTTPHEADER, array('Authorization: bearer '.$_REQUEST['access_token']));
-			
-			curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
-			curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
-			
-			$r = curl_exec($c); curl_close($c); $d = json_decode($r);
-			
-			$_SESSION['wpsg']['checkout']['email'] = $d->email;
-			$_SESSION['wpsg']['checkout']['email2'] = $d->email;
-			 
-			$this->shop->redirect($this->shop->getUrl(wpsg_ShopController::URL_BASKET, false, false, array(), false, 'LoginWithAmazon'));
-						
-		} // public function returnRedirect()
-		
-		// Modulfunktionen 
-		 
-		private function api_finishPayment($order_id)
-		{
-			
-			require_once WPSG_PATH_MOD.'mod_amazon/PayWithAmazon/Client.php';
-			
-			$oOrder = wpsg_order::getInstance($order_id);
-			$client = new PayWithAmazon\Client($this->getAPIConfig());
-			
-			$oResponse = $client->confirmOrderReference(array(
-				'amazon_order_reference_id' => $oOrder->getMeta('amazon_order_reference_id'),
-				'mws_auth_token' => $oOrder->getMeta('amazon_last_authorization_reference_id')
-			));
-			
-			if (wpsg_isSizedInt($this->shop->get_option('wpsg_debugModus'))) $oOrder->log('Amazon:confirmOrderReference', print_r($oResponse->toArray(), 1));
-			
-			return $oResponse->toArray();
-						
-		} // private function api_finishPayment($order_id)
-		
-		private function api_getPayment($order_id)
-		{
-			
-			require_once WPSG_PATH_MOD.'mod_amazon/PayWithAmazon/Client.php';
-			
-			$oOrder = wpsg_order::getInstance($order_id);
-			$client = new PayWithAmazon\Client($this->getAPIConfig());
-			
-			$oResponse = $client->getOrderReferenceDetails(array(
-				'amazon_order_reference_id' => $oOrder->getMeta('amazon_order_reference_id'),
-				'address_consent_token' => $oOrder->getMeta('amazon_last_authorization_reference_id')
-			));
-			
-			if (wpsg_isSizedInt($this->shop->get_option('wpsg_debugModus'))) $oOrder->log('Amazon:getOrderReferenceDetails', print_r($oResponse->toArray(), 1));
-		
-			return $oResponse->toArray();
-			
-		} // private function api_getPayment($order_id)
-		
-		private function api_setPayment($order_id)
-		{
-			
-			require_once WPSG_PATH_MOD.'mod_amazon/PayWithAmazon/Client.php';
-			
-			$oOrder = wpsg_order::getInstance($order_id);			
-			$client = new PayWithAmazon\Client($this->getAPIConfig());
-			
-			$oResponse = $client->setOrderReferenceDetails(array(
-				'amazon_order_reference_id' => $oOrder->getMeta('amazon_order_reference_id'),
-				'amount' => $oOrder->getToPay(),
-				'seller_order_id' => $oOrder->id,
-				'mws_auth_token' => $oOrder->getMeta('amazon_last_authorization_reference_id'),
-				'seller_note' => $this->shop->replaceUniversalPlatzhalter(__($this->shop->get_option('wpsg_mod_amazon_subject'), 'wpsg'), $order_id),
-				'currency_code' => 'EUR'
-			));
-			
-			if (wpsg_isSizedInt($this->shop->get_option('wpsg_debugModus'))) $oOrder->log('Amazon:setOrderReferenceDetails', print_r($oResponse->toArray(), 1));
-			
-			return $oResponse->toArray();
-			 						
-		} // private function api_setPayment($order_id)
-		 
-		private function api_capturePayment($order_id)
-		{
-			
-			require_once WPSG_PATH_MOD.'mod_amazon/PayWithAmazon/Client.php';
-			
-			$oOrder = wpsg_order::getInstance($order_id);
-			$client = new PayWithAmazon\Client($this->getAPIConfig());
-			
-			$oResponse = $client->authorize(array(
-				'amazon_order_reference_id' => $oOrder->getMeta('amazon_order_reference_id'),
-				'authorization_amount' => $oOrder->getToPay(),
-				'authorization_reference_id' => $order_id,
-				'soft_descriptor' => $this->shop->replaceUniversalPlatzhalter(__($this->shop->get_option('wpsg_mod_amazon_subject'), 'wpsg'), $order_id),
-				'seller_authorization_note' => $this->shop->replaceUniversalPlatzhalter(__($this->shop->get_option('wpsg_mod_amazon_subject'), 'wpsg'), $order_id),
-				'currency_code' => 'EUR',
-				'capture_now' => true
-			));
-			
-			$arReturn = $oResponse->toArray();
-			
-			if (wpsg_isSizedString($arReturn['AuthorizeResult']['AuthorizationDetails']['AmazonAuthorizationId'])) $oOrder->setMeta('amazon_capture_id', $arReturn['AuthorizeResult']['AuthorizationDetails']['AmazonAuthorizationId']);
-			
-			if (wpsg_isSizedInt($this->shop->get_option('wpsg_debugModus'))) $oOrder->log('Amazon:authorize', print_r($arReturn, 1));
-			
-			return $arReturn;
-						
-		} // private function api_capturePayment($order_id)
-		
-		private function api_closePayment($order_id)
-		{
-			
-			require_once WPSG_PATH_MOD.'mod_amazon/PayWithAmazon/Client.php';
-				
-			$oOrder = wpsg_order::getInstance($order_id);
-			$client = new PayWithAmazon\Client($this->getAPIConfig());
-				
-			$oResponse = $client->closeOrderReference(array(
-				'amazon_order_reference_id' => $oOrder->getMeta('amazon_order_reference_id'),
-				'closure_reason' => '',
-				'mws_auth_token' => $oOrder->getMeta('amazon_last_authorization_reference_id')
-			));
-			
-			if (wpsg_isSizedInt($this->shop->get_option('wpsg_debugModus'))) $oOrder->log('Amazon:closeOrderReference', print_r($oResponse->toArray(), 1));
-				
-			return $oResponse->toArray();
-			
-		} // private function api_closePayment($order_id)
-		
-		private function api_cancelPayment($order_id)
-		{
-				
-			require_once WPSG_PATH_MOD.'mod_amazon/PayWithAmazon/Client.php';
-		
-			$oOrder = wpsg_order::getInstance($order_id);
-			$client = new PayWithAmazon\Client($this->getAPIConfig());
-		
-			$oResponse = $client->cancelOrderReference(array(
-				'amazon_order_reference_id' => $oOrder->getMeta('amazon_order_reference_id')				
-			));
-				
-			if (wpsg_isSizedInt($this->shop->get_option('wpsg_debugModus'))) $oOrder->log('Amazon:cancelOrderReference', print_r($oResponse->toArray(), 1));
-		
-			return $oResponse->toArray();
-				
-		} // private function api_cancelPayment($order_id)
-	
-		private function api_refund($order_id)
-		{
-			
-			require_once WPSG_PATH_MOD.'mod_amazon/PayWithAmazon/Client.php';
-									
-			$oOrder = wpsg_order::getInstance($order_id);
-			$client = new PayWithAmazon\Client($this->getAPIConfig());
-			
-			$oResponse = $client->refund(array(
-				'amazon_capture_id' => $oOrder->getMeta('amazon_capture_id'),
-				'refund_reference_id' => 'R'.$oOrder->id,
-				'refund_amount' => $oOrder->getToPay(),
-				'currency_code' => 'EUR',
-				'seller_refund_note' => 'STORNO'
-			));
-			
-			$arReturn = $oResponse->toArray();
-			
-			if (wpsg_isSizedString($arReturn['RefundResult']['RefundDetails']['AmazonRefundId']))
-			{
-				
-				$oOrder->setMeta('amazon_refund_id', $arReturn['RefundResult']['RefundDetails']['AmazonRefundId']);
-				$oOrder->setMeta('amazon_capture_id', null);
-				
-			}
-			
-			if (wpsg_isSizedInt($this->shop->get_option('wpsg_debugModus'))) $oOrder->log('Amazon:refund', print_r($arReturn, 1));
-			
-			return $arReturn;
-			
-		} // private function api_refund($order_id)
-		
-		private function getAPIConfig()
-		{
-			
-			$config = array(
-				'merchant_id' => $this->shop->get_option('wpsg_mod_amazon_seller_id'),
-				'access_key' => $this->shop->get_option('wpsg_mod_amazon_mws_access_key_id'),
-				'secret_key' => $this->shop->get_option('wpsg_mod_amazon_mws_access_key'),
-				'region' => 'de',
-				'sandbox' => ((wpsg_isSizedInt($this->shop->get_option('wpsg_mod_amazon_sandbox')))?true:false)
-			);
-			
-			return $config;				
-			
-		} // private function getAPIConfig()
-		
-	} // class wpsg_mod_amazon extends wpsg_mod_basic
-
-?>
+
+    /**
+     * Modul fÃŒr "Bezahlen mit Amazon"
+     * @author Daschmi (12.03.2016)
+     */
+    class wpsg_mod_amazon extends wpsg_mod_basic
+    {
+
+        var $lizenz = 1;
+        var $id = 3140;
+        var $hilfeURL = 'http://wpshopgermany.de/?p=3462587';
+        var $version = "4.2.3";
+        var $free = false;
+
+        const ORDER_DONE_START = 0; // Zahlung starten lassen mit Pay with Amazon
+        const ORDER_DONE_GO = 1; // Zahlung gestartet, Wallet aneigen
+        const ORDER_DONE_PAST = 9; // Zahlung bereits durchgefÃŒhrt
+        const ORDER_DONE = 10; // Zahlung wurde gerade durchgefÃŒhrt
+
+        /**
+         * Kostruktor
+         */
+        public function __construct()
+        {
+
+            parent::__construct();
+
+            $this->name = __('AmazonPay', 'wpsg');
+            $this->group = __('Zahlungsarten', 'wpsg');
+            $this->desc = __('ErmÃ¶glicht die Anmeldung / Zahlung mit Amazon.', 'wpsg');
+
+        } // public function __construct()
+
+        public function install()
+        {
+
+            $this->shop->checkDefault('wpsg_mod_amazon_aktiv', '1');
+            $this->shop->checkDefault('wpsg_mod_amazon_basket', '1');
+            $this->shop->checkDefault('wpsg_mod_amazon_name', __('AmazonPay', 'wpsg'), false, true);
+            $this->shop->checkDefault('wpsg_mod_amazon_hint', __('Bezahlen Sie ihre Bestellung einfach mit ihrem Amazon Konto.', 'wpsg'), false, true);
+            $this->shop->checkDefault('wpsg_mod_amazon_subject', __('O%order_id% - K%kunde_id%', 'wpsg'), false, true);
+
+
+        } // public function install()
+
+        public function settings_edit()
+        {
+
+            $this->shop->view['ipnURL'] = $this->shop->getUrl(wpsg_ShopController::URL_BASKET, 'wpsg_mod_amazon', 'ipn');
+            $this->shop->view['jsOrigin'] = preg_replace('/^http:\/\//i', 'https://', $this->shop->get_option('siteurl'));
+
+            $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_amazon/settings_edit.phtml');
+
+        } // public function settings_edit()
+
+        public function settings_save()
+        {
+
+            $this->shop->update_option('wpsg_mod_amazon_sandbox', $_REQUEST['wpsg_mod_amazon_sandbox'], false, false, WPSG_SANITIZE_CHECKBOX);
+
+            $this->shop->update_option('wpsg_mod_amazon_seller_id', $_REQUEST['wpsg_mod_amazon_seller_id'], false, false, WPSG_SANITIZE_APIKEY);
+            $this->shop->update_option('wpsg_mod_amazon_mws_access_key_id', $_REQUEST['wpsg_mod_amazon_mws_access_key_id'], false, false, WPSG_SANITIZE_APIKEY);
+            $this->shop->update_option('wpsg_mod_amazon_mws_access_key', $_REQUEST['wpsg_mod_amazon_mws_access_key'], false, false, WPSG_SANITIZE_APIKEY);
+            $this->shop->update_option('wpsg_mod_amazon_lwa_client_id', $_REQUEST['wpsg_mod_amazon_lwa_client_id'], false, false, WPSG_SANITIZE_APIKEY);
+            $this->shop->update_option('wpsg_mod_amazon_lwa_client_secret', $_REQUEST['wpsg_mod_amazon_lwa_client_secret'], false, false, WPSG_SANITIZE_APIKEY);
+            $this->shop->update_option('wpsg_mod_amazon_sandbox', $_REQUEST['wpsg_mod_amazon_sandbox'], false, false, WPSG_SANITIZE_CHECKBOX);
+
+            $this->shop->update_option('wpsg_mod_amazon_aktiv', $_REQUEST['wpsg_mod_amazon_aktiv'], false, false, WPSG_SANITIZE_CHECKBOX);
+            $this->shop->update_option('wpsg_mod_amazon_name', $_REQUEST['wpsg_mod_amazon_name'], false, true, WPSG_SANITIZE_TEXTFIELD);
+            $this->shop->update_option('wpsg_mod_amazon_subject', $_REQUEST['wpsg_mod_amazon_subject'], false, true, WPSG_SANITIZE_TEXTFIELD);
+            $this->shop->update_option('wpsg_mod_amazon_hint', $_REQUEST['wpsg_mod_amazon_hint'], false, true, WPSG_SANITIZE_TEXTFIELD);
+            $this->shop->update_option('wpsg_mod_amazon_basket', $_REQUEST['wpsg_mod_amazon_basket'], false, false, WPSG_SANITIZE_CHECKBOX);
+
+            $this->shop->update_option('wpsg_mod_amazon_gebuehr', $_REQUEST['wpsg_mod_amazon_gebuehr'], false, false, WPSG_SANITIZE_FLOAT);
+            $this->shop->update_option('wpsg_mod_amazon_mwst', $_REQUEST['wpsg_mod_amazon_mwst'], false, false, WPSG_SANITIZE_TAXKEY);
+            $this->shop->update_option('wpsg_mod_amazon_mwstland', $_REQUEST['wpsg_mod_amazon_mwstland'], false, false, WPSG_SANITIZE_CHECKBOX);
+
+        } // public function settings_save()
+
+        public function basket_inner_prebutton(&$basket_view)
+        {
+
+            // Amazon ÃŒberhaupt mÃ¶glich
+            if (!array_key_exists($this->id, $this->shop->arPayment)) return;
+
+            if (!wpsg_isSizedInt($this->shop->get_option('wpsg_mod_amazon_aktiv')) || !wpsg_isSizedInt($this->shop->get_option('wpsg_mod_amazon_basket'))) return;
+
+            $oOrder = wpsg_order::getInstance($_SESSION['wpsg']['order_id']);
+
+            $this->shop->view['wpsg_mod_amazon']['redirectURL'] = $this->shop->getUrl(wpsg_ShopController::URL_BASKET, 'wpsg_mod_amazon', 'return');
+            $this->shop->view['wpsg_mod_amazon']['logoutURL'] = $this->shop->getUrl(wpsg_ShopController::URL_BASKET, 'wpsg_mod_amazon', 'logout');
+
+            $this->shop->view['wpsg_mod_amazon']['amazon_last_authorization_reference_id'] = $oOrder->getMeta('amazon_last_authorization_reference_id');
+
+            $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_amazon/basket_inner_prebutton.phtml');
+
+        } // public function basket_inner_prebutton(&$basket_view)
+
+        public function setOrderStatus($order_id, $status_id, $inform)
+        {
+
+            $oOrder = wpsg_order::getInstance($order_id);
+
+            if ($oOrder->getPaymentID() == $this->id && in_array($status_id, array(wpsg_ShopController::STATUS_STORNIERT, wpsg_ShopController::STATUS_ZURUECKGEZAHLT)))
+            {
+
+                $capture_id = $oOrder->getMeta('amazon_capture_id');
+
+                if (wpsg_isSizedString($capture_id))
+                {
+
+                    $arReturn = $this->api_refund($oOrder->id);
+
+                    if (wpsg_isSizedString($arReturn['RefundResult']['RefundDetails']['AmazonRefundId']))
+                    {
+
+                        $this->shop->addBackendMessage(__('Der Betrag wurde erfolgreich zurÃŒckerstattet.', 'wpsg'));
+
+                    }
+                    else
+                    {
+
+                        $this->shop->addBackendError(__('Es gab technische Probleme beim zurÃŒckerstatten des Betrages.', 'wpsg'));
+
+                        $oOrder->log(__('Fehler beim zurÃŒckerstatten des Bestellbetrages', 'wpsg'), print_r($arReturn, 1));
+
+                    }
+
+                }
+                else
+                {
+
+                    $this->shop->addBackendError(__('RÃŒckzahlung nicht mÃ¶glich, da keine Capture/Authorize ID gesetzt wurde', 'wpsg'));
+
+                }
+
+            }
+
+        } // public function setOrderStatus($order_id, $status_id, $inform)
+
+        public function wp_head()
+        {
+
+            if (!wpsg_isSizedInt($this->shop->get_option('wpsg_mod_amazon_aktiv'))) return;
+
+            echo '<script type="text/javascript"> window.onAmazonLoginReady = function() { amazon.Login.setClientId("'.$this->shop->get_option('wpsg_mod_amazon_lwa_client_id').'"); }; </script>';
+
+            if (wpsg_isSizedInt($this->shop->get_option('wpsg_mod_amazon_sandbox')))
+            {
+
+                echo '<script type="text/javascript" src="https://static-eu.payments-amazon.com/OffAmazonPayments/de/sandbox/lpa/js/Widgets.js"></script>';
+
+            }
+            else
+            {
+
+                echo '<script type="text/javascript" src="https://static-eu.payments-amazon.com/OffAmazonPayments/de/lpa/js/Widgets.js"></script>';
+
+            }
+
+        } // public function wp_head()
+
+        public function order_done(&$order_id, &$done_view)
+        {
+
+            $oOrder = wpsg_order::getInstance($order_id);
+
+            if ($oOrder->getToPay() <= 0 || $oOrder->getPaymentID() != $this->id) return;
+
+            if (wpsg_isSizedString($oOrder->getMeta('amazon_order_reference_id')) && !wpsg_isSizedString($oOrder->getMeta('amazon_order_done')))
+            {
+
+                // Zahlung durchfÃŒhren
+                $this->api_setPayment($order_id);
+                $this->api_finishPayment($order_id);
+
+                $capture_return = $this->api_capturePayment($order_id);
+
+                $this->api_closePayment($order_id);
+
+                if (wpsg_isSizedString($capture_return['AuthorizeResult']['AuthorizationDetails']['AuthorizationAmount']['Amount']))
+                {
+
+                    $amount_captured = wpsg_tf($capture_return['AuthorizeResult']['AuthorizationDetails']['AuthorizationAmount']['Amount']);
+
+                    if ($this->shop->setPayMent($oOrder->id, $amount_captured))
+                    {
+
+                        //$this->shop->setOrderStatus($oOrder->id, 100, true);
+                        $oOrder->setMeta('amazon_order_done', serialize($capture_return));
+
+                        $this->shop->view['wpsg_mod_amazon']['state'] = self::ORDER_DONE;
+                        return $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_amazon/order_done.phtml');
+
+                    }
+
+                }
+
+            }
+            else if (wpsg_isSizedString($oOrder->getMeta('amazon_order_done')))
+            {
+
+                $this->shop->view['wpsg_mod_amazon']['state'] = self::ORDER_DONE_PAST;
+                return $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_amazon/order_done.phtml');
+
+            }
+
+            if (wpsg_isSizedString($oOrder->getMeta('amazon_order_reference_id')))
+            {
+
+                $oOrder->setMeta('amazon_order_reference_id', null);
+                $oOrder->setMeta('amazon_last_authorization_reference_id', null);
+
+            }
+
+            if (wpsg_isSizedString($_REQUEST['access_token']))
+            {
+
+                $this->shop->view['wpsg_mod_amazon']['state'] = self::ORDER_DONE_GO;
+
+            }
+            else
+            {
+
+                $this->shop->view['wpsg_mod_amazon']['state'] = self::ORDER_DONE_START;
+
+            }
+
+            $this->shop->view['wpsg_mod_amazon']['redirectURL'] = $this->shop->getDoneURL($order_id);
+
+            return $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_amazon/order_done.phtml');
+
+        } // public function order_done($order_id, $done_view)
+
+        public function basket_checkoutAction(&$basketController)
+        {
+
+            if ($_SESSION['wpsg']['checkout']['payment'] != $this->id || !wpsg_isSizedInt($this->shop->get_option('wpsg_mod_amazon_basket'))) return;
+
+            if (wpsg_isSizedString($_REQUEST['amazon']['OrderReference']))
+            {
+
+                $oOrder = wpsg_order::getInstance($_SESSION['wpsg']['order_id']);
+
+                $oOrder->setMeta('amazon_order_reference_id', $_REQUEST['amazon']['OrderReference']);
+
+                $res = $this->api_getPayment($_SESSION['wpsg']['order_id']);
+
+                $res = $res['GetOrderReferenceDetailsResult']['OrderReferenceDetails'];
+
+                list($vname, $name) = wpsg_explodeName($res['Destination']['PhysicalDestination']['Name']);
+
+                if (wpsg_isSizedString($res['Buyer']['Email']) && !wpsg_isSizedString($_SESSION['wpsg']['checkout']['email']))
+                {
+
+                    $_SESSION['wpsg']['checkout']['email'] = $res['Buyer']['Email'];
+                    $_SESSION['wpsg']['checkout']['email2'] = $res['Buyer']['Email'];
+
+                }
+
+                if (wpsg_isSizedString($res['Buyer']['Phone'])) $_SESSION['wpsg']['checkout']['tel'] = $res['Buyer']['Phone'];
+
+                // Vereinfacht auf die Ãbernahme der Lieferadresse
+                if (wpsg_isSizedArray($res['Destination']['PhysicalDestination']))
+                {
+
+                    if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['vname'])) $_SESSION['wpsg']['checkout']['vname'] = $vname;
+                    if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['name'])) $_SESSION['wpsg']['checkout']['name'] = $name;
+
+                    if (wpsg_isSizedArray($res['Destination']['PhysicalDestination']['AddressLine1'])) $res['Destination']['PhysicalDestination']['AddressLine1'] = implode(' ', $res['Destination']['PhysicalDestination']['AddressLine1']);
+                    if (wpsg_isSizedArray($res['Destination']['PhysicalDestination']['AddressLine2'])) $res['Destination']['PhysicalDestination']['AddressLine1'] = implode(' ', $res['Destination']['PhysicalDestination']['AddressLine2']);
+
+                    if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['strasse'])) $_SESSION['wpsg']['checkout']['strasse'] = ltrim(implode(', ', array(
+                        wpsg_getStr($res['Destination']['PhysicalDestination']['AddressLine1']),
+                        wpsg_getStr($res['Destination']['PhysicalDestination']['AddressLine2']),
+                    )), ', ');
+                    if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['plz'])) $_SESSION['wpsg']['checkout']['plz'] = $res['Destination']['PhysicalDestination']['PostalCode'];
+                    if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['ort'])) $_SESSION['wpsg']['checkout']['ort'] = $res['Destination']['PhysicalDestination']['City'];
+
+                    // Land wenn gefunden
+                    $country_id = wpsg_country::getCountryIDFromCode($res['Destination']['PhysicalDestination']['CountryCode']);
+                    if (!wpsg_isSizedInt($_SESSION['wpsg']['checkout']['land']) && wpsg_isSizedString($country_id)) $_SESSION['wpsg']['checkout']['land'] = $country_id;
+
+                }
+
+                /*
+                if ($this->shop->hasMod('wpsg_mod_shippingadress'))
+                {
+
+                    // Lieferadresse ist aktiv
+                    // Lieferadresse aus Amazon -> Lieferadresse
+                    // Recnungsadresse aus Amazon -> Rechnungsadresse
+                    // Eventuell schauen ob gleich ist :?
+
+                    if (wpsg_isSizedArray($res['BillingAddress']['PhysicalAddress']))
+                    {
+
+                        if (wpsg_isSizedArray($res['BillingAddress']['PhysicalAddress']['AddressLine1'])) $res['BillingAddress']['PhysicalAddress']['AddressLine1'] = implode(' ', $res['Destination']['PhysicalDestination']['AddressLine1']);
+                        if (wpsg_isSizedArray($res['BillingAddress']['PhysicalAddress']['AddressLine2'])) $res['BillingAddress']['PhysicalAddress']['AddressLine1'] = implode(' ', $res['Destination']['PhysicalDestination']['AddressLine2']);
+
+                        if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['shipping_vname'])) $_SESSION['wpsg']['checkout']['shipping_vname'] = $vname;
+                        if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['shipping_name'])) $_SESSION['wpsg']['checkout']['shipping_name'] = $name;
+                        if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['strasse'])) $_SESSION['wpsg']['checkout']['strasse'] = ltrim(implode(', ', array(
+                                wpsg_getStr($res['BillingAddress']['PhysicalAddress']['AddressLine1']),
+                                wpsg_getStr($res['BillingAddress']['PhysicalAddress']['AddressLine2']),
+                        )), ', ');
+
+                        if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['plz'])) $_SESSION['wpsg']['checkout']['plz'] = $res['BillingAddress']['PhysicalAddress']['PostalCode'];
+                        if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['ort'])) $_SESSION['wpsg']['checkout']['ort'] = $res['BillingAddress']['PhysicalAddress']['City'];
+
+                        // Land wenn gefunden
+                        $country_id = wpsg_country::getCountryIDFromCode($res['BillingAddress']['PhysicalAddress']['CountryCode']);
+                        if (!wpsg_isSizedInt($_SESSION['wpsg']['checkout']['land']) && wpsg_isSizedString($country_id)) $_SESSION['wpsg']['checkout']['land'] = $country_id;
+
+                    }
+
+                    if (wpsg_isSizedArray($res['Destination']['PhysicalDestination']))
+                    {
+
+                        if (wpsg_isSizedArray($res['Destination']['PhysicalDestination']['AddressLine1'])) $res['Destination']['PhysicalDestination']['AddressLine1'] = implode(' ', $res['Destination']['PhysicalDestination']['AddressLine1']);
+                        if (wpsg_isSizedArray($res['Destination']['PhysicalDestination']['AddressLine2'])) $res['Destination']['PhysicalDestination']['AddressLine1'] = implode(' ', $res['Destination']['PhysicalDestination']['AddressLine2']);
+
+                        if (!isset($_SESSION['wpsg']['checkout']['diff_shippingadress'])) $_SESSION['wpsg']['checkout']['diff_shippingadress'] = '1';
+                        if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['shipping_vname'])) $_SESSION['wpsg']['checkout']['shipping_vname'] = $vname;
+                        if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['shipping_name'])) $_SESSION['wpsg']['checkout']['shipping_name'] = $name;
+                        if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['shipping_strasse'])) $_SESSION['wpsg']['checkout']['shipping_strasse'] = ltrim(implode(', ', array(
+                            wpsg_getStr($res['Destination']['PhysicalDestination']['AddressLine1']),
+                            wpsg_getStr($res['Destination']['PhysicalDestination']['AddressLine2']),
+                        )), ', ');
+                        if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['shipping_plz'])) $_SESSION['wpsg']['checkout']['shipping_plz'] = $res['Destination']['PhysicalDestination']['PostalCode'];
+                        if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['shipping_ort'])) $_SESSION['wpsg']['checkout']['shipping_ort'] = $res['Destination']['PhysicalDestination']['City'];
+
+                        // Land wenn gefunden
+                        $country_id = wpsg_country::getCountryIDFromCode($res['Destination']['PhysicalDestination']['CountryCode']);
+                        if (!wpsg_isSizedInt($_SESSION['wpsg']['checkout']['shipping_land']) && wpsg_isSizedString($country_id)) $_SESSION['wpsg']['checkout']['shipping_land'] = $country_id;
+
+                    }
+
+                }
+                else
+                {
+
+                    // Modul "Lieferanschrift" ist deaktiviert
+                    // Ich nehme hier als Liefer- und Rechnungsanschrift die Daten aus Amazon Lieferanschrift
+                    if (wpsg_isSizedArray($res['Destination']['PhysicalDestination']))
+                    {
+
+                        if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['vname'])) $_SESSION['wpsg']['checkout']['vname'] = $vname;
+                        if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['name'])) $_SESSION['wpsg']['checkout']['name'] = $name;
+
+                        if (wpsg_isSizedArray($res['Destination']['PhysicalDestination']['AddressLine1'])) $res['Destination']['PhysicalDestination']['AddressLine1'] = implode(' ', $res['Destination']['PhysicalDestination']['AddressLine1']);
+                        if (wpsg_isSizedArray($res['Destination']['PhysicalDestination']['AddressLine2'])) $res['Destination']['PhysicalDestination']['AddressLine1'] = implode(' ', $res['Destination']['PhysicalDestination']['AddressLine2']);
+
+                        if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['strasse'])) $_SESSION['wpsg']['checkout']['strasse'] = ltrim(implode(', ', array(
+                                wpsg_getStr($res['Destination']['PhysicalDestination']['AddressLine1']),
+                                wpsg_getStr($res['Destination']['PhysicalDestination']['AddressLine2']),
+                        )), ', ');
+                        if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['plz'])) $_SESSION['wpsg']['checkout']['plz'] = $res['Destination']['PhysicalDestination']['PostalCode'];
+                        if (!wpsg_isSizedString($_SESSION['wpsg']['checkout']['ort'])) $_SESSION['wpsg']['checkout']['ort'] = $res['Destination']['PhysicalDestination']['City'];
+
+                        // Land wenn gefunden
+                        $country_id = wpsg_country::getCountryIDFromCode($res['Destination']['PhysicalDestination']['CountryCode']);
+                        if (!wpsg_isSizedInt($_SESSION['wpsg']['checkout']['land']) && wpsg_isSizedString($country_id)) $_SESSION['wpsg']['checkout']['land'] = $country_id;
+
+                    }
+
+                }
+                */
+
+                $this->shop->basket->initFromSession(true);
+                $check1 = $this->shop->basket->checkCheckout(1);
+
+                if ($check1 === true)
+                {
+
+                    $check2 = $this->shop->basket->checkCheckout(2);
+
+                    if ($check2 === true)
+                    {
+
+                        $this->shop->redirect($this->shop->getUrl(wpsg_ShopController::URL_OVERVIEW));
+
+                    }
+                    else
+                    {
+
+                        $this->shop->redirect($this->shop->getUrl(wpsg_ShopController::URL_CHECKOUT2));
+
+                    }
+
+                }
+                else
+                {
+
+                    $this->shop->redirect($this->shop->getUrl(wpsg_ShopController::URL_CHECKOUT));
+
+                }
+
+            }
+
+            if ($bError) return -2;
+
+        } // public function basket_checkoutAction(&$basketController)
+
+        public function addPayment(&$arPayment)
+        {
+
+            if (is_admin() || $this->shop->get_option('wpsg_mod_amazon_aktiv') == '1') {
+
+                $arPayment[$this->id] = array(
+                    'id' => $this->id,
+                    'name' => __($this->shop->get_option('wpsg_mod_amazon_name'), 'wpsg'),
+                    'price' => $this->shop->get_option('wpsg_mod_amazon_gebuehr'),
+                    'tax_key' => $this->shop->get_option('wpsg_mod_amazon_mwst'),
+                    'mwst_null' => $this->shop->get_option('wpsg_mod_amazon_mwstland'),
+                    'hint' => __($this->shop->get_option('wpsg_mod_amazon_hint'), 'wpsg'),
+                    'logo' => $this->shop->getRessourceURL('mods/mod_amazon/gfx/logo_100x25.png')
+                );
+
+            }
+
+        } // public function addPayment(&$arPayment)
+
+        /* Redirect */
+
+        public function ipnRedirect() {
+
+            require_once WPSG_PATH_MOD.'mod_amazon/PayWithAmazon/IpnHandler.php';
+
+            $headers = $_SERVER; // getallheaders();
+            $body = file_get_contents('php://input');
+
+            $ipnHandler = new \PayWithAmazon\IpnHandler($headers, $body);
+            $ipnData = $ipnHandler->toArray();
+
+            if (wpsg_isSizedArray($ipnData) && wpsg_isSizedString($ipnData['NotificationType'], 'PaymentCapture'))
+            {
+
+                $order_id = $ipnData['CaptureDetails']['CaptureReferenceId'];
+                $oOrder = wpsg_order::getInstance($order_id);
+
+                if (wpsg_isSizedInt($this->shop->get_option('wpsg_debugModus'))) $oOrder->log('Amazon:notification:PaymentCapture', print_r($ipnData, 1));
+
+                if ($this->shop->setPayMent($order_id, $ipnData['CaptureDetails']['CaptureAmount']['Amount']) && wpsg_isSizedString($ipnData['CaptureDetails']['CaptureStatus']['State'], 'Completed'))
+                {
+
+                    $oOrder->setMeta('amazon_capture_id', $ipnData['CaptureDetails']['AmazonCaptureId']);
+
+                    $this->shop->setOrderStatus($order_id, 100, true);
+
+                }
+
+            }
+
+        } // public function ipnRedirect()
+
+        public function logoutRedirect()
+        {
+
+            $this->shop->redirect($this->shop->getUrl(wpsg_ShopController::URL_BASKET));
+
+        } // public function logoutRedirect()
+
+        public function returnRedirect()
+        {
+
+            if (wpsg_isSizedInt($_REQUEST['order_id']) && wpsg_isSizedString($_REQUEST['wpsg_done']))
+            {
+
+                $_REQUEST['order_id'] = wpsg_sinput("key", $_REQUEST['order_id']);
+
+                if (wpsg_isSizedString($_REQUEST['amazon']['OrderReference']))
+                {
+
+                    $hash = preg_replace('/(\+)|(\=)/', 'A', base64_encode(md5('wpShopGermany'.$_REQUEST['order_id'], $this->shop->get_option("wpsg_salt"))));
+
+                    if ($hash != $_REQUEST['wpsg_done']) die(__('Aufrufsfehler!!', 'wpsg'));
+
+                    $oOrder = wpsg_order::getInstance($_REQUEST['order_id']);
+                    $oOrder->setMeta('amazon_order_reference_id', $_REQUEST['amazon']['OrderReference']);
+
+                }
+
+                $this->shop->redirect($this->shop->getDoneURL($_REQUEST['order_id']));
+
+            }
+
+            if (!wpsg_isSizedInt($_SESSION['wpsg']['order_id'])) {
+
+                $this->shop->basket->initFromSession();
+                $this->shop->basket->save(false, false, true);
+
+            }
+
+            $oOrder = wpsg_order::getInstance($_SESSION['wpsg']['order_id']);
+            $oOrder->setMeta('amazon_last_authorization_reference_id', $_REQUEST['access_token']);
+
+            $_SESSION['wpsg']['checkout']['payment'] = $this->id;
+
+            if (wpsg_isSizedInt($this->shop->get_option('wpsg_mod_amazon_sandbox'))) $c = curl_init('https://api.sandbox.amazon.com/auth/o2/tokeninfo?access_token='. urlencode($_REQUEST['access_token']));
+            else $c = curl_init('https://api.amazon.com/auth/o2/tokeninfo?access_token='. urlencode($_REQUEST['access_token']));
+
+            curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
+            curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
+
+            $r = curl_exec($c); curl_close($c); $d = json_decode($r);
+
+            if ($d->aud != $this->shop->get_option('wpsg_mod_amazon_lwa_client_id'))
+            {
+
+                die("Amazon API Fehler!");
+                exit;
+
+            }
+
+            if (wpsg_isSizedInt($this->shop->get_option('wpsg_mod_amazon_sandbox'))) $c = curl_init('https://api.sandbox.amazon.com/user/profile');
+            else $c = curl_init('https://api.amazon.com/user/profile');
+
+            curl_setopt($c, CURLOPT_HTTPHEADER, array('Authorization: bearer '.$_REQUEST['access_token']));
+
+            curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
+            curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
+
+            $r = curl_exec($c); curl_close($c); $d = json_decode($r);
+
+            $_SESSION['wpsg']['checkout']['email'] = $d->email;
+            $_SESSION['wpsg']['checkout']['email2'] = $d->email;
+
+            $this->shop->redirect($this->shop->getUrl(wpsg_ShopController::URL_BASKET));
+
+        } // public function returnRedirect()
+
+        // Modulfunktionen
+
+        private function api_finishPayment($order_id)
+        {
+
+            require_once WPSG_PATH_MOD.'mod_amazon/PayWithAmazon/Client.php';
+
+            $oOrder = wpsg_order::getInstance($order_id);
+            $client = new PayWithAmazon\Client($this->getAPIConfig());
+
+            $oResponse = $client->confirmOrderReference(array(
+                'amazon_order_reference_id' => $oOrder->getMeta('amazon_order_reference_id'),
+                'mws_auth_token' => $oOrder->getMeta('amazon_last_authorization_reference_id')
+            ));
+
+            if (wpsg_isSizedInt($this->shop->get_option('wpsg_debugModus'))) $oOrder->log('Amazon:confirmOrderReference', print_r($oResponse->toArray(), 1));
+
+            return $oResponse->toArray();
+
+        } // private function api_finishPayment($order_id)
+
+        private function api_getPayment($order_id)
+        {
+
+            require_once WPSG_PATH_MOD.'mod_amazon/PayWithAmazon/Client.php';
+
+            $oOrder = wpsg_order::getInstance($order_id);
+            $client = new PayWithAmazon\Client($this->getAPIConfig());
+
+            $oResponse = $client->getOrderReferenceDetails(array(
+                'amazon_order_reference_id' => $oOrder->getMeta('amazon_order_reference_id'),
+                'address_consent_token' => $oOrder->getMeta('amazon_last_authorization_reference_id')
+            ));
+
+            if (wpsg_isSizedInt($this->shop->get_option('wpsg_debugModus'))) $oOrder->log('Amazon:getOrderReferenceDetails', print_r($oResponse->toArray(), 1));
+
+            return $oResponse->toArray();
+
+        } // private function api_getPayment($order_id)
+
+        private function api_setPayment($order_id)
+        {
+
+            require_once WPSG_PATH_MOD.'mod_amazon/PayWithAmazon/Client.php';
+
+            $oOrder = wpsg_order::getInstance($order_id);
+            $client = new PayWithAmazon\Client($this->getAPIConfig());
+
+            $oResponse = $client->setOrderReferenceDetails(array(
+                'amazon_order_reference_id' => $oOrder->getMeta('amazon_order_reference_id'),
+                'amount' => $oOrder->getToPay(),
+                'seller_order_id' => $oOrder->id,
+                'mws_auth_token' => $oOrder->getMeta('amazon_last_authorization_reference_id'),
+                'seller_note' => $this->shop->replaceUniversalPlatzhalter(__($this->shop->get_option('wpsg_mod_amazon_subject'), 'wpsg'), $order_id),
+                'currency_code' => 'EUR'
+            ));
+
+            if (wpsg_isSizedInt($this->shop->get_option('wpsg_debugModus'))) $oOrder->log('Amazon:setOrderReferenceDetails', print_r($oResponse->toArray(), 1));
+
+            return $oResponse->toArray();
+
+        } // private function api_setPayment($order_id)
+
+        private function api_capturePayment($order_id)
+        {
+
+            require_once WPSG_PATH_MOD.'mod_amazon/PayWithAmazon/Client.php';
+
+            $oOrder = wpsg_order::getInstance($order_id);
+            $client = new PayWithAmazon\Client($this->getAPIConfig());
+
+            $oResponse = $client->authorize(array(
+                'amazon_order_reference_id' => $oOrder->getMeta('amazon_order_reference_id'),
+                'authorization_amount' => $oOrder->getToPay(),
+                'authorization_reference_id' => $order_id,
+                'soft_descriptor' => $this->shop->replaceUniversalPlatzhalter(__($this->shop->get_option('wpsg_mod_amazon_subject'), 'wpsg'), $order_id),
+                'seller_authorization_note' => $this->shop->replaceUniversalPlatzhalter(__($this->shop->get_option('wpsg_mod_amazon_subject'), 'wpsg'), $order_id),
+                'currency_code' => 'EUR',
+                'capture_now' => true
+            ));
+
+            $arReturn = $oResponse->toArray();
+
+            if (wpsg_isSizedString($arReturn['AuthorizeResult']['AuthorizationDetails']['AmazonAuthorizationId'])) $oOrder->setMeta('amazon_capture_id', $arReturn['AuthorizeResult']['AuthorizationDetails']['AmazonAuthorizationId']);
+
+            if (wpsg_isSizedInt($this->shop->get_option('wpsg_debugModus'))) $oOrder->log('Amazon:authorize', print_r($arReturn, 1));
+
+            return $arReturn;
+
+        } // private function api_capturePayment($order_id)
+
+        private function api_closePayment($order_id)
+        {
+
+            require_once WPSG_PATH_MOD.'mod_amazon/PayWithAmazon/Client.php';
+
+            $oOrder = wpsg_order::getInstance($order_id);
+            $client = new PayWithAmazon\Client($this->getAPIConfig());
+
+            $oResponse = $client->closeOrderReference(array(
+                'amazon_order_reference_id' => $oOrder->getMeta('amazon_order_reference_id'),
+                'closure_reason' => '',
+                'mws_auth_token' => $oOrder->getMeta('amazon_last_authorization_reference_id')
+            ));
+
+            if (wpsg_isSizedInt($this->shop->get_option('wpsg_debugModus'))) $oOrder->log('Amazon:closeOrderReference', print_r($oResponse->toArray(), 1));
+
+            return $oResponse->toArray();
+
+        } // private function api_closePayment($order_id)
+
+        private function api_cancelPayment($order_id)
+        {
+
+            require_once WPSG_PATH_MOD.'mod_amazon/PayWithAmazon/Client.php';
+
+            $oOrder = wpsg_order::getInstance($order_id);
+            $client = new PayWithAmazon\Client($this->getAPIConfig());
+
+            $oResponse = $client->cancelOrderReference(array(
+                'amazon_order_reference_id' => $oOrder->getMeta('amazon_order_reference_id')
+            ));
+
+            if (wpsg_isSizedInt($this->shop->get_option('wpsg_debugModus'))) $oOrder->log('Amazon:cancelOrderReference', print_r($oResponse->toArray(), 1));
+
+            return $oResponse->toArray();
+
+        } // private function api_cancelPayment($order_id)
+
+        private function api_refund($order_id)
+        {
+
+            require_once WPSG_PATH_MOD.'mod_amazon/PayWithAmazon/Client.php';
+
+            $oOrder = wpsg_order::getInstance($order_id);
+            $client = new PayWithAmazon\Client($this->getAPIConfig());
+
+            $oResponse = $client->refund(array(
+                'amazon_capture_id' => $oOrder->getMeta('amazon_capture_id'),
+                'refund_reference_id' => 'R'.$oOrder->id,
+                'refund_amount' => $oOrder->getToPay(),
+                'currency_code' => 'EUR',
+                'seller_refund_note' => 'STORNO'
+            ));
+
+            $arReturn = $oResponse->toArray();
+
+            if (wpsg_isSizedString($arReturn['RefundResult']['RefundDetails']['AmazonRefundId']))
+            {
+
+                $oOrder->setMeta('amazon_refund_id', $arReturn['RefundResult']['RefundDetails']['AmazonRefundId']);
+                $oOrder->setMeta('amazon_capture_id', null);
+
+            }
+
+            if (wpsg_isSizedInt($this->shop->get_option('wpsg_debugModus'))) $oOrder->log('Amazon:refund', print_r($arReturn, 1));
+
+            return $arReturn;
+
+        } // private function api_refund($order_id)
+
+        private function getAPIConfig()
+        {
+
+            $config = array(
+                'merchant_id' => $this->shop->get_option('wpsg_mod_amazon_seller_id'),
+                'access_key' => $this->shop->get_option('wpsg_mod_amazon_mws_access_key_id'),
+                'secret_key' => $this->shop->get_option('wpsg_mod_amazon_mws_access_key'),
+                'region' => 'de',
+                'sandbox' => ((wpsg_isSizedInt($this->shop->get_option('wpsg_mod_amazon_sandbox')))?true:false)
+            );
+
+            return $config;
+
+        } // private function getAPIConfig()
+
+    } // class wpsg_mod_amazon extends wpsg_mod_basic
Index: /views/mods/mod_amazon/basket_inner_prebutton.phtml
===================================================================
--- /views/mods/mod_amazon/basket_inner_prebutton.phtml	(revision 7734)
+++ /views/mods/mod_amazon/basket_inner_prebutton.phtml	(revision 7735)
@@ -1,10 +1,10 @@
-<?php 
+<?php
 
-	/**
-	 * Template fÃŒr die Integration von "Bezahlen mit Amazon" in den Warenkorb
-	 */
+    /**
+     * Template fÃŒr die Integration von "Bezahlen mit Amazon" in den Warenkorb
+     */
 
 ?>
- 
+
 <div id="LoginWithAmazon"></div>
 
@@ -12,112 +12,128 @@
 <div class="wpsg_amazonhandler" id="walletWidgetDiv"></div>
 
+<style type="text/css">
+
+    #addressBookWidgetDiv{ width:auto; height:228px; margin:15px 0; }
+    #walletWidgetDiv { width:100%; height:228px; margin:15px 0; }
+    #walletWidgetDiv iframe,
+    #addressBookWidgetDiv iframe { max-width:100%; border:0px !important; }
+    #LoginWithAmazon { float:right; }
+    .wpsg_mod_paypalapi_button_wrap { float:left; }
+
+</style>
+
 <input type="hidden" name="amazon[OrderReference]" id="wpsg_mod_amazon_OrderReference" value="" />
 
 <div class="wpsg_clear"></div>
- 
-<script type="text/javascript">/* <![CDATA[ */
- 
-	var authRequest; 
 
-	OffAmazonPayments.Button('LoginWithAmazon', '<?php echo $this->get_option('wpsg_mod_amazon_seller_id'); ?>', {
-		
-		type:  "PwA", 
-		color: "Gold", 
-		size:  "small", 
-		language: "de-DE",
+<script>
 
-		authorization: function() { 
+    var authRequest;
 
-			loginOptions = {
-				scope: "profile payments:widget payments:shipping_address payments:billing_address", 
-				popup: true
-			}; 
-			
-			authRequest = amazon.Login.authorize(loginOptions, "<?php echo $this->view['wpsg_mod_amazon']['redirectURL']; ?>");
-				 
-		},
+    OffAmazonPayments.Button('LoginWithAmazon', '<?php echo $this->get_option('wpsg_mod_amazon_seller_id'); ?>', {
 
-		onError: function(error) { 
-		    
-			//console.log("Login: Es ist folgender Fehler aufgetreten: " + error.getErrorCode() + ' - ' + error.getErrorMessage());
-			alert("Login: Es ist folgender Fehler aufgetreten: " + error.getErrorCode() + ' - ' + error.getErrorMessage());
-				
-		} 
-	        
-	} );
+        type:  "PwA",
+        color: "Gold",
+        size:  "small",
+        language: "de-DE",
 
-	<?php if (wpsg_isSizedString($this->view['wpsg_mod_amazon']['amazon_last_authorization_reference_id']) && $this->view['basket']['checkout']['payment'] == 3140) { ?>
+        authorization: function() {
 
-	jQuery('.wpsg_checkoutbutton').hide();
-	jQuery('.wpsg_amazonhandler').show();
-	
-	new OffAmazonPayments.Widgets.AddressBook( {
-		
-	    sellerId: '<?php echo $this->get_option('wpsg_mod_amazon_seller_id'); ?>',
+            loginOptions = {
+                scope: "profile payments:widget payments:shipping_address payments:billing_address",
+                popup: true
+            };
 
-	    onOrderReferenceCreate: function(orderReference) {
+            authRequest = amazon.Login.authorize(loginOptions, "<?php echo $this->view['wpsg_mod_amazon']['redirectURL']; ?>");
 
-	    	var oID = orderReference.getAmazonOrderReferenceId();
-	    	
-			jQuery('#wpsg_mod_amazon_OrderReference').val(oID);
-			jQuery('.wpsg_checkoutbutton').show();
-	    			     
-	    },
-	    
-	    onAddressSelect: function(orderReference) {
- 
-		    // Replace the following code with the action that you want to perform
-		    // after the address is selected.
-		    // The amazonOrderReferenceId can be used to retrieve
-	    	// the address details by calling the GetOrderReferenceDetails
-		    // operation. If rendering the AddressBook and Wallet widgets on the
-		    // same page, you should wait for this event before you render the
-	    	// Wallet widget for the first time.
-		    // The Wallet widget will re-render itself on all subsequent
-		    // onAddressSelect events, without any action from you. It is not
-	    	// recommended that you explicitly refresh it.
+        },
 
-			new OffAmazonPayments.Widgets.Wallet({
+        onError: function(error) {
 
-	    	    sellerId: '<?php echo $this->get_option('wpsg_mod_amazon_seller_id'); ?>',
+            //console.log("Login: Es ist folgender Fehler aufgetreten: " + error.getErrorCode() + ' - ' + error.getErrorMessage());
+            alert("Login: Es ist folgender Fehler aufgetreten: " + error.getErrorCode() + ' - ' + error.getErrorMessage());
 
-	    	    onPaymentSelect: function(orderReference) {
+        }
 
-	    			// Replace this code with the action that you want to perform
-	    	      	// after the payment method is selected.
-	    		      
-	    	    },
-	    	    
-	    	    design: {
-		    	    
-	    	      	designMode: 'responsive'
-		    	      	
-	    	    },
-	    	    
-	    	    onError: function(error) {
+    } );
 
-	    	    	alert("Wallet: Es ist folgender Fehler aufgetreten: " + error.getErrorCode() + ' - ' + error.getErrorMessage());
-		    	     
-	    	    }
-	    	    
-	    	}).bind("walletWidgetDiv");
-	    	  
-	    },
-	    
-	    design: {
-		    
-	      designMode: 'responsive'
-		      
-	    },
-	    
-	    onError: function(error) {
+    <?php if (wpsg_isSizedString($this->view['wpsg_mod_amazon']['amazon_last_authorization_reference_id']) && $this->view['basket']['checkout']['payment'] == 3140) { ?>
 
-	    	alert("Payment: Es ist folgender Fehler aufgetreten: " + error.getErrorCode() + ' - ' + error.getErrorMessage());
-		       
-	    }
-	    
-	} ).bind("addressBookWidgetDiv");
+    jQuery(document).ready(function() {
 
-	<?php } ?>
-	
-/* ]]> */</script>
+        jQuery('.wpsg_checkoutbutton').hide();
+        jQuery('.wpsg_amazonhandler').show();
+        jQuery('#LoginWithAmazon').hide();
+
+        new OffAmazonPayments.Widgets.AddressBook( {
+
+            sellerId: '<?php echo $this->get_option('wpsg_mod_amazon_seller_id'); ?>',
+
+            onOrderReferenceCreate: function(orderReference) {
+
+                var oID = orderReference.getAmazonOrderReferenceId();
+
+                jQuery('#wpsg_mod_amazon_OrderReference').val(oID);
+                jQuery('.wpsg_checkoutbutton').show();
+
+            },
+
+            onAddressSelect: function(orderReference) {
+
+                // Replace the following code with the action that you want to perform
+                // after the address is selected.
+                // The amazonOrderReferenceId can be used to retrieve
+                // the address details by calling the GetOrderReferenceDetails
+                // operation. If rendering the AddressBook and Wallet widgets on the
+                // same page, you should wait for this event before you render the
+                // Wallet widget for the first time.
+                // The Wallet widget will re-render itself on all subsequent
+                // onAddressSelect events, without any action from you. It is not
+                // recommended that you explicitly refresh it.
+
+                new OffAmazonPayments.Widgets.Wallet({
+
+                    sellerId: '<?php echo $this->get_option('wpsg_mod_amazon_seller_id'); ?>',
+
+                    onPaymentSelect: function(orderReference) {
+
+                        // Replace this code with the action that you want to perform
+                        // after the payment method is selected.
+
+                    },
+
+                    design: {
+
+                        designMode: 'responsive'
+
+                    },
+
+                    onError: function(error) {
+
+                        alert("Wallet: Es ist folgender Fehler aufgetreten: " + error.getErrorCode() + ' - ' + error.getErrorMessage());
+
+                    }
+
+                }).bind("walletWidgetDiv");
+
+            },
+
+            design: {
+
+                designMode: 'responsive'
+
+            },
+
+            onError: function(error) {
+
+                alert("Payment: Es ist folgender Fehler aufgetreten: " + error.getErrorCode() + ' - ' + error.getErrorMessage());
+
+            }
+
+        } ).bind("addressBookWidgetDiv");
+
+    });
+
+    <?php } ?>
+
+</script>
