<?php 

	/**
	 * Modul für die Zahlung über "wirecard"
	 * @author Daschmi
	 */
	class wpsg_mod_wirecard extends wpsg_mod_basic
	{
		
		var $lizenz = 2;
		var $id = 12; 
		var $hilfeURL = 'http://wpshopgermany.de/?p=7872';
		var $version = "9.9.9";
		var $free = true;
		
		/**
		 * Costructor
		 */
		public function __construct()
		{
				
			parent::__construct();
				
			$this->name = __('wirecard', 'wpsg');
			$this->group = __('Zahlungsarten', 'wpsg');
			$this->desc = __('Ermöglicht die Zahlungsart wirecard.', 'wpsg');
		
			if (is_object($this->shop) && method_exists($this->shop, 'getCurrentLanguage') && $this->shop->getCurrentLanguage() == 'en_US') $this->hilfeURL = 'http://wpshopgermany.de/?p=17187';
			
		} // public function __construct()
		
		public function install()
		{
			
			$this->shop->checkDefault('wpsg_mod_wirecard_name', __('wirecard Checkout Page', 'wpsg'), false, true);
			$this->shop->checkDefault('wpsg_mod_wirecard_activ', '1');
			$this->shop->checkDefault('wpsg_mod_wirecard_hint', __('Zahlen Sie die Bestellung mittels wirecard. Über wirecard sind verschiedene Zahlungsarten wie PayPal, Sofortüberweisung oder Kreditkarte möglich.', 'wpsg'), false, true);
			
			$this->shop->checkDefault('wpsg_mod_wirecard_paymenttype', 'SELECT');
			$this->shop->checkDefault('wpsg_mod_wirecard_gebuehr', '0');
			$this->shop->checkDefault('wpsg_mod_wirecard_mwst', '0');
			$this->shop->checkDefault('wpsg_mod_wirecard_mwstland', '0');
			$this->shop->checkDefault('wpsg_mod_wirecard_currency', 'EUR');
			$this->shop->checkDefault('wpsg_mod_wirecard_mode', '2');
			$this->shop->checkDefault('wpsg_mod_wirecard_submitadress', '0');
			$this->shop->checkDefault('wpsg_mod_wirecard_language', 'de');
			$this->shop->checkDefault('wpsg_mod_wirecard_autostart', '0');
			$this->shop->checkDefault('wpsg_mod_wirecard_minValue', '');
			$this->shop->checkDefault('wpsg_mod_wirecard_maxValue', '');
			$this->shop->checkDefault('wpsg_mod_wirecard_subject', 'O%order_id% - K%kunde_id%', false, true);
			
		} // public function install()
		
		public function init()
		{
			
		} // public function init()
		
		public function settings_edit()
		{
			
			$pages = get_pages();
				
			$arPages = array(
				'-1' => __('Neu anlegen und zuordnen', 'wpsg')
			);
				
			foreach ($pages as $k => $v)
			{
				$arPages[$v->ID] = $v->post_title.' (ID:'.$v->ID.')';
			}
				
			$this->shop->view['pages'] = $arPages;
			$this->shop->view['paymentTypes'] = $this->getWirecardPaymentTypes();
			
			$this->shop->render(WPSG_PATH_VIEW.'/mods/mod_wirecard/settings_edit.phtml');
			
		} // public function settings_edit()
		
		public function settings_save()
		{
			
			$this->shop->update_option('wpsg_mod_wirecard_name', $_REQUEST['wpsg_mod_wirecard_name']);
			$this->shop->update_option('wpsg_mod_wirecard_activ', $_REQUEST['wpsg_mod_wirecard_activ']);
			$this->shop->update_option('wpsg_mod_wirecard_hint', $_REQUEST['wpsg_mod_wirecard_hint']);
			$this->shop->update_option('wpsg_mod_wirecard_logo', $_REQUEST['wpsg_mod_wirecard_logo']);
			
			$this->shop->addTranslationString('wpsg_mod_wirecard_name', $_REQUEST['wpsg_mod_wirecard_name']);
			$this->shop->addTranslationString('wpsg_mod_wirecard_hint', $_REQUEST['wpsg_mod_wirecard_hint']);
			
			$this->shop->update_option('wpsg_mod_wirecard_customerid', $_REQUEST['wpsg_mod_wirecard_customerid']);
			$this->shop->update_option('wpsg_mod_wirecard_secret', $_REQUEST['wpsg_mod_wirecard_secret']);
			$this->shop->update_option('wpsg_mod_wirecard_shopid', $_REQUEST['wpsg_mod_wirecard_shopid']);
			
			$this->shop->update_option('wpsg_mod_wirecard_gebuehr', $_REQUEST['wpsg_mod_wirecard_gebuehr']);
			$this->shop->update_option('wpsg_mod_wirecard_mwst', $_REQUEST['wpsg_mod_wirecard_mwst']);
			$this->shop->update_option('wpsg_mod_wirecard_mwstland', $_REQUEST['wpsg_mod_wirecard_mwstland']);
			$this->shop->update_option('wpsg_mod_wirecard_currency', $_REQUEST['wpsg_mod_wirecard_currency']);
			$this->shop->update_option('wpsg_mod_wirecard_mode', $_REQUEST['wpsg_mod_wirecard_mode']);
			$this->shop->update_option('wpsg_mod_wirecard_language', $_REQUEST['wpsg_mod_wirecard_language']);
			$this->shop->update_option('wpsg_mod_wirecard_autostart', $_REQUEST['wpsg_mod_wirecard_autostart']);
			$this->shop->update_option('wpsg_mod_wirecard_subject', $_REQUEST['wpsg_mod_wirecard_subject']);
			$this->shop->update_option('wpsg_mod_wirecard_submitadress', $_REQUEST['wpsg_mod_wirecard_submitadress']);
			$this->shop->update_option('wpsg_mod_wirecard_minValue', $_REQUEST['wpsg_mod_wirecard_minValue']);
			$this->shop->update_option('wpsg_mod_wirecard_maxValue', $_REQUEST['wpsg_mod_wirecard_maxValue']);
			
			$this->shop->createPage(__('Erfolgreiche wirecard Zahlung', 'wpsg'), 'wpsg_page_mod_wirecard_success', $_REQUEST['wpsg_page_mod_wirecard_success']);
			$this->shop->createPage(__('Fehlgeschlagene wirecard Zahlung', 'wpsg'), 'wpsg_page_mod_wirecard_error', $_REQUEST['wpsg_page_mod_wirecard_error']);
			$this->shop->createPage(__('Abgebrochene wirecard Zahlung', 'wpsg'), 'wpsg_page_mod_wirecard_cancel', $_REQUEST['wpsg_page_mod_wirecard_cancel']);
			$this->shop->createPage(__('Unbestimmte wirecard Zahlung', 'wpsg'), 'wpsg_page_mod_wirecard_pending', $_REQUEST['wpsg_page_mod_wirecard_pending']);

			// Reihenfolge Zahlungsarten
			$this->shop->update_option('wpsg_mod_wirecard_paymentorder', implode(',', $_REQUEST['wpsg_mod_wirecard_paymentorder']));
						
			// Zahlungsarten
			$this->shop->update_option('wpsg_mod_wirecard_paymenttype', implode(',', $_REQUEST['wpsg_mod_wirecard_paymenttype']));
			
			//$this->shop->update_option('wpsg_mod_wirecard_paymenttype', $_REQUEST['wpsg_mod_wirecard_paymenttype']);
			
		} // public function settings_save()
		
		public function checkGeneralBackendError()
		{
				
			if (( !wpsg_isSizedString($this->shop->get_option('wpsg_mod_wirecard_secret')) || !wpsg_isSizedString($this->shop->get_option('wpsg_mod_wirecard_customerid')) ) && wpsg_isSizedInt($this->shop->get_option('wpsg_mod_wirecard_activ')))
			{
		
				$this->shop->addBackendError('nohspc_'.wpsg_translate(
					wpsg_translate(
						__('Das Modul "wirecard" ist aktiviert und es wurde kein geheimer Schlüssel und keine Kunden ID hinterlegt. Gehen Sie in die <a href="#1#">Einstellungen</a> des Moduls um den geheimen Schlüssel zu hinterlegen.', 'wpsg'),
						WPSG_URL_WP.'wp-admin/admin.php?page=wpsg-Admin&action=module&modul=wpsg_mod_wirecard'
					)
				));
		
			}
				
		} // public function checkGeneralBackendError()
		
		public function addPayment(&$arPayment)
		{
				
			if (!is_admin() && $this->shop->get_option('wpsg_mod_wirecard_activ') != '1') return;
		
			$mwst_value = $this->getTaxValue($this->shop->get_option('wpsg_mod_wirecard_activ'), $this->shop->getDefaultCountry());
						
			$arPayment[$this->id] = array(
				'id' => $this->id,
				'name' => __($this->shop->get_option('wpsg_mod_wirecard_name'), 'wpsg'),
				'preis' => $this->shop->get_option('wpsg_mod_wirecard_gebuehr'),
				'mwst' => $this->shop->get_option('wpsg_mod_wirecard_mwst'),
				'mwst_value' => $mwst_value,
				'mwst_null' => $this->shop->get_option('wpsg_mod_wirecard_mwstland'),				
				'logo' => $this->shop->getRessourceURL('mods/mod_wirecard/gfx/wirecard.png'),
				'logo_100x25' => $this->shop->getRessourceURL('mods/mod_wirecard/gfx/logo_100x25.png')
			);

			$this->shop->view['wpsg_mod_wirecard']['arPaymentTypes'] = $this->getWirecardPaymentTypes();
			
			foreach ($this->shop->view['wpsg_mod_wirecard']['arPaymentTypes'] as $k => $v) 
			{
				
				if (!in_array($k, (array)explode(',', $this->shop->get_option('wpsg_mod_wirecard_paymenttype')))) unset($this->shop->view['wpsg_mod_wirecard']['arPaymentTypes'][$k]);
				
			}
			
			// Fallback auf SELECT wenn nichts definiert wurde
			if (!wpsg_isSizedArray($this->shop->view['wpsg_mod_wirecard']['arPaymentTypes'])) 
			{
				 
				$this->shop->view['wpsg_mod_wirecard']['arPaymentTypes'] = array(
					'SELECT' => __('Auswahl innerhalb wirecard', 'wpsg')
				);
				
			}
			
			if (wpsg_isSizedString($_SESSION['wpsg']['checkout']['wpsg_mod_wirecard_paymentType']))
			{
				
				$this->shop->view['wpsg_mod_wirecard']['paymentTypeSet'] = $_SESSION['wpsg']['checkout']['wpsg_mod_wirecard_paymentType'];
				
			}
			
			$arPayment[$this->id]['hint'] = $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_wirecard/paymenthint.phtml', false);
							
			if (isset($_REQUEST['wpsg_checkout2']))
			{
			
				$arBasket = $this->shop->basket->toArray();
			
				if ($this->shop->get_option('wpsg_preisangaben') == WPSG_NETTO || $arBasket['noMwSt'])
				{
			
					$payment_netto = $this->getPreis($this->shop->get_option('wpsg_mod_wirecard_gebuehr'), $arBasket['sum']['preis']);
					$payment_brutto = wpsg_calculatePreis($payment_netto, WPSG_BRUTTO, $mwst_value);
			
				}
				else
				{
			
					$payment_brutto = $this->getPreis($this->shop->get_option('wpsg_mod_wirecard_gebuehr'), $arBasket['sum']['preis']);
					$payment_netto = wpsg_calculatePreis($payment_brutto, WPSG_NETTO, $mwst_value);
			
				}
			
				// Entsprechenden Preis anzeigen
				if ($this->shop->getFrontendTaxview() == WPSG_NETTO)
				{
						
					$arPayment[$this->id]['price'] = $payment_netto;
						
				}
				else
				{
						
					$arPayment[$this->id]['price'] = $payment_brutto;
						
				}
			
			}
			
		} // public function addPayment(&$arPayment)
		
		public function checkCheckout(&$state, &$error, &$arCheckout)
		{
			
			if ($arCheckout['payment'] != $this->id) return;
			
			if (
				(isset($_REQUEST['wpsg_checkout']) && isset($_REQUEST['wpsg_mod_wirecard_paymentType'])) ||
				(isset($_REQUEST['wpsg_checkout2']) && isset($_REQUEST['wpsg_mod_wirecard_paymentType']))
			)
			{
			
				if (in_array($_REQUEST['wpsg_mod_wirecard_paymentType'], array('INVOICE')))										
				{
					
					$arBasket = $this->shop->cache->getShopBasketArray();
					
					if ($arBasket['sum']['preis_gesamt_brutto'] < wpsg_tf($this->shop->get_option('wpsg_mod_wirecard_minValue')) || $arBasket['sum']['preis_gesamt_brutto'] > wpsg_tf($this->shop->get_option('wpsg_mod_wirecard_maxValue')))
					{
										
						$this->shop->addFrontendError(__('Die Zahlungsart wirecard - Rechnung ist auf Grund eines ungültigen Rechnungsbetrages nicht möglich.', 'wpsg'));					
						$error = true;
					
					}
					
				}  
				
				$_SESSION['wpsg']['checkout']['wpsg_mod_wirecard_paymentType'] = wpsg_xss($_REQUEST['wpsg_mod_wirecard_paymentType']);

				$arCheckout['wpsg_mod_wirecard_paymentType'] = $_SESSION['wpsg']['checkout']['wpsg_mod_wirecard_paymentType'];
				
			}
			
			$this->shop->arPayment[$this->id]['name'] .= ' ('.__($arCheckout['wpsg_mod_wirecard_paymentType'], 'wpsg').')';
			
		} // public function checkCheckout(&$state, &$error, &$arCheckout)
		
		public function calcPayment(&$arBasket)
		{

			if ($arBasket['checkout']['payment'] == $this->id)
			{
			
				$payment_price = $this->getPreis($this->shop->get_option('wpsg_mod_wirecard_gebuehr'), $arBasket['sum']['preis']);
			
				if ($this->shop->get_option('wpsg_mod_wirecard_mwstland') == '1' && $arBasket['noMwSt'])
				{
						
					// Keine MwSt. berechnen !
					$arBasket['sum']['preis_payment'] = $payment_price;
					$arBasket['sum']['preis_payment_brutto'] = $payment_price;
					$arBasket['sum']['preis_payment_netto'] = $payment_price;

					$arBasket['payment']['mwst'] = 0;
					$this->shop->arPayment[$arBasket['checkout']['payment']]['mwst_value'] = 0;
						
					$arBasket['payment']['tax_rata'] = false;
					
				}
				else
				{
						
					// MwSt berechnen (Angaben im Backend sind immer Brutto)
					$this->setPaymentKosten($arBasket, $payment_price, $this->shop->get_option('wpsg_mod_paypal_mwst'));
			
				}
			
			}
			
		} // public function calcPayment(&$arBasket)
		
		public function order_done(&$order_id, &$done_view)
		{
			
			global $q_config;
		
			if ($done_view['basket']['sum']['preis_gesamt_brutto'] > 0 && $this->shop->view['basket']['checkout']['payment'] == $this->id)
			{
				
				$oOrder = $this->shop->cache->loadOrderObject($order_id);
				
				if ($this->shop->get_option('wpsg_mod_wirecard_language') == 'auto')
				{
					 
					$arLocales = $q_config['locale'];
						
					if (wpsg_isSizedArray($arLocales) && wpsg_isSizedString(get_locale()) && in_array(get_locale(), $arLocales))
					{
				
						$language = array_search(get_locale(), $arLocales);
				
					}
					else
					{
							
						// Wenn Mehrsprachigkeit nicht korrekt konfiguriert oder ISO Code nicht ermittelt werden konnte
						// auf die schöne gute alte deutsche Sprache zurückgreifen
						$language = "de";
				
					}
						
				}
				else
				{
						
					$language = $this->shop->get_option('wpsg_mod_wirecard_language');
						
				}
				
				if (wpsg_isSizedString($done_view['basket']['checkout']['wpsg_mod_wirecard_paymentType']) && array_key_exists($done_view['basket']['checkout']['wpsg_mod_wirecard_paymentType'], $this->getWirecardPaymentTypes()))
				{
					
					$paymentType = $done_view['basket']['checkout']['wpsg_mod_wirecard_paymentType'];
					
				}
				else
				{
					
					// Fallback auf SELECT
					$paymentType = "SELECT";
					
				}
				
				$confirmURL = get_permalink($this->shop->get_option('wpsg_page_basket'));
					
				if (strpos($confirmURL, "?") > 0)
				{
					$confirmURL .= "&wpsg_plugin=wpsg_mod_wirecard&confirm=wc";
				}
				else
				{
					$confirmURL .= "?wpsg_plugin=wpsg_mod_wirecard&confirm=wc";
				}
		 
				$arParam = array(
					'consumerIpAddress' => $_SERVER['REMOTE_ADDR'],
					'consumerUserAgent' => $_SERVER['HTTP_USER_AGENT'],
					'customerId' => $this->shop->get_option('wpsg_mod_wirecard_customerid'),
					'shopId' => $this->shop->get_option('wpsg_mod_wirecard_shopid'),
					'currency' => $this->shop->get_option('wpsg_mod_wirecard_currency'),
					'language' => $language,
					'order_id' => $order_id,
					'orderReference' => $order_id,
					'successUrl' => get_permalink($this->shop->get_option('wpsg_page_mod_wirecard_success')),
					'failureUrl' => get_permalink($this->shop->get_option('wpsg_page_mod_wirecard_error')),
					'cancelUrl' => get_permalink($this->shop->get_option('wpsg_page_mod_wirecard_cancel')),
					'pendingUrl' => get_permalink($this->shop->get_option('wpsg_page_mod_wirecard_pending')),
					'serviceUrl' => $this->shop->getURL(wpsg_ShopController::URL_VERSANDKOSTEN),
					'confirmUrl' => $confirmURL,
					'paymentType' => $paymentType,
					'orderDescription' => $this->shop->replaceUniversalPlatzhalter('O%order_id% - K%kunde_id%', $order_id),
					'customerStatement' => $this->shop->replaceUniversalPlatzhalter('O%order_id% - K%kunde_id%', $order_id),
					'displayText' => $this->shop->replaceUniversalPlatzhalter('O%order_id% - K%kunde_id%', $order_id),
					'amount' => round(wpsg_tf($done_view['basket']['sum']['preis_gesamt_brutto']), 2),			
					'basketAmount' => round(wpsg_tf($oOrder->getAmount()), 2),
					'basketCurrency' => $this->shop->get_option('wpsg_mod_wirecard_currency'),
					'basketItems' => sizeof($oOrder->getOrderProducts())
				);

				if ($this->shop->get_option('wpsg_mod_wirecard_submitadress') == '1')
				{
					
					$arParam = $arParam + array(
						'consumerBillingFirstname' =>  $oOrder->getCustomer()->getFirstname(),
						'consumerBillingLastname' => $oOrder->getCustomer()->getName(),
						'consumerBillingAddress1' => $oOrder->getCustomer()->getStreet(),
						'consumerBillingCity' => $oOrder->getCustomer()->getCity(),
						'consumerBillingCountry' => $oOrder->getCustomer()->getCountryKuerzel(),
						'consumerBillingZipCode' => $oOrder->getCustomer()->getZip(),
						'consumerEmail' => $oOrder->getCustomer()->getEMail(),
						'consumerBirthDate' => $oOrder->getCustomer()->getBirthdate('Y-m-d'),
						'consumerShippingFirstName' => $oOrder->getShippingFirstName(),
						'consumerShippingLastName' => $oOrder->getShippingName(),
						'consumerShippingAddress1' => $oOrder->getShippingStreet(),
						'consumerShippingCity' => $oOrder->getShippingCity(),
						'consumerShippingCountry' => $oOrder->getShippingCountryKuerzel(),
						'consumerShippingZipCode' => $oOrder->getShippingZip()
					);
					
				}
				
				$index = 1;
				foreach ($oOrder->getOrderProducts() as $oOrderProduct)
				{
				
					$arParam['basketItem'.$index.'ArticleNumber'] = $oOrderProduct->getNumber();
					$arParam['basketItem'.$index.'Quantity'] = $oOrderProduct->getCount();
					$arParam['basketItem'.$index.'UnitPrice'] = round(wpsg_tf($oOrderProduct->getOneAmount(WPSG_NETTO)));
					$arParam['basketItem'.$index.'Tax'] = $oOrderProduct->getTaxValue();
					$arParam['basketItem'.$index.'Description'] = $oOrderProduct->getProduct()->getProductName();
												
					$index ++;
						
				}
				
				$this->addFingerprint($arParam);
  
				$strReturn = $this->shop->get_url_post_content('https://checkout.wirecard.com/page/init-server.php', $arParam);
				
				parse_str($strReturn, $arReturn);
				
				if (!wpsg_isSizedArray($arReturn) || array_key_exists('message', $arReturn) || !array_key_exists('redirectUrl', $arReturn))
				{
					
					if (array_key_exists('message', $arReturn)) $strReturn = $arReturn['message'];
					
					$this->db->ImportQuery(WPSG_TBL_OL, array(
						"title" => __("wirecard Fehler: Zahlung konnte nicht gestartet werden.", "wpsg"),
						"cdate" => "NOW()",
						"o_id" => wpsg_q($order_id),
						"mailtext" => wpsg_q("Parameter an wirecard:\r\n".print_r($arParam, 1)."\r\nRückgabe von wirecard:\r\n".$strReturn)
					));
					
					wpsg_debug("wirecard Zahlung konnte nicht gestartet werden!");
					wpsg_debug("Parameter an wirecard: ");
					wpsg_debug($arParam);
					wpsg_debug("Rückgabe von wirecard: ");
					wpsg_debug($strReturn);
					
					$this->shop->view['wpsg_mod_wirecard']['error'] = true;
					
					echo '<script type="text/javascript">location.href = "'.get_permalink($this->shop->get_option('wpsg_page_mod_wirecard_error')).'";</script>';
					
					//$this->shop->view['wpsg_mod_wirecard']['redirectUrl'] = get_permalink($this->shop->get_option('wpsg_page_mod_wirecard_error'));
					
				}
				else
				{
					  					
					$this->shop->view['wpsg_mod_wirecard']['error'] = false;
					$this->shop->view['wpsg_mod_wirecard']['redirectUrl'] = $arReturn['redirectUrl'];
					
				}
				 
				echo $this->shop->render(WPSG_PATH_VIEW.'/mods/mod_wirecard/order_done.phtml', false);
		
			}
		
		} // public function order_done(&$order_id)
		
		public function content_filter(&$content)
		{
			
			if (in_array(get_the_id(), array(
				$this->shop->get_option('wpsg_page_mod_wirecard_success'), 
				$this->shop->get_option('wpsg_page_mod_wirecard_error'),
				$this->shop->get_option('wpsg_page_mod_wirecard_cancel'), 
				$this->shop->get_option('wpsg_page_mod_wirecard_pending'))))
			{
				
				$iframeBreakout = '
					<script type="text/javascript">/* <![CDATA[ */
						
						(function(window) {
						
							if (window.location !== window.parent.location) {
   								window.parent.location = window.location;
  							}
						
							if (typeof window.opener == "object")
							{
							
								if (typeof window.opener.wirecard_popup == "object" && window.location !== window.opener.location) {
								
									window.opener.location = window.location;
									window.opener.wirecard_popup.close();
								
								}	
								
							}	
						
						})(this);

					/* ]]> */</script>						
				';
				
				$content = $iframeBreakout.$content;
				
				return -2;
				
			}
			
		}
		
		public function wp_loaded() 
		{
			
			if (wpsg_isSizedString($_REQUEST['wpsg_plugin'], 'wpsg_mod_wirecard') && wpsg_isSizedString($_REQUEST['confirm'], 'wc'))
			{
 
				// Hash prüfen
				$arHashKeys = explode(',', $_REQUEST['responseFingerprintOrder']);
				$strHASH = "";
				
				foreach ($arHashKeys as $key)
				{
					
					if ($key == "secret") $strHASH .= $this->shop->get_option('wpsg_mod_wirecard_secret');
					else $strHASH .= $_REQUEST[$key];
					
				}
				 
				if (md5($strHASH) == $_REQUEST['responseFingerprint'])
				{
					
					$this->db->ImportQuery(WPSG_TBL_OL, array(
						"title" => __("wirecard VERIFIED", "wpsg"),
						"cdate" => "NOW()",
						"o_id" => wpsg_q($_REQUEST['order_id']),
						"mailtext" => wpsg_q(wpsg_hspc(print_r($_REQUEST, 1)))
					));
					
					if ($this->shop->setPayMent($_REQUEST['order_id'], $_REQUEST['amount']))
					{
							
						$this->shop->setOrderStatus($_REQUEST['order_id'], 100, true);
							
					}
					
				}
				else if (wpsg_isSizedInt($_REQUEST['order_id']))
				{
					
					$this->db->ImportQuery(WPSG_TBL_OL, array(
						"title" => __("wirecard FAILED", "wpsg"),
						"cdate" => "NOW()",
						"o_id" => wpsg_q($_REQUEST['order_id']),
						"mailtext" => wpsg_q(wpsg_hspc(print_r($_REQUEST, 1)))
					));
					
				} 
				
			}
			
		} // public function wp_loaded() 
		
		public function mail_payment()
		{
		
			if ($this->shop->view['basket']['checkout']['payment'] != $this->id) return;
				
			if ($this->shop->htmlMail === true)
			{
				
				echo '<a href="'.$this->shop->getDoneURL($this->shop->view['o_id']).'">'.__('Zahlungslink', 'wpsg').'</a>'.__(', um die Zahlung durchzuführen', 'wpsg');
				
			}
			else
			{
			
				echo wpsg_pad_right(__('Zahlungslink', 'wpsg').':', 35).$this->shop->getDoneURL($this->shop->view['o_id']);
				
			}
				
		} // public function mail_payment()
		
		/* Modulfunktionen */
		
		/**
		 * Gibt einen Array mit allen bei Wirecard möglichen Zahlungsarten zurück
		 * Unabhängig von den tatsächlich verfügbaren
		 */
		private function getWirecardPaymentTypes()
		{

			$wirecardPaymentTypesReturn = array();
			
			$wirecardPaymentTypes = array(
				'SELECT' => __('Auswahl innerhalb wirecard', 'wpsg'),
				'BANCONTACT_MISTERCASH' => __('Bancontact/Mister Cash', 'wpsg'),
				'C2P' => __('CLICK2PAY', 'wpsg'),
				'CCARD' => __('Credit Card', 'wpsg'),
				'EKONTO' => __('eKonto', 'wpsg'),
				'EPS' => __('EPS e-payment ("EPS Online Überweisung")', 'wpsg'),
				'GIROPAY' => __('giropay', 'wpsg'),
				'IDL' => __('iDEAL', 'wpsg'),
				'INSTALLMENT' => __('Installment by payolution or RatePAY', 'wpsg'),
				'INVOICE' => __('Invoice by payolution or RatePAY', 'wpsg'),
				'MAESTRO' => __('Maestro SecureCode', 'wpsg'),
				'MONETA' => __('moneta.ru', 'wpsg'),
				'MPASS' => __('mpass', 'wpsg'),
				'PRZELEWY24' => __('Przelewy24', 'wpsg'),
				'PAYPAL' => __('PayPal', 'wpsg'),
				'PBX' => __('Paybox', 'wpsg'),
				'POLI' => __('POLi payments', 'wpsg'),
				'PSC' => __('Paysafecard', 'wpsg'),
				'QUICK' => __('Quick', 'wpsg'),
				'SEPA-DD' => __('SEPA Direct Debit', 'wpsg'),
				'SKRILLDIRECT' => __('Skrill Direct', 'wpsg'),
				'SKRILLWALLET' => __('Skrill Digital Wallet', 'wpsg'),
				'SOFORTUEBERWEISUNG' => __('sofort.com', 'wpsg'),
				'TRUSTLY' => __('Trustly', 'wpsg')
			);
			
			$wirecardPaymentTypesOrder = explode(',', $this->shop->get_option('wpsg_mod_wirecard_paymentorder'));
				
			if (wpsg_isSizedArray($wirecardPaymentTypesOrder))
			{
			 
				foreach ($wirecardPaymentTypesOrder as $pt)
				{
						
					if (array_key_exists($pt, $wirecardPaymentTypes))
					{
			
						$wirecardPaymentTypesReturn[$pt] = $wirecardPaymentTypes[$pt];
						unset($wirecardPaymentTypes[$pt]);
			
					}
						
				}
			
				// Sind noch Zahlungsarten da, die nicht im Sortier Array drin sind
				if (wpsg_isSizedArray($wirecardPaymentTypes))
				{
						
					foreach ($wirecardPaymentTypes as $pt_key => $pt)
					{
			
						$wirecardPaymentTypesReturn[$pt_key] = $pt;
			
					}
						
				}
			
			}
			else
			{
			
				$wirecardPaymentTypesReturn = $wirecardPaymentTypes;
			
			}
			
			return $wirecardPaymentTypesReturn;
			
		} // private function getWirecardPaymentTypes()

		/**
		 * Fügt den Fingerabdruck und die Fingerabdruck Reihenfolge hinzu
		 */
		private function addFingerprint(&$data)
		{
			
			$array_keys = array_keys($data);
			$array_keys[] = 'secret';
			$array_keys[] = 'requestFingerprintOrder';			
			shuffle($array_keys);
			
			$data['requestFingerprintOrder'] = implode(',', $array_keys);
						
			$arFingerprintValue = array();
			 
			foreach ($array_keys as $k => $v)
			{
					
				if ($v == "secret") $arFingerprintValue[] = $this->shop->get_option('wpsg_mod_wirecard_secret');
				else $arFingerprintValue[] = $data[$v];
					
			}
			 
			$data['requestFingerprint'] = md5(implode('', $arFingerprintValue)); 
			
		} // private function addFingerprint($data)
		
	} // class wpsg_mod_wirecard extends wpsg_mod_basic

?>