@param TdbShopOrder                  $oOrder
@param bool                          $bSponsored
@param IMapperCacheTriggerRestricted $oCacheTriggerManager
@param $bCachingEnabled

@return array
516168
protected function getVoucherList(TdbShopOrder $oOrder, $bSponsored = false, IMapperCacheTriggerRestricted $oCacheTriggerManager, $bCachingEnabled)
    {
        $aVoucherList = array();

        // get vouchers
        $oVoucherUseList = &$oOrder->GetFieldShopVoucherUseList();
        $oVoucherUseList->GoToStart();
        if (0 < $oVoucherUseList->Length()) {
            while ($oVoucherUse = &$oVoucherUseList->Next()) {
                if ($bCachingEnabled) {
                    $oCacheTriggerManager->addTrigger($oVoucherUse->table, $oVoucherUse->id);
                }
                $oVoucher = $oVoucherUse->GetFieldShopVoucher();
                if (null !== $oVoucher) {
                    if ($bCachingEnabled) {
                        $oCacheTriggerManager->addTrigger($oVoucher->table, $oVoucher->id);
                    }
                    if (false === $oVoucher->IsSponsored() && false === $bSponsored) {
                        $aVoucher = $this->getDataFromVoucher($oVoucherUse, $oVoucher, $oCacheTriggerManager, $bCachingEnabled);
                        $aVoucherList[] = $aVoucher;
                    } elseif (true === $oVoucher->IsSponsored() && true === $bSponsored) {
                        $aVoucher = $this->getDataFromVoucher($oVoucherUse, $oVoucher, $oCacheTriggerManager, $bCachingEnabled);
                        $aVoucherList[] = $aVoucher;
                    }
                } else {
                    $aVoucher = $this->getDataFromVoucher($oVoucherUse, null, $oCacheTriggerManager);
                    $aVoucherList[] = $aVoucher;
                }
            }
            $oVoucherUseList->GoToStart();
        }

        return $aVoucherList;
    }
764878
public function capture($oOrder = null, $aRequestParameters = array())
    {
        $oData = $this->_callOrderRequest(
            'capture',
            $oOrder,
            $aRequestParameters,
            array(
                'amazon_authorization_id',
                'capture_amount',
                'currency_code',
                'capture_reference_id',
                'seller_capture_note'
            ),
            $blProcessable
        );

        //Update Order info
        if ($blProcessable === true && isset($oData->CaptureResult->CaptureDetails)) {
            $this->setCaptureState($oOrder, $oData->CaptureResult->CaptureDetails);
            $this->closeOrderReference($oOrder, array(), false);
        }

        return $oData;
    }
526375
protected function _preFinalizeOrder(oxBasket &$oBasket, &$oUser, &$blIsAmazonOrder, &$blAuthorizeAsync)
    {
        $blAuthorizeAsync = false;
        $oContainer = $this->_getContainer();
        $oSession = $oContainer->getSession();
        $oUtils = $oContainer->getUtils();
        $oConfig = $oContainer->getConfig();

        $blIsAmazonOrder = $oBasket->getPaymentId() === 'bestitamazon'
            && $oConfig->getRequestParameter('cl') === 'order';

        //Situation when amazonOrderReferenceId was wiped out somehow, do cleanup and redirect
        if ($blIsAmazonOrder === true) {
            $sAmazonOrderReferenceId = (string)$oSession->getVariable('amazonOrderReferenceId');

            if ($sAmazonOrderReferenceId === '') {
                $oUtils->redirect($oConfig->getShopSecureHomeUrl().'cl=user&fnc=cleanAmazonPay', false);
                return false;
            }

            $sBasketHash = $oContainer->getBasketUtil()->getBasketHash($sAmazonOrderReferenceId, $oBasket);
            $sCurrentBasketHash = $oConfig->getRequestParameter('amazonBasketHash');
            $sCurrentBasketHash = $sCurrentBasketHash === null ?
                $oSession->getVariable('sAmazonBasketHash') :
                $sCurrentBasketHash;

            if ($sCurrentBasketHash !== $sBasketHash) {
                $oUtils->redirect($oConfig->getShopSecureHomeUrl().'cl=user&fnc=cleanAmazonPay', false);
                return false;
            }

            //Get Full customer data from Amazon
            $oData = $oContainer->getClient()->getOrderReferenceDetails();
            $sStatus = (string)$oData->GetOrderReferenceDetailsResult
                ->OrderReferenceDetails->OrderReferenceStatus->State;

            if ($sStatus !== 'Open') {
                $oUtils->redirect($oConfig->getShopSecureHomeUrl().'cl=user&fnc=cleanAmazonPay', false);
                return false;
            }

            $blOptimizedFlow = (string)$oConfig->getConfigParam('sAmazonMode')
                === bestitAmazonPay4OxidClient::OPTIMIZED_FLOW;

            //Call Amazon authorize (Dedicated for Sync mode), don't call if ERP mode is enabled
            if ((bool)$oConfig->getConfigParam('blAmazonERP') !== true
                && $this->_callSyncAmazonAuthorize($oBasket, $sAmazonOrderReferenceId, $blOptimizedFlow) === false
            ) {
                if ($blOptimizedFlow === true) {
                    $blAuthorizeAsync = true;
                } else {
                    return false;
                }
            }

            //Manage full user data with user data updates
            $oAmazonData = $oData->GetOrderReferenceDetailsResult->OrderReferenceDetails;
            $oUser = $this->_manageFullUserData($oUser, $oAmazonData);
        }

        return true;
    }
928211
public function closeOrderReference($oOrder = null, $aRequestParameters = array(), $blUpdateOrderStatus = true)
    {
        $oData = $this->_callOrderRequest(
            'closeOrderReference',
            $oOrder,
            $aRequestParameters,
            array('amazon_order_reference_id'),
            $blProcessable,
            'AMZ-Order-Closed'
        );

        //Update Order info
        if ($blUpdateOrderStatus === true && $blProcessable === true) {
            $oOrder->assign(array(
                'oxtransstatus' => 'AMZ-Order-Closed'
            ));
            $oOrder->save();
        }

        return $oData;
    }
56182
protected function _parentFinalizeOrder(oxBasket $oBasket, $oUser, $blRecalculatingOrder = false)
    {
        return parent::finalizeOrder($oBasket, $oUser, $blRecalculatingOrder);
    }
536737
protected function GetPaymentPayload($oOrder, $dPaymentAmount = null)
    {
        $oCurrency = null;
        if (method_exists($oOrder, 'GetFieldPkgShopCurrency')) {
            $oCurrency = $oOrder->GetFieldPkgShopCurrency();
        }
        if (null === $dPaymentAmount) {
            $dPaymentAmount = $oOrder->fieldValueTotal;
        }
        $sCurrency = $this->GetCurrencyIdentifier($oCurrency);
        $aPayload = array('MerchantID' => $this->GetConfigParameter('MerchantID'), 'TransID' => $this->GetTransactionIdForEasyCash($oOrder), 'Amount' => round($dPaymentAmount * 100), 'Currency' => $sCurrency, 'OrderDesc' => $this->GetOrderDescriptionTextForEasyCash($oOrder), 'Capture' => 'AUTO',
        );

        return $aPayload;
    }
553382
protected function getArticle(
        TdbShopOrderStatusItem $oPosition,
        IMapperCacheTriggerRestricted $oCacheTriggerManager,
        $bCachingEnabled
    ) {
        $oOrderItem = $oPosition->GetFieldShopOrderItem();
        $aArticle = array();
        /** @var $oArticle TdbShopArticle */
        $oArticle = &$oOrderItem->GetFieldShopArticle();

        $aArticle['iAmount'] = number_format((float) $oOrderItem->fieldOrderAmount, 0, ',', '');
        $aArticle['iUsedAmount'] = number_format($oPosition->fieldAmount, 0, ',', '');
        $aArticle['sManufacturer'] = $oOrderItem->fieldShopManufacturerName;
        $aArticle['sArticleName'] = $oOrderItem->fieldName;
        $aArticle['sArticleVariantName'] = $oOrderItem->fieldNameVariantInfo;
        $aArticle['sPrice'] = $oOrderItem->fieldOrderPriceFormated;
        $aArticle['sPriceTotal'] = $oOrderItem->fieldOrderPriceTotalFormated;
        $aArticle['sUsedPriceTotal'] = $oOrderItem->fieldPrice * $oPosition->fieldAmount;

        if ($oArticle) {
            $aArticle['sImageId'] = $this->getArticleImageId($oArticle, $oCacheTriggerManager, $bCachingEnabled);
            $aArticle = $this->GetVariantInfo($oArticle, $aArticle, $oCacheTriggerManager, $bCachingEnabled);
            $aArticle['sArticleDetailURL'] = $oArticle->getLink(true);
            if ($bCachingEnabled) {
                $oCacheTriggerManager->addTrigger($oArticle->table, $oArticle->id);
            }
        }

        return $aArticle;
    }
895610
protected function getActiveOrder(TdbShopOrderList $oOrderList)
    {
        $sActiveOrderParameter = $this->GetActiveOrderRequest();
        if (false !== $sActiveOrderParameter) {
            $oOrderList->AddFilterString("`shop_order`.`ordernumber` = '".$sActiveOrderParameter."'");
            $oOrderList->GoToStart();

            if (0 < $oOrderList->Length()) {
                return $oOrderList->Current();
            }
        }

        return null;
    }
87808
public function ExecutePayment(TdbShopOrder &$oOrder, $sMessageConsumer = '')
    {
        $bPaymentOk = parent::ExecutePayment($oOrder);
        if ($bPaymentOk) {
            TdbShopPaymentHandler::SetExecutePaymentInterrupt(true);
            $bPaymentOk = $this->ExecuteIPaymentCall($oOrder);
        }

        return $bPaymentOk;
    }
969315
private function getOrder(TdbShopOrder $oOrder, $bCachingEnabled, IMapperCacheTriggerRestricted $oCacheTriggerManager)
    {
        $aOrder = array();

        $oLocal = TCMSLocal::GetActive();

        $aOrder['sOrderDate'] = $oLocal->FormatDate($oOrder->fieldDatecreated, TCMSLocal::DATEFORMAT_SHOW_DATE);
        $aOrder['sOrdernumber'] = $oOrder->fieldOrdernumber;
        $aOrder['sSumGrandTotal'] = $oOrder->fieldValueTotalFormated;
        $aOrder['sShippingAddress'] = $this->getShippingAddress($oOrder, $bCachingEnabled, $oCacheTriggerManager);
        $aOrder['sDetailLink'] = $this->getDetailLink($oOrder);
        $orderCurrency = $oOrder->GetFieldPkgShopCurrency();
        if (null !== $orderCurrency) {
            $aOrder['currencyIso'] = $orderCurrency->fieldIso4217;
            $aOrder['currencySymbol'] = $orderCurrency->fieldSymbol;
        }
        $aOrder['bActive'] = false;

        return $aOrder;
    }
1021247
private function getIPNIdentifierFromOrder(TdbShopOrder $oOrder)
    {
        $sIdentifier = null;
        $query = "SELECT `shop_payment_handler_group`.*
                    FROM `shop_payment_handler_group`
              INNER JOIN `shop_payment_handler` on `shop_payment_handler_group`.`id` = `shop_payment_handler`.`shop_payment_handler_group_id`
              INNER JOIN `shop_payment_method` on `shop_payment_handler`.`id` = `shop_payment_method`.`shop_payment_handler_id`
              INNER JOIN `shop_order` on `shop_payment_method`.`id` = `shop_order`.`shop_payment_method_id`
                   WHERE `shop_order`.`id` = '".MySqlLegacySupport::getInstance()->real_escape_string($oOrder->id)."'
        ";
        if ($aGroup = MySqlLegacySupport::getInstance()->fetch_assoc(MySqlLegacySupport::getInstance()->query($query))) {
            $sIdentifier = trim($aGroup['ipn_group_identifier']);
            if ('' === $sIdentifier) {
                $sIdentifier = trim($aGroup['system_name']);
            }
        }

        return $sIdentifier;
    }
103784
protected function getDiscounts(TdbShopOrder $oOrder, IMapperCacheTriggerRestricted $oCacheTriggerManager, $bCachingEnabled)
    {
        $aDiscountList = array();

        $oDiscountList = &$oOrder->GetFieldShopOrderDiscountList();
        $oDiscountList->GoToStart();
        if (0 < $oDiscountList->Length()) {
            while ($oDiscount = &$oDiscountList->Next()) {
                if ($bCachingEnabled) {
                    $oCacheTriggerManager->addTrigger($oDiscount->table, $oDiscount->id);
                }
                $aDiscount = array('sName' => $oDiscount->fieldName, 'dValue' => $oDiscount->fieldTotal, 'sValue' => TCMSLocal::GetActive()->FormatNumber($oDiscount->fieldTotal, 2));
                $aDiscountList[] = $aDiscount;
            }
            $oDiscountList->GoToStart();
        }

        return $aDiscountList;
    }
1200485
public function getOrderReferenceDetails($oOrder = null, array $aParams = array(), $blReadonly = false)
    {
        $aRequestParameters = array();
        $sAmazonOrderReferenceId = ($oOrder === null) ?
            (string)$this->getSession()->getVariable('amazonOrderReferenceId') : '';

        if ($oOrder !== null) {
            $aRequestParameters['amazon_order_reference_id'] = $oOrder->getFieldData('bestitamazonorderreferenceid');
        } elseif ($sAmazonOrderReferenceId !== '') {
            $aRequestParameters['amazon_order_reference_id'] = $sAmazonOrderReferenceId;
            $sLoginToken = (string)$this->getSession()->getVariable('amazonLoginToken');

            if ($sLoginToken !== '') {
                $aRequestParameters['address_consent_token'] = $sLoginToken;
            }
        }

        //Make request
        $aRequestParameters = array_merge($aRequestParameters, $aParams);

        $oData = $this->_convertResponse($this->_getAmazonClient()->getOrderReferenceDetails($aRequestParameters));

        //Update Order info
        if ($blReadonly === false
            && $oOrder !== null
            && isset($oData->GetOrderReferenceDetailsResult->OrderReferenceDetails->OrderReferenceStatus->State)
        ) {
            $this->processOrderReference(
                $oOrder,
                $oData->GetOrderReferenceDetailsResult->OrderReferenceDetails
            );
        }

        return $oData;
    }
918717
public function sendOrderEmailToOwner($order, $subject = null)
    {
        self::$blSendToOwnerWasCalled = true;
        self::$oOwnerOrder = $order;

        return null;
    }
267759
protected function HandleNotifyMessageForPaymentState($sPaymentState, $aParameter, $oOrder)
    {
        if (!$oOrder->fieldOrderIsPaid) {
            if ('9' === $sPaymentState) {
                $oOrder->SetStatusPaid(true);
                $oOrder->SetStatusCanceled(false);
                $this->HandleNotifyOrderOnChange($oOrder, true, true, true);
                TTools::WriteLogEntry('OGONE: handle notify message order ('.$aParameter['ORDERID'].') was activated and paid by notify (Status 9 paid)', 1, __FILE__, __LINE__);
            } elseif ('5' === $sPaymentState) {
                if ($oOrder->fieldCanceled || !$oOrder->fieldSystemOrderSaveCompleted) {
                    $oOrder->SetStatusCanceled(false);
                    $oOrder->SetStatusPaid(false);
                    TTools::WriteLogEntry('OGONE: handle notify message order ('.$aParameter['ORDERID'].') was activated by notify and set to not paid (Status 5 reservation)', 1, __FILE__, __LINE__);
                    $this->HandleNotifyOrderOnChange($oOrder, false, !$oOrder->fieldSystemOrderSaveCompleted, true);
                }
            } else {
                if ('6' === $sPaymentState || '1' === $sPaymentState || '2' === $sPaymentState || '0' === $sPaymentState) {
                    $oOrder->SetStatusCanceled(true);
                    $oOrder->SetStatusPaid(false);
                    $this->HandleNotifyOrderOnChange($oOrder, false, false, true);
                    TTools::WriteLogEntry('OGONE: handle notify message order ('.$aParameter['ORDERID'].') was canceled and set to not paid by notify (Status 0,1,2,6)', 1, __FILE__, __LINE__);
                }
            }
        } else {
            TTools::WriteLogEntry('OGONE: handle notify message order ('.$aParameter['ORDERID'].') was already paid nothing to do)', 1, __FILE__, __LINE__);
        }
    }
149179
public function getTransactionDataFromOrder(
        $sTransactionType = TPkgShopPaymentTransactionData::TYPE_PAYMENT,
        $aProductAmountRestriction = null,
        $bUseConfirmedTransactionsOnly = true
    ) {
        $dSignMultiplier = 1;
        if (TPkgShopPaymentTransactionData::TYPE_PAYMENT === $sTransactionType) {
            $aItemBaseToUse = $this->getBillableProducts($bUseConfirmedTransactionsOnly);
        } else {
            $aItemBaseToUse = $this->getRefundableProducts($bUseConfirmedTransactionsOnly);
        }

        $oTransactionData = new TPkgShopPaymentTransactionData($this->order, $sTransactionType);
        $dOrderTotal = 0;
        $dProductValue = 0;
        $bAllRemainingItemsSelected = true;
        $dDiscount = 0;

        $orderItems = $this->order->GetFieldShopOrderItemList();
        foreach ($aItemBaseToUse as $sShopOrderItemId => $iAmountAllowedForUse) {
            $iAmountForTransaction = $iAmountAllowedForUse;
            if (null !== $aProductAmountRestriction) {
                if (false === isset($aProductAmountRestriction[$sShopOrderItemId])) {
                    $bAllRemainingItemsSelected = false; // some items were skipped
                    continue;
                }

                $iAmountForTransaction = $dSignMultiplier * $aProductAmountRestriction[$sShopOrderItemId];

                if ($iAmountForTransaction > $iAmountAllowedForUse) {
                    $sMsg = "trying to use {$iAmountForTransaction} from item {$sShopOrderItemId} when only {$iAmountAllowedForUse} are available";
                    throw new TPkgCmsException_LogAndMessage(
                        TPkgShopPaymentTransactionManager::MESSAGE_ERROR,
                        array('sMessage' => $sMsg),
                        $sMsg,
                        array('order' => $this->order->sqlData)
                    );
                }
            }
            $oOrderItem = $orderItems->FindItemWithProperty('id', $sShopOrderItemId);
            if (false === $oOrderItem) {
                $sMsg = "unable to load the shop_order_item [{$this->order->id}] in order [{$sShopOrderItemId}]";
                throw new TPkgCmsException_LogAndMessage(
                    TPkgShopPaymentTransactionManager::MESSAGE_ERROR,
                    array('sMessage' => $sMsg),
                    $sMsg,
                    array('order' => $this->order->sqlData)
                );
            }

            //$totalQuantityForTransaction = $this->gettot
            $oItem = new TPkgShopPaymentTransactionItemData();
            $oItem
                ->setType(TPkgShopPaymentTransactionItemData::TYPE_PRODUCT)
                ->setAmount($dSignMultiplier * $iAmountForTransaction)
                ->setOrderItemId($sShopOrderItemId)
                ->setValue($oOrderItem->fieldOrderPrice);
            if (0 != $oItem->getAmount()) {
                $oTransactionData->addItem($oItem);
                $dOrderTotal += $oItem->getAmount() * $oItem->getValue();
                $dProductValue += $oItem->getAmount() * $oItem->getValue();
                $dDiscount += round(
                        (($oOrderItem->fieldOrderPriceAfterDiscounts / $oOrderItem->fieldOrderAmount) * $iAmountForTransaction),
                        2
                    ) - ($dSignMultiplier * $oItem->getAmount() * $oItem->getValue());
            }
            $bAllRemainingItemsSelected = $bAllRemainingItemsSelected && ($iAmountForTransaction == $iAmountAllowedForUse);
        }

        if ($dDiscount > 0 || $dDiscount < 0) {
            $oItem = new TPkgShopPaymentTransactionItemData();
            $oItem
                ->setType(TPkgShopPaymentTransactionItemData::TYPE_DISCOUNT)
                ->setAmount($dSignMultiplier)
                ->setValue($dDiscount);
            $oTransactionData->addItem($oItem);
            $dOrderTotal = $dOrderTotal + ($oItem->getAmount() * $oItem->getValue());
        }

        // shipping, payment, vouchers and "other" should always be used as quickly as possible
        $dShippingPrice = $this->order->fieldShopShippingGroupPrice - $this->getTransactionPositionTotalForType(
                TPkgShopPaymentTransactionItemData::TYPE_SHIPPING,
                true
            );
        if ($dShippingPrice > 0 || $dShippingPrice < 0) {
            $oItem = new TPkgShopPaymentTransactionItemData();
            $oItem
                ->setType(TPkgShopPaymentTransactionItemData::TYPE_SHIPPING)
                ->setAmount($dSignMultiplier)
                ->setValue($dShippingPrice);
            $oTransactionData->addItem($oItem);
            $dOrderTotal = $dOrderTotal + ($oItem->getAmount() * $oItem->getValue());
        }

        $dPaymentMethodPrice = $this->order->fieldShopPaymentMethodPrice - $this->getTransactionPositionTotalForType(
                TPkgShopPaymentTransactionItemData::TYPE_PAYMENT,
                true
            );
        if ($dPaymentMethodPrice > 0 || $dPaymentMethodPrice < 0) {
            $oItem = new TPkgShopPaymentTransactionItemData();
            $oItem
                ->setType(TPkgShopPaymentTransactionItemData::TYPE_PAYMENT)
                ->setAmount($dSignMultiplier)
                ->setValue($dPaymentMethodPrice);
            $oTransactionData->addItem($oItem);
            $dOrderTotal = $dOrderTotal + ($oItem->getAmount() * $oItem->getValue());
        }

        $dVoucher = $this->getTransactionOrderDataVoucherValue($sTransactionType, $dOrderTotal);

        if ($dVoucher > 0 || $dVoucher < 0) {
            $oItem = new TPkgShopPaymentTransactionItemData();
            $oItem
                ->setType(TPkgShopPaymentTransactionItemData::TYPE_VOUCHER)
                ->setAmount($dSignMultiplier)
                ->setValue($dVoucher);
            $oTransactionData->addItem($oItem);
            $dOrderTotal = $dOrderTotal + ($oItem->getAmount() * $oItem->getValue());
        }

        $dExpectedTotal = $dSignMultiplier * $this->getOrderTotalOtherValue();

        $dOther = $dExpectedTotal - $this->getTransactionPositionTotalForType(
                TPkgShopPaymentTransactionItemData::TYPE_OTHER,
                true
            );

        if ($dOther > 0 || $dOther < 0) {
            $oItem = new TPkgShopPaymentTransactionItemData();
            $oItem
                ->setType(TPkgShopPaymentTransactionItemData::TYPE_OTHER)
                ->setAmount($dSignMultiplier)
                ->setValue($dOther);
            $oTransactionData->addItem($oItem);
            $dOrderTotal = $dOrderTotal + ($oItem->getAmount() * $oItem->getValue());
        }

        $oTransactionData->setTotalValue($dOrderTotal);

        return $oTransactionData;
    }
613123
public function createApiLogsByOrderIdAndRequest($idOrder, $request)
    {
        $query = $this->getFactory()->createPaymentPayoneApiLogQuery()
            ->useSpyPaymentPayoneQuery()
            ->filterByFkSalesOrder($idOrder)
            ->endUse()
            ->filterByRequest($request)
            ->orderByCreatedAt(Criteria::DESC) //TODO: Index?
            ->orderByIdPaymentPayoneApiLog(Criteria::DESC);

        return $query;
    }