/**
  * Constructor for PENDING state - we need the fingeprint validator so we add it after the
  * parent::__construct($returnData)
  *
  * @param array $returnData
  */
 public function __construct($returnData, $secret, $hashAlgo = WirecardCEE_Stdlib_Fingerprint::HASH_ALGORITHM_HMAC_SHA512)
 {
     //@see WirecardCEE_Stdlib_Return_ReturnAbstract::__construct($returnData)
     parent::__construct($returnData);
     $oFingerprintValidator = new WirecardCEE_Stdlib_Validate_Fingerprint(array(self::$SECRET => $secret, self::$FINGERPRINT_ORDER_FIELD => 'responseFingerprintOrder'));
     $oFingerprintValidator->setHashAlgorithm($hashAlgo);
     $oFingerprintValidator->setOrderType(WirecardCEE_Stdlib_Validate_Fingerprint::TYPE_DYNAMIC);
     $this->addValidator($oFingerprintValidator, 'responseFingerprint');
 }
 /**
  * @param $type
  * @param $message
  * @param Order $order
  * @param \WirecardCEE_Stdlib_Return_ReturnAbstract $return
  *
  * @return \Magento\Sales\Api\Data\TransactionInterface|null
  */
 public function saveTransaction($type, $message, $order, $return)
 {
     $additionalInformation = array();
     foreach ($return->getReturned() as $fieldName => $fieldValue) {
         $additionalInformation[htmlentities($fieldName)] = htmlentities($fieldValue);
     }
     $payment = $order->getPayment();
     $tid = '';
     if ($return instanceof \WirecardCEE_Stdlib_Return_Success) {
         $tid = $return->getGatewayReferenceNumber();
     }
     /* generate dummy GwRef for pending payments */
     if (!strlen($tid)) {
         $tid = uniqid('tmp_');
     }
     $transaction = $this->_transactionBuilder->setPayment($payment)->setOrder($order)->setTransactionId($tid)->build($type);
     $transaction->setIsClosed(0);
     /* must be set as RAW_DETAILS, otherwise they are not displayed in the admin area */
     $transaction->setAdditionalInformation(Transaction::RAW_DETAILS, $additionalInformation);
     $payment->addTransactionCommentsToOrder($transaction, $message);
     return $transaction;
 }
 /**
  * Confirm the payment of an order
  *
  * @param Mage_Sales_Model_Order $order
  * @param WirecardCEE_Stdlib_Return_ReturnAbstract $return
  */
 protected function _confirmOrder($order, $return)
 {
     /** @var Wirecard_CheckoutSeamless_Helper_Data $helper */
     $helper = Mage::helper('wirecard_checkoutseamless');
     if (!$this->_succeeded($order)) {
         if ($return->getPaymentState() == WirecardCEE_QMore_ReturnFactory::STATE_PENDING) {
             $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true, $helper->__('The payment authorization is pending.'))->save();
         } else {
             $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, $helper->__('The amount has been authorized and captured by Wirecard Checkout Seamless.'))->save();
             // invoice payment
             if ($order->canInvoice()) {
                 $invoice = $order->prepareInvoice();
                 $invoice->register()->capture();
                 Mage::getModel('core/resource_transaction')->addObject($invoice)->addObject($invoice->getOrder())->save();
             }
             // send new order email to customer
             $order->sendNewOrderEmail();
         }
     }
     $payment = $order->getPayment();
     $additionalInformation = array();
     foreach ($return->getReturned() as $fieldName => $fieldValue) {
         $additionalInformation[htmlentities($fieldName)] = htmlentities($fieldValue);
     }
     // need to remember whether confirm request was processed
     // check this within returnAction
     // could be if confirm request has bee blocked (firewall)
     $additionalInformation['confirmProcessed'] = true;
     $payment->setAdditionalInformation($additionalInformation);
     $payment->setAdditionalData(serialize($additionalInformation));
     $payment->save();
 }