/**
  * adds given consumerData to Wirecard Checkout Page request
  * @param WirecardCEE_Client_QPay_Request_Initiation_ConsumerData $consumerData
  * @return WirecardCEE_Client_QPay_Request_Initiation
  */
 private function _addConsumerData(WirecardCEE_Client_QPay_Request_Initiation_ConsumerData $consumerData)
 {
     foreach ($consumerData->getData() as $key => $value) {
         $this->_setField($key, $value);
     }
     return $this;
 }
 /**
  * Process the seamless Payment after Order is complete
  *
  * @param Varien_Event_Observer $observer
  *
  * @throws Exception
  * @return Phoenix_WirecardCheckoutPage_Model_Observer
  */
 public function salesOrderPaymentPlaceEnd(Varien_Event_Observer $observer)
 {
     /**
      * @var Phoenix_WirecardCheckoutPage_Model_Abstract
      */
     $payment = $observer->getPayment();
     $this->_order = $payment->getOrder();
     $storeId = $this->_order->getStoreId();
     $paymentInstance = $payment->getMethodInstance();
     if (Mage::getStoreConfigFlag('payment/' . $payment->getMethod() . '/useSeamless', $storeId)) {
         $storageId = $payment->getAdditionalData();
         $orderIdent = $this->_order->getQuoteId();
         $customerId = Mage::getStoreConfig('payment/' . $payment->getMethod() . '/customer_id', $storeId);
         $shopId = Mage::getStoreConfig('payment/' . $payment->getMethod() . '/shop_id', $storeId);
         $secretKey = Mage::getStoreConfig('payment/' . $payment->getMethod() . '/secret_key', $storeId);
         $serviceUrl = Mage::getUrl(Mage::getStoreConfig('payment/' . $payment->getMethod() . '/service_url', $storeId));
         $paymentType = $this->_getMappedPaymentCode($payment->getMethod());
         $returnurl = Mage::getUrl('wirecard_checkout_page/processing/checkresponse', array('_secure' => true, '_nosid' => true));
         $pluginVersion = WirecardCEE_Client_QPay_Request_Initiation::generatePluginVersion('Magento', Mage::getVersion(), $paymentInstance->getPluginName(), $paymentInstance->getPluginVersion());
         $initiation = new WirecardCEE_Client_QPay_Request_Initiation($customerId, $shopId, $secretKey, substr(Mage::app()->getLocale()->getLocaleCode(), 0, 2), $pluginVersion);
         $consumerData = new WirecardCEE_Client_QPay_Request_Initiation_ConsumerData();
         if (Mage::getStoreConfigFlag('payment/' . $payment->getMethod() . '/send_additional_data', $storeId)) {
             $consumerData->setEmail($this->_order->getCustomerEmail());
             $dob = $payment->getMethodInstance()->getCustomerDob();
             if ($dob) {
                 $consumerData->setBirthDate($dob);
             }
             $consumerData->addAddressInformation($this->_getBillingObject());
             if ($this->_order->hasShipments()) {
                 $consumerData->addAddressInformation($this->_getShippingObject());
             }
         }
         if ($payment->getMethod() == 'wirecard_checkout_page_invoice' || $payment->getMethod() == 'wirecard_checkout_page_installment') {
             $consumerData->setEmail($this->_order->getCustomerEmail());
             $dob = $payment->getMethodInstance()->getCustomerDob();
             if ($dob) {
                 $consumerData->setBirthDate($dob);
             } else {
                 throw new Exception('Invalid dob');
             }
             $consumerData->addAddressInformation($this->_getBillingObject('invoice'));
         }
         $consumerData->setIpAddress($this->_order->getRemoteIp());
         $consumerData->setUserAgent(Mage::app()->getRequest()->getServer('HTTP_USER_AGENT'));
         $initiation->setConfirmUrl(Mage::getUrl('wirecard_checkout_page/processing/seamlessConfirm', array('_secure' => true, '_nosid' => true)));
         $initiation->setWindowName('paymentIframe');
         $initiation->orderId = $this->_order->getIncrementId();
         $initiation->companyTradeRegistryNumber = $payment->getMethodInstance()->getCompanyTradeRegistrationNumber();
         if ($orderIdent && $storageId) {
             $initiation->setStorageReference($orderIdent, $storageId);
         }
         if (Mage::getStoreConfigFlag('payment/' . $payment->getMethod() . '/auto_deposit', $storeId)) {
             $initiation->setAutoDeposit(true);
         }
         $initiation->setOrderReference($this->_order->getIncrementId());
         $financialInstitution = $payment->getMethodInstance()->getFinancialInstitution();
         if ($financialInstitution) {
             $initiation->setFinancialInstitution($financialInstitution);
         }
         Phoenix_WirecardCheckoutPage_Helper_Configuration::configureWcsLibrary();
         $response = $initiation->initiate(round($this->_order->getBaseGrandTotal(), 2), $this->_order->getBaseCurrencyCode(), $paymentType, $this->_order->getIncrementId(), $returnurl, $returnurl, $returnurl, $returnurl, $serviceUrl, $consumerData);
         if (isset($response) && $response->getStatus() == WirecardCEE_Client_QPay_Response_Initiation::STATE_SUCCESS) {
             $payment->setAdditionalData(serialize($payment->getAdditionalData()))->save();
             Mage::getSingleton('core/session')->unsetData('wirecard_checkout_page_payment_info');
             Mage::getSingleton('core/session')->setWirecardCheckoutPageRedirectUrl(urldecode($response->getRedirectUrl()));
         } elseif (isset($response)) {
             $errorMessage = '';
             foreach ($response->getErrors() as $error) {
                 $errorMessage .= ' ' . $error->getMessage();
             }
             throw new Exception(trim($errorMessage));
         } else {
             $payment->setAdditionalData(serialize($payment->getAdditionalData()))->save();
             Mage::getSingleton('core/session')->unsetData('wirecard_checkout_page_payment_info');
         }
     }
     return $this;
 }