*
@param $str_xml
@return PagSeguroTransactionSearchResult
433255
public static function readSearchResult($str_xml)
    {

        $parser = new PagSeguroXmlParser($str_xml);
        $data = $parser->getResult('transactionSearchResult');

        $searchResutlt = new PagSeguroTransactionSearchResult();

        if (isset($data['totalPages'])) {
            $searchResutlt->setTotalPages($data['totalPages']);
        }

        if (isset($data['date'])) {
            $searchResutlt->setDate($data['date']);
        }

        if (isset($data['resultsInThisPage'])) {
            $searchResutlt->setResultsInThisPage($data['resultsInThisPage']);
        }

        if (isset($data['currentPage'])) {
            $searchResutlt->setCurrentPage($data['currentPage']);
        }

        if (isset($data['transactions']) && is_array($data['transactions'])) {
            $transactions = array();
            if (isset($data["transactions"]['transaction'][0])) {
                $i = 0;
                foreach ($data["transactions"]['transaction'] as $key => $value) {
                    $transactions[$i++] = self::parseTransactionSummary($value);
                }
            } else {
                $transactions[0] = self::parseTransactionSummary($data["transactions"]['transaction']);
            }
            $searchResutlt->setTransactions($transactions);
        }

        return $searchResutlt;
    }
155838
private static function _getTreeElm($str, &$info)
    {
        /*
         * Normalize the string.
         */
        $str = preg_replace('/(\n\r|\n|\r|\s)+/', ' ', $str);

        /*
         * Identify it by checking its first symbols.
         */
        if (strpos($str, '</') === 0) {
            return 'end';
        } elseif (strpos($str, '<!') === 0) {
            return 'content';
        } elseif (strpos($str, '<!--') === 0) {
            return 'comment';
        } elseif (strpos($str, '<') === 0) {
            preg_match('/<([a-zA-Z0-9]+)(.*?(?=\/>|>))(\/>|>)+/', $str, $info);

            return 'start';
        }

        return 'content';
    }
2441
public static function readInstallments($str_xml)
    {

        // Parser
        $parser = new PagSeguroXmlParser($str_xml);
        
        
        // <installment>
        $data = $parser->getResult('installments');
        
        
        // <installment><installments>
        if (isset($data)) {
            if (isset($data["installment"][0])) {
                foreach ($data["installment"] as $installment) {
                    $installments[] = new PagSeguroInstallment(
                        $installment['cardBrand'],
                        $installment['quantity'],
                        $installment['amount'],
                        $installment['totalAmount'],
                        $installment['interestFree']
                    );
                }
            } else {
                    $installments[] = new PagSeguroInstallment(
                        $data["installment"]['cardBrand'],
                        $data["installment"]['quantity'],
                        $data["installment"]['amount'],
                        $data["installment"]['totalAmount'],
                        $data["installment"]['interestFree']
                    );
            }
            $installments = new PagSeguroInstallments($installments);
            return $installments;
        }
    }
874631
static public function parse($str, $content_type)
    {
        switch ($content_type) {
            case 'json':
                return self::toJson($str);
            
            case 'xml':
                return self::toXml($str);

            default:
                return $str;
        }
    }
437476
public function fetchByName($str_key_name)
    {
        $arr_results = $this->fetchByNames([$str_key_name]);
        if(count($arr_results) > 0) {
            return $arr_results[0];
        }
        return null;
    }
1323971
protected function fetchByKeyPart(array $arr_key_parts, $str_setter)
    {

        // Build the query
        $obj_request = (object)[
            'keys' => []
        ];
        $this->applyTransaction($obj_request);

        // Add keys
        foreach($arr_key_parts as $str_key_part) {
            $obj_element = (object)['kind' => $this->obj_schema->getKind()];
            if('setId' === $str_setter) {
                $obj_element->id = $str_key_part;
            } elseif ('setName' === $str_setter) {
                $obj_element->name = $str_key_part;
            }
            $obj_key = (object)['path' => [$obj_element]];
            $this->applyPartition($obj_key);
            $obj_request->keys[] = $obj_key;
        }

        // Run
        $this->executePostRequest('lookup', $obj_request);

        // Extract results
        $arr_mapped_results = [];
        if(isset($this->obj_last_response->found) && is_array($this->obj_last_response->found)) {
            $arr_mapped_results = $this->createMapper()->mapFromResults($this->obj_last_response->found);
        }
        $this->obj_schema = null; // Consume Schema
        return $arr_mapped_results;
    }
625020
public function fetchByName($str_name)
    {
        return $this->obj_gateway
            ->withSchema($this->obj_schema)
            ->withTransaction($this->str_transaction_id)
            ->fetchByName($str_name);
    }
926950
static public function xml2arr($xml)
    {
        $disableEntities = libxml_disable_entity_loader(true);
        $result = json_decode(Tools::json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
        libxml_disable_entity_loader($disableEntities);
        return $result;
    }
1141594
protected function parseXML($xml){
        if (!$xml){
            return false;
        }
        
        foreach($xml->children() as $item){
            $n = $this->index;
            
            $this->itemList[$n]['ASIN'] = (string)$item->ASIN;
            $this->itemList[$n]['SellerSKU'] = (string)$item->SellerSKU;
            $this->itemList[$n]['OrderItemId'] = (string)$item->OrderItemId;
            $this->itemList[$n]['Title'] = (string)$item->Title;
            $this->itemList[$n]['QuantityOrdered'] = (string)$item->QuantityOrdered;
            if (isset($item->QuantityShipped)){
                $this->itemList[$n]['QuantityShipped'] = (string)$item->QuantityShipped;
            }
            if (isset($item->BuyerCustomizedInfo->CustomizedURL)){
                $this->itemList[$n]['BuyerCustomizedInfo'] = (string)$item->BuyerCustomizedInfo->CustomizedURL;
            }
            if (isset($item->PointsGranted)){
                $this->itemList[$n]['PointsGranted']['PointsNumber'] = (string)$item->PointsGranted->PointsNumber;
                $this->itemList[$n]['PointsGranted']['Amount'] = (string)$item->PointsGranted->PointsMonetaryValue->Amount;
                $this->itemList[$n]['PointsGranted']['CurrencyCode'] = (string)$item->PointsGranted->PointsMonetaryValue->CurrencyCode;
            }
            if (isset($item->PriceDesignation)){
                $this->itemList[$n]['PriceDesignation'] = (string)$item->PriceDesignation;
            }
            if (isset($item->GiftMessageText)){
                $this->itemList[$n]['GiftMessageText'] = (string)$item->GiftMessageText;
            }
            if (isset($item->GiftWrapLevel)){
                $this->itemList[$n]['GiftWrapLevel'] = (string)$item->GiftWrapLevel;
            }
            if (isset($item->ItemPrice)){
                $this->itemList[$n]['ItemPrice']['Amount'] = (string)$item->ItemPrice->Amount;
                $this->itemList[$n]['ItemPrice']['CurrencyCode'] = (string)$item->ItemPrice->CurrencyCode;
            }
            if (isset($item->ShippingPrice)){
                $this->itemList[$n]['ShippingPrice']['Amount'] = (string)$item->ShippingPrice->Amount;
                $this->itemList[$n]['ShippingPrice']['CurrencyCode'] = (string)$item->ShippingPrice->CurrencyCode;
            }
            if (isset($item->GiftWrapPrice)){
                $this->itemList[$n]['GiftWrapPrice']['Amount'] = (string)$item->GiftWrapPrice->Amount;
                $this->itemList[$n]['GiftWrapPrice']['CurrencyCode'] = (string)$item->GiftWrapPrice->CurrencyCode;
            }
            if (isset($item->ItemTax)){
                $this->itemList[$n]['ItemTax']['Amount'] = (string)$item->ItemTax->Amount;
                $this->itemList[$n]['ItemTax']['CurrencyCode'] = (string)$item->ItemTax->CurrencyCode;
            }
            if (isset($item->ShippingTax)){
                $this->itemList[$n]['ShippingTax']['Amount'] = (string)$item->ShippingTax->Amount;
                $this->itemList[$n]['ShippingTax']['CurrencyCode'] = (string)$item->ShippingTax->CurrencyCode;
            }
            if (isset($item->GiftWrapTax)){
                $this->itemList[$n]['GiftWrapTax']['Amount'] = (string)$item->GiftWrapTax->Amount;
                $this->itemList[$n]['GiftWrapTax']['CurrencyCode'] = (string)$item->GiftWrapTax->CurrencyCode;
            }
            if (isset($item->ShippingDiscount)){
                $this->itemList[$n]['ShippingDiscount']['Amount'] = (string)$item->ShippingDiscount->Amount;
                $this->itemList[$n]['ShippingDiscount']['CurrencyCode'] = (string)$item->ShippingDiscount->CurrencyCode;
            }
            if (isset($item->PromotionDiscount)){
                $this->itemList[$n]['PromotionDiscount']['Amount'] = (string)$item->PromotionDiscount->Amount;
                $this->itemList[$n]['PromotionDiscount']['CurrencyCode'] = (string)$item->PromotionDiscount->CurrencyCode;
            }
            if (isset($item->CODFee)){
                $this->itemList[$n]['CODFee']['Amount'] = (string)$item->CODFee->Amount;
                $this->itemList[$n]['CODFee']['CurrencyCode'] = (string)$item->CODFee->CurrencyCode;
            }
            if (isset($item->CODFeeDiscount)){
                $this->itemList[$n]['CODFeeDiscount']['Amount'] = (string)$item->CODFeeDiscount->Amount;
                $this->itemList[$n]['CODFeeDiscount']['CurrencyCode'] = (string)$item->CODFeeDiscount->CurrencyCode;
            }
            if (isset($item->PromotionIds)){
                $i = 0;
                foreach($item->PromotionIds->children() as $x){
                    $this->itemList[$n]['PromotionIds'][$i] = (string)$x;
                    $i++;
                }
            }
            if (isset($item->InvoiceData)){
                if (isset($item->InvoiceData->InvoiceRequirement)){
                    $this->itemList[$n]['InvoiceData']['InvoiceRequirement'] = (string)$item->InvoiceData->InvoiceRequirement;
                }
                if (isset($item->InvoiceData->BuyerSelectedInvoiceCategory)){
                    $this->itemList[$n]['InvoiceData']['BuyerSelectedInvoiceCategory'] = (string)$item->InvoiceData->BuyerSelectedInvoiceCategory;
                }
                if (isset($item->InvoiceData->InvoiceTitle)){
                    $this->itemList[$n]['InvoiceData']['InvoiceTitle'] = (string)$item->InvoiceData->InvoiceTitle;
                }
                if (isset($item->InvoiceData->InvoiceInformation)){
                    $this->itemList[$n]['InvoiceData']['InvoiceInformation'] = (string)$item->InvoiceData->InvoiceInformation;
                }
            }
            if (isset($item->ConditionId)){
                $this->itemList[$n]['ConditionId'] = (string)$item->ConditionId;
            }
            if (isset($item->ConditionSubtypeId)){
                $this->itemList[$n]['ConditionSubtypeId'] = (string)$item->ConditionSubtypeId;
            }
            if (isset($item->ConditionNote)){
                $this->itemList[$n]['ConditionNote'] = (string)$item->ConditionNote;
            }
            if (isset($item->ScheduledDeliveryStartDate)){
                $this->itemList[$n]['ScheduledDeliveryStartDate'] = (string)$item->ScheduledDeliveryStartDate;
            }
            if (isset($item->ScheduledDeliveryEndDate)){
                $this->itemList[$n]['ScheduledDeliveryEndDate'] = (string)$item->ScheduledDeliveryEndDate;
            }
            $this->index++;
        }
            
    }
38761
public function getTransactionsManager() {
		if ($this->_transactionsManager === null) {
			if ($this->hasLocator()) {
				$locator = $this->getLocator();

				if ($locator->has(self::PHSRV_TRANSACTIONS)) {
					$this->_transactionsManager = $locator->get(self::PHSRV_TRANSACTIONS);
				}
			}
			
			if ($this->_transactionsManager === null) {
				$this->_transactionsManager = new TransactionsManager($this->getTableModelDi());
			}
			
			$this->_transactionsManager->setDbService($this->getAdapterName());
		}
		
		return $this->_transactionsManager;
	}
484968
static public function camelcasedToDashed($str) {
        $str = lcfirst($str);
        return preg_replace_callback(
            '/([A-Z])/',
            function ($str) {
                return "-" . strtolower($str[1]);
            },
            $str
        );
    }
765024
public function searchTransactions()
    {
        try {
            $connection = $this->getConnection();
            $select = $connection->select()
                ->from( ['order' => 'sales_order'], ['status', 'created_at', 'increment_id', 'store_id', 'entity_id'] )
                ->join( ['ps' => 'pagseguro_orders'], 'order.entity_id = ps.order_id')
                ->where('ps.transaction_code != ?', '')
                ->order('order.created_at DESC');

            if (!is_null($this->_session->getData('store_id'))) {
                $select = $select->where('order.store_id = ?', $this->_session->getData('store_id'));
            }

            if ($this->_scopeConfig->getValue('payment/pagseguro/environment')) {
                $select = $select->where('ps.environment = ?', $this->_scopeConfig->getValue('payment/pagseguro/environment'));
            }

            if (!empty($this->_idMagento)) {
                $select = $select->where('order.increment_id = ?', $this->_idMagento);
            }

            if (!empty($this->_idPagseguro)) {
                $select = $select->where('ps.transaction_code = ?', $this->_idPagseguro);
            }

            if (!empty($this->_status)) {
                $select = $this->getStatusFromPaymentKey($this->_status) == 'partially_refunded'
                    ? $select->where('ps.partially_refunded = ?', 1)
                    : $select->where('order.status = ?', $this->getStatusFromPaymentKey($this->_status));
            }

            if (!empty($this->_dateBegin) && !empty($this->_dateEnd)) {
                $startDate = date('Y-m-d H:i:s', strtotime(str_replace("/", "-", $this->_dateBegin)));
                $endDate = date('Y-m-d'.' 23:59:59', strtotime(str_replace("/", "-", $this->_dateEnd)));
                $select = $select->where('order.created_at >= ?', $startDate)->where('order.created_at <= ?', $endDate);
            }

            $connection->prepare($select);
            return $connection->fetchAll($select);
        } catch (\Exception $exception) {
            throw $exception;
        }
    }
677529
public static function readSuccessXml($str_xml)
    {
        $parser = new PagSeguroXmlParser($str_xml);

        $data = $parser->getResult('authorizationRequest');
        $authorizationParserData = new PagSeguroParserData();
        $authorizationParserData->setCode($data['code']);
        $authorizationParserData->setRegistrationDate($data['date']);
        return $authorizationParserData;
    }
878266
public function searchAndReplace($str)
	{
		$this->matcher->load($str, $this->collection);

		return $this->matcher->searchAndReplace();
	}
662319
public static function parse($strQuery, $encoding = null)
    {
        self::_getInstance();

        // Reset FSM if previous parse operation didn't return it into a correct state
        self::$_instance->reset();

        include_once 'Zend/Search/Lucene/Search/QueryParserException.php';
        try {
            include_once 'Zend/Search/Lucene/Search/QueryParserContext.php';

            self::$_instance->_encoding     = ($encoding !== null) ? $encoding : self::$_instance->_defaultEncoding;
            self::$_instance->_lastToken    = null;
            self::$_instance->_context      = new Zend_Search_Lucene_Search_QueryParserContext(self::$_instance->_encoding);
            self::$_instance->_contextStack = array();
            self::$_instance->_tokens       = self::$_instance->_lexer->tokenize($strQuery, self::$_instance->_encoding);

            // Empty query
            if (count(self::$_instance->_tokens) == 0) {
                include_once 'Zend/Search/Lucene/Search/Query/Insignificant.php';
                return new Zend_Search_Lucene_Search_Query_Insignificant();
            }


            foreach (self::$_instance->_tokens as $token) {
                try {
                    self::$_instance->_currentToken = $token;
                    self::$_instance->process($token->type);

                    self::$_instance->_lastToken = $token;
                } catch (Exception $e) {
                    if (strpos($e->getMessage(), 'There is no any rule for') !== false) {
                        throw new Zend_Search_Lucene_Search_QueryParserException('Syntax error at char position ' . $token->position . '.', 0, $e);
                    }

                    include_once 'Zend/Search/Lucene/Exception.php';
                    throw new Zend_Search_Lucene_Exception($e->getMessage(), $e->getCode(), $e);
                }
            }

            if (count(self::$_instance->_contextStack) != 0) {
                throw new Zend_Search_Lucene_Search_QueryParserException('Syntax Error: mismatched parentheses, every opening must have closing.');
            }

            return self::$_instance->_context->getQuery();
        } catch (Zend_Search_Lucene_Search_QueryParserException $e) {
            if (self::$_instance->_suppressQueryParsingExceptions) {
                $queryTokens = Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize($strQuery, self::$_instance->_encoding);

                include_once 'Zend/Search/Lucene/Search/Query/MultiTerm.php';
                $query = new Zend_Search_Lucene_Search_Query_MultiTerm();
                $termsSign = (self::$_instance->_defaultOperator == self::B_AND) ? true /* required term */ :
                                                                                   null /* optional term */;

                include_once 'Zend/Search/Lucene/Index/Term.php';
                foreach ($queryTokens as $token) {
                    $query->addTerm(new Zend_Search_Lucene_Index_Term($token->getTermText()), $termsSign);
                }


                return $query;
            } else {
                include_once 'Zend/Search/Lucene/Exception.php';
                throw new Zend_Search_Lucene_Exception($e->getMessage(), $e->getCode(), $e);
            }
        }
    }
141027
public function fetchById($str_id)
    {
        return $this->obj_gateway
            ->withSchema($this->obj_schema)
            ->withTransaction($this->str_transaction_id)
            ->fetchById($str_id);
    }
811617
protected function parseXml($xml) {
        if (!$xml){
            return false;
        }

        //SKU or ASIN list
        $list = false;
        if (isset($xml->SKUPrepInstructionsList)) {
            $list = $xml->SKUPrepInstructionsList;
        }
        if (isset($xml->ASINPrepInstructionsList)) {
            $list = $xml->ASINPrepInstructionsList;
        }
        if ($list) {
            foreach ($list->children() as $x) {
                $temp = array();
                if (isset($x->SellerSKU)) {
                    $temp['SellerSKU'] = (string)$x->SellerSKU;
                }
                $temp['ASIN'] = (string)$x->ASIN;
                $temp['BarcodeInstruction'] = (string)$x->BarcodeInstruction;
                $temp['PrepGuidance'] = (string)$x->PrepGuidance;
                foreach ($x->PrepInstructionList->children() as $z) {
                    $temp['PrepInstructionList'][] = (string)$z;
                }
                if (isset($x->AmazonPrepFeesDetailsList)) {
                    foreach ($x->AmazonPrepFeesDetailsList->children() as $z) {
                        $fee = array();
                        $fee['PrepInstruction'] = (string)$z->PrepInstruction;
                        $fee['Amount']['Value'] = (string)$z->Amount->Value;
                        $fee['Amount']['CurrencyCode'] = (string)$z->Amount->CurrencyCode;
                        $temp['AmazonPrepFees'][] = $fee;
                    }
                }
                $this->prepList[] = $temp;
            }
        }

        //invalid item list
        $invList = false;
        if (isset($xml->InvalidSKUList)) {
            $invList = $xml->InvalidSKUList;
        }
        if (isset($xml->InvalidASINList)) {
            $invList = $xml->InvalidASINList;
        }
        if ($invList) {
            foreach ($invList->children() as $x) {
                $temp = array();
                $temp['ErrorReason'] = (string)$x->ErrorReason;
                if (isset($x->SellerSKU)) {
                    $temp['SellerSKU'] = (string)$x->SellerSKU;
                }
                if (isset($x->ASIN)) {
                    $temp['ASIN'] = (string)$x->ASIN;
                }
                $this->invalidList[] = $temp;
            }
        }
    }