Handles a query response

@param Transaction $transaction
@param object      $data
15569
protected function handleQueryResponse(Transaction $transaction, $data)
    {
        $result = $transaction->getResult();
        $parentResult = $transaction->getParent()->getResult();
        $eventResult = null;

        foreach ($data->Results as $event) {
            if ($event->TransAct_ReferenceID === $parentResult->getExternalId()) {
                $eventResult = $event;

                // We don't break in case the transaction has multiple events in the same query-- we want the latest
            }
        }

        $resultType = $parentResult->getStatus()->getValue();

        if (null !== $eventResult) {
            switch ($eventResult->ResultingStatus) {
                case 'Scheduled':
                    $resultType = Result\ResultStatus::PENDING;
                    break;

                case 'Cancelled':
                    $resultType = Result\ResultStatus::CANCELLED;
                    break;

                case 'In-Process':
                    $resultType = Result\ResultStatus::PROCESSED;
                    break;

                case 'Cleared':
                    $resultType = Result\ResultStatus::APPROVED;
                    break;

                case 'Failed Verification':
                case 'Returned-NSF':
                case 'Returned-Other':
                    $resultType = Result\ResultStatus::DECLINED;
                    break;

                case 'Charged Back':
                    $resultType = Result\ResultStatus::CHARGED_BACK;
                    break;

                case 'Merchant Hold':
                case 'Processor Hold':
                    $resultType = Result\ResultStatus::HOLD;
                    break;
            }
        }

        $result->setStatus(new Result\ResultStatus($resultType));
    }
948095
public function send(array $transaction)
    {
        $this->assertValidTransaction($transaction);

        if ($transaction['transaction_type'] == 'email') {
            $transaction['content']['plain'] = base64_encode($transaction['content']['plain']);
            $transaction['content']['html'] = base64_encode($transaction['content']['html']);
        }

        $request = new Request('transactionals');
        $request->setParams($transaction);

        $response = $this->client->post($request);

        $this->assertSuccessResponse($response);

        return $response->getData();
    }
625579
protected function throwUnlessSuccessResponse(Response $response, FinancialTransactionInterface $transaction)
    {
        if ($response->isSuccess()) {
            return;
        }

        $transaction->setResponseCode($response->body->get('ACK'));
        $transaction->setReasonCode($response->body->get('L_ERRORCODE0'));

        $ex = new FinancialException('PayPal-Response was not successful: '.$response);
        $ex->setFinancialTransaction($transaction);

        throw $ex;
    }
606867
public function delete(TransactionInterface $transaction = null)
    {
        if (empty($transaction)) {
            /*
             * When no transaction is given we will create our own and run it immediately.
             */
            $transaction = $transaction ?? new Transaction();
            $transaction->delete($this);
            $transaction->run();
        } else {
            $transaction->addCommand($this->queueDelete());
        }
    }
534516
protected function doTransact(Transaction $transaction, array $options = array())
    {
        $this->validateTransaction($transaction);
        $params = $this->buildParams($transaction, $options);

        $result = $transaction->getResult();
        $result->setTransactor($this);

        $postUrl = $options['post_url'];
        $client = $this->getClient();

        $request = $client->post($postUrl)
            ->addPostFields($params);

        try {
            $response = $request->send();

            $data = Transaction\TransactionType::QUERY !== $transaction->getType()->getValue()
                ? json_decode($response->getBody(true))
                : $this->normalizeQueryResponse($response->getBody(true));
        } catch (BadResponseException $e) {
            $data = new \stdClass();
            $data->CommandStatus = 'Error';
            $data->Description = 'Client Error';
            $data->ErrorInformation = 'An error occurred while contacting the PaymentsXpress system';
            $data->Exception = $e->getMessage();
        }

        if ('Approved' !== $data->CommandStatus) {
            $result->setStatus(new Result\ResultStatus('Declined' !== $data->CommandStatus ? Result\ResultStatus::ERROR : Result\ResultStatus::DECLINED));
            $result->setMessage(!empty($data->ErrorInformation) ? $data->Description . ': ' . $data->ErrorInformation : $data->Description);

            if (!empty($data->TransAct_ReferenceID)) {
                $result->setExternalId($data->TransAct_ReferenceID);
            }
        } else {
            if (Transaction\TransactionType::QUERY === $transaction->getType()->getValue()) {
                $this->handleQueryResponse($transaction, $data);
            } else {
                $result->setStatus(new Result\ResultStatus(Result\ResultStatus::PENDING));
            }

            $result->setExternalId($data->TransAct_ReferenceID);
        }

        $result->setData('request', $params);
        $result->setData('response', $data);

        return $result;
    }
983684
private function _submitTransaction($transaction, $txnType, $clientTransactionId = null)
    {
        $options = array();
        if ($clientTransactionId !== null) {
            $options['clientTransactionId'] = $clientTransactionId;
        }
        $rsp = $this->doRequest($transaction, $options);
        HpsGatewayResponseValidation::checkResponse($rsp, $txnType);
        $response = HpsCheckResponse::fromDict($rsp, $txnType);

        if ($response->responseCode != 0) {
            throw new HpsCheckException(
                $rsp->Header->GatewayTxnId,
                $response->details,
                $response->responseCode,
                $response->responseText
            );
        }

        return $response;
    }
264259
public function handleVersionOne(Transaction $transaction): Transaction
    {
        if (isset($transaction->secondSignature)) {
            $transaction->signSignature = $transaction->secondSignature;
        }

        if (Types::VOTE === $transaction->type) {
            $transaction->recipientId = Address::fromPublicKey($transaction->senderPublicKey, $transaction->network);
        }

        if (Types::MULTI_SIGNATURE_REGISTRATION === $transaction->type) {
            $transaction->asset['multisignature']['keysgroup'] = array_map(function ($key) {
                return '+'.$key;
            }, $transaction->asset['multisignature']['keysgroup']);
        }

        if (isset($transaction->vendorFieldHex)) {
            $transaction->vendorField = hex2bin($transaction->vendorFieldHex);
        }

        if (! isset($transaction->id)) {
            $transaction->id = $transaction->getId();
        }

        if (Types::SECOND_SIGNATURE_REGISTRATION === $transaction->type) {
            $transaction->recipientId = Address::fromPublicKey($transaction->senderPublicKey, $transaction->network);
        }

        if (Types::MULTI_SIGNATURE_REGISTRATION === $transaction->type) {
            $transaction->recipientId = Address::fromPublicKey($transaction->senderPublicKey, $transaction->network);
        }

        return $transaction;
    }
1330539
function verify($transaction)
	{
		$this->transaction = $transaction;
		$this->transactionId = $transaction->id;
		$this->amount = intval($transaction->price);
		$this->refId = $transaction->ref_id;
	}
393830
public function destroy(Transaction $transaction)
    {
        $this->transaction->destroy($transaction);

        return redirect()->route('admin.order.order.show', $transaction->order_id)
            ->withSuccess(trans('core::core.messages.resource deleted', ['name' => trans('order::transactions.title.transactions')]));
    }
1288792
public function isRequestValid(TransactionInterface $transaction)
    {
        $checkUrl = $transaction->get('check');

        $checkPrivate = $this->generateUrlCheck($transaction->getOrder());

        return $checkUrl === $checkPrivate;
    }
283163
public function map($response, Transaction $transaction = null)
    {
        $this->transaction = $transaction;

        // If the response is encoded, we need to first decode it.
        $decodedResponse = base64_decode($response);
        $this->xmlResponse = (base64_encode($decodedResponse) === $response) ? $decodedResponse : $response;
        //we need to use internal_errors, because we don't want to throw errors on invalid xml responses
        $oldErrorHandling = libxml_use_internal_errors(true);
        $this->simpleXml = simplexml_load_string($this->xmlResponse);
        //reset to old value after string is loaded
        libxml_use_internal_errors($oldErrorHandling);

        if (!$this->simpleXml instanceof \SimpleXMLElement) {
            throw new MalformedResponseException('Response is not a valid xml string.');
        }

        if (isset($this->simpleXml->{'transaction-state'})) {
            $state = (string)$this->simpleXml->{'transaction-state'};
        } else {
            throw new MalformedResponseException('Missing transaction-state in response.');
        }

        switch ($state) {
            case 'success':
                return $this->mapSuccessResponse();
            case 'in-progress':
                return new PendingResponse($this->simpleXml);
            default:
                return new FailureResponse($this->simpleXml);
        }
    }
297212
public function execute(TransactionData $transactionData, $argument = null)
    {
        foreach ($this->expectationBackup->listExpectations() as $expectation) {
            $this->expectationStorage->addExpectation($expectation);
        }
        $this->logger->debug('Pre-defined expectations are restored, scenarios and requests history are cleared.');

        $transactionData->setResponse(
            $transactionData->getResponse()->withStatus(200)
        );
    }
499026
public function execute(TransactionData $transactionData, $argument = null)
    {
        $list = json_encode($this->storage->listExpectations());

        $transactionData->setResponse(
            $transactionData->getResponse()
            ->withBody(new StringStream($list))
            ->withHeader('Content-type', 'application/json')
        );
    }
1267721
public function delete( $object, $transaction = self::TRANSACTION_LAST_USED )
    {
        // this'll throw a exception if anything isn't right
        $task = Task::init( $object, Task::DELETE );
        $transaction = $this->getTransaction($transaction,true);
        $this->queue[$transaction][] = $task;
        return $this;
    }
500958
public function handle(TransactionHandler $transaction)
    {
        if ($this->sheetImport instanceof WithCustomValueBinder) {
            Cell::setValueBinder($this->sheetImport);
        }

        $headingRow = HeadingRowExtractor::headingRow($this->sheetImport);

        $filter = new ChunkReadFilter(
            $headingRow,
            $this->startRow,
            $this->chunkSize,
            $this->sheetName
        );

        $this->reader->setReadFilter($filter);
        $this->reader->setReadDataOnly(true);
        $this->reader->setReadEmptyCells(false);

        $spreadsheet = $this->reader->load(
            $this->temporaryFile->sync()->getLocalPath()
        );

        $sheet = Sheet::byName(
            $spreadsheet,
            $this->sheetName
        );

        if ($sheet->getHighestRow() < $this->startRow) {
            $sheet->disconnect();

            return;
        }

        $transaction(function () use ($sheet) {
            $sheet->import(
                $this->sheetImport,
                $this->startRow
            );

            $sheet->disconnect();
        });
    }
799505
@Override
    public void setTransactionState(boolean transactionState) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("Received transaction state change: '%s':%n%s",
                    endpointConfiguration.getServerConfiguration().getDatabaseName(),
                    String.valueOf(transactionState)));
        }

        this.transactionState = transactionState;
        if(!endpointConfiguration.isAutoTransactionHandling() && transactionState){
            handleMessageAndCheckResponse(JdbcMessage.startTransaction());
        }
    }
816504
private function _submitTransaction($transaction, $txnType)
    {

        try {
            $response = $this->doRequest($transaction);
        } catch (HpsException $e) {
            if ($e->innerException != null && $e->innerException->getMessage() == 'gateway_time-out') {
                throw new HpsException('An error occurred and the gateway has timed out', 'gateway_timeout', $e, 'gateway_timeout');
            }
            throw $e;
        }

        $this->_processGatewayResponse($response, $txnType);

        $rvalue = null;
        switch ($txnType) {
            case 'GetAttachments':
                $rvalue = HpsAttachment::fromDict($response, $txnType);
                break;
            default:
                break;
        }

        return $rvalue;
    }