@param $transactionId
@param $responseCode
@param $responseText
@param $item

@return \HpsProcessorException|null
518752
public static function getException($transactionId, $responseCode, $responseText, $item)
    {
        $responseCode = (string)$responseCode;
        $code = null;
        $message = null;

        if ($responseCode == '00') {
            return null;
        }

        if (isset($item->Processor) && isset($item->Processor->Response)) {
            $error = self::nvpToArray($item->Processor->Response);
            $code = $error['Code'];
            $message = $error['Message'];
        }

        return new HpsProcessorException($transactionId, $code, $message, $responseCode, $responseText);
    }
1356412
public function cpcEdit($transactionId, $cpcData)
    {
        $xml = new DOMDocument();
        $hpsTransaction = $xml->createElement('hps:Transaction');
        $hpsPosCreditCPCEdit = $xml->createElement('hps:CreditCPCEdit');
        $hpsPosCreditCPCEdit->appendChild($xml->createElement('hps:GatewayTxnId', $transactionId));
        $hpsPosCreditCPCEdit->appendChild($this->_hydrateCPCData($cpcData, $xml));
        $hpsTransaction->appendChild($hpsPosCreditCPCEdit);

        return $this->_submitTransaction($hpsTransaction, 'CreditCPCEdit');
    }
129637
public void addItem(Item item, Transaction tran) throws OutOfCacheSpace, StreamIsFull, ProtocolException, TransactionException, PersistenceException, SevereMessageStoreException {
    super.addItem(item, tran);
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "addItem");
    if (item instanceof SchemaStoreItem) {
      addToIndex((SchemaStoreItem)item);
      if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "JSchema added to store: " + ((SchemaStoreItem)item).getSchema().getID());
    }
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "addItem");
  }
428593
public function createPaymentByTransactionIdQuery($transactionId)
    {
        $query = $this->getFactory()->createPaymentPayoneQuery();
        $query->filterByTransactionId($transactionId);

        return $query;
    }
1255717
public function execute(TransactionData $transactionData, $argument = null)
    {
        $transactionData->setResponse(
            $this->processAndGetResponse(
                $transactionData,
                function (TransactionData $transaction, ScenarioState $state) {
                    $this->storage->setScenarioState($state->getScenarioName(), $state->getScenarioState());
                    $this->logger->debug(
                        'Scenario ' . $state->getScenarioName() . ' state is set to ' . $state->getScenarioState()
                    );

                    return $transaction->getResponse()
                        ->withStatus(200)
                        ->withHeader('Content-Type', 'application/json')
                        ->withBody(new StringStream(json_encode($state)));
                }
            )
        );
    }
707994
public static function fromDict($rsp, $txnType, $returnType = 'HpsTransaction')
    {
        $transaction = new $returnType();

        // Hydrate the header
        $transaction->_header = new HpsTransactionHeader();
        $transaction->_header->gatewayResponseCode = (string)$rsp->Header->GatewayRspCode;
        $transaction->_header->gatewayResponseMessage = (string)$rsp->Header->GatewayRspMsg;
        $transaction->_header->responseDt = (string)$rsp->Header->RspDT;
        $transaction->_header->clientTxnId = (isset($rsp->Header->ClientTxnId) ? (string)$rsp->Header->ClientTxnId : null);

        $transaction->transactionId = (string)$rsp->Header->GatewayTxnId;
        if (isset($rsp->Header->ClientTxnId)) {
            $transaction->clientTransactionId = (string)$rsp->Header->ClientTxnId;
        }

        // Hydrate the body
        if (!isset($rsp->Transaction) || !isset($rsp->Transaction->{$txnType})) {
            return $transaction;
        }
        // Hydrate the body
        $item = $rsp->Transaction->{$txnType};
        if ($item != null) {
            $transaction->responseCode = (isset($item->RspCode) ? (string)$item->RspCode : null);
            $transaction->responseText = (isset($item->RspText) ? (string)$item->RspText : null);
            $transaction->referenceNumber = (isset($item->RefNbr) ? (string)$item->RefNbr : null);
        }

        return $transaction;
    }
940147
public function shouldRetry(&$responseString, $exception, $transaction_id)
  {
    // Is transaction - no retry
    if ($transaction_id)
      return false;
    if (!$this->_retryRequests)
      return false;
    if (!is_null($exception)) {
      $this->logFailure();
      if ($this->_numUsed == count($this->_connectionStrings)) {
        return false;
      }
	  $errors = $exception->errors();
      if ($exception->code() == 9006 && $errors[0]['source'] == "CPS_API")
        return true;
      return false;
    }
//     $sp = strpos($responseString, '<cps:error>');
//     if ($sp === FALSE) {
//       $this->logSuccess();
//       return false;
//     }
//     $ep = strrpos($responseString, '</cps:error>');
//     if ($ep === FALSE) {// shouldn't really ever happen, unless our XML response was cut off?
//       $this->logFailure();
//       return ($this->_retryRequests && !$transaction_id);
//     }
//     try {
//       $errorXml = new SimpleXMLElement('<root xmlns:cps="www.clusterpoint.com">' . substr($responseString, $sp, $ep - $sp + strlen('</cps:error>')) . '</root>');
//     } catch (Exception $e) {
//       // Unable to parse errors - shouldn't really ever happen, unless there's something wrong with this function
//       return ($this->_retryRequests && !$transaction_id);
//     }
//     foreach ($errorXml->children('www.clusterpoint.com')->error as $e) {
//       $code = (int)$e->children('')->code;
//       $level = (string)$e->children('')->level;

//       if (($level == 'FAILED') || ($level == 'ERROR') || ($level == 'FATAL') || ($code == 2344)) {
//         // request returned an error, should retry
//         $this->logFailure();
//         return ($this->_retryRequests && !$transaction_id);
//       }
//     }
    $this->logSuccess();
    return false;
  }
632530
private function _submitTransaction($transaction, $txnType, $clientTxnId = null, $cardData = null)
    {
        try {
            $response = $this->doRequest($transaction, $clientTxnId);
        } catch (HpsException $e) {
            if ($e->innerException != null && $e->innerException->getMessage() == 'gateway_time-out') {
                // if (in_array($txnType, array('CreditSale', 'CreditAuth'))) {
                //     try {
                //         $this->reverse($cardData, $this->_amount, $this->_currency);
                //     } catch (Exception $e) {
                //         throw new HpsGatewayException('0', HpsExceptionCodes::GATEWAY_TIMEOUT_REVERSAL_ERROR);
                //     }
                // }
                throw new HpsException('An error occurred and the gateway has timed out', 'gateway_timeout', $e, 'gateway_timeout');
            }
            throw $e;
        }

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

        $rvalue = null;
        switch ($txnType) {
            case 'AltPaymentCreateSession':
                $rvalue = HpsAltPaymentCreateSession::fromDict($response, $txnType);
                break;
            case 'AltPaymentSessionInfo':
                $rvalue = HpsAltPaymentSessionInfo::fromDict($response, $txnType);
                break;
            case 'AltPaymentSale':
                $rvalue = HpsAltPaymentSale::fromDict($response, $txnType);
                break;
            case 'AltPaymentAuth':
                $rvalue = HpsAltPaymentAuth::fromDict($response, $txnType);
                break;
            case 'AltPaymentCapture':
                $rvalue = HpsAltPaymentCapture::fromDict($response, $txnType);
                break;
            case 'AltPaymentReturn':
                $rvalue = HpsAltPaymentReturn::fromDict($response, $txnType);
                break;
            case 'AltPaymentVoid':
                $rvalue = HpsAltPaymentVoid::fromDict($response, $txnType);
                break;
            case 'GetTransactionStatus':
                $rvalue = HpsTransactionStatus::fromDict($response, $txnType);
                break;
            default:
                break;
        }

        return $rvalue;
    }
897739
protected function processAndGetResponse(TransactionData $transactionData, callable $process)
    {
        try {
            return $this->createObjectFromRequestAndProcess($transactionData, $process);
        } catch (InvalidRequestException $e) {
            $this->logger->warning('Invalid request received');

            return $this->constructErrorResponse($e->getErrors(), $transactionData->getResponse());
        } catch (\Exception $e) {
            $this->logger->error('An unexpected exception occurred: ' . $e->getMessage());
            $this->logger->debug($e->__toString());

            return $this->constructErrorResponse([$e->getMessage()], $transactionData->getResponse());
        }
    }
990336
public function cancelTransaction($transactionCode)
    {
        return $this->sendTransaction([
            'email'           => $this->email,
            'token'           => $this->token,
            'transactionCode' => $transactionCode,
        ], $this->url['cancelTransaction']);
    }
565449
public static function fromDict($rsp, $txnType, $returnType = 'HpsGiftCardAlias')
    {
        $item = $rsp->Transaction->$txnType;

        $alias = new HpsGiftCardAlias();
        $alias->transactionId = (string)$rsp->Header->GatewayTxnId;
        $alias->giftCard = new HpsGiftCard($item->CardData);
        $alias->responseCode = (isset($item->RspCode) ? (string)$item->RspCode : null);
        $alias->responseText = (isset($item->RspText) ? (string)$item->RspText : null);

        return $alias;
    }
1026357
private function _processChargeIssuerResponse($response, $expectedType)
    {
        $transactionId = (isset($response->Header->GatewayTxnId) ? $response->Header->GatewayTxnId : null);
        $item = $response->Transaction->$expectedType;

        if ($item != null) {
            $responseCode = (isset($item->RspCode) ? $item->RspCode : null);
            $responseText = (isset($item->RspText) ? $item->RspText : null);

            if ($responseCode != null) {
                // check if we need to do a reversal
                if ($responseCode == '91') {
                    try {
                        $this->reverse($transactionId, $this->_amount, $this->_currency);
                    } catch (HpsGatewayException $e) {
                        // if the transaction wasn't found; throw the original timeout exception
                        if ($e->details->gatewayResponseCode == 3) {
                            HpsIssuerResponseValidation::checkResponse($transactionId, $responseCode, $responseText);
                        }
                        throw new HpsCreditException(
                            $transactionId,
                            HpsExceptionCodes::ISSUER_TIMEOUT_REVERSAL_ERROR,
                            'Error occurred while reversing a charge due to HPS issuer timeout',
                            $e
                        );
                    } catch (HpsException $e) {
                        throw new HpsCreditException(
                            $transactionId,
                            HpsExceptionCodes::ISSUER_TIMEOUT_REVERSAL_ERROR,
                            'Error occurred while reversing a charge due to HPS issuer timeout',
                            $e
                        );
                    }
                }
                HpsIssuerResponseValidation::checkResponse($transactionId, $responseCode, $responseText);
            }
        }
    }
1204668
public WePayOrder queryByTransactionId(String transactionId){
        checkNotNullAndEmpty(transactionId, "transactionId");
        Map<String, String> queryParams = new TreeMap<>();
        put(queryParams, WepayField.TRANSACTION_ID, transactionId);
        return doQueryOrder(queryParams);
    }
628162
protected static function deletePaymentTransactionByIdAsyncWithHttpInfo($payment_transaction_id) 
    {
        $returnType = '';  
        $request = self::deletePaymentTransactionByIdRequest($payment_transaction_id); 

        return self::getHttpClient()
            ->sendAsync($request, self::createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    return [null, $response->getStatusCode(), $response->getHeaders()];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }
1087239
public function _submitTransaction($transaction, $txnType, $clientTxnId = null)
    {
        $response = $this->doRequest($transaction, $clientTxnId);

        HpsGatewayResponseValidation::checkResponse($response, $txnType);
        HpsIssuerResponseValidation::checkResponse(
            $response->Header->GatewayTxnId,
            $response->Transaction->$txnType->RspCode,
            $response->Transaction->$txnType->RspText,
            'gift'
        );

        $rvalue = '';
        switch ($txnType) {
            case 'GiftCardActivate':
                $rvalue = HpsGiftCardActivate::fromDict($response, $txnType, 'HpsGiftCardActivate');
                break;
            case 'GiftCardAddValue':
                $rvalue = HpsGiftCardAddValue::fromDict($response, $txnType, 'HpsGiftCardAddValue');
                break;
            case 'GiftCardAlias':
                $rvalue = HpsGiftCardAlias::fromDict($response, $txnType, 'HpsGiftCardAlias');
                break;
            case 'GiftCardBalance':
                $rvalue = HpsGiftCardBalance::fromDict($response, $txnType, 'HpsGiftCardBalance');
                break;
            case 'GiftCardDeactivate':
                $rvalue = HpsGiftCardDeactivate::fromDict($response, $txnType, 'HpsGiftCardDeactivate');
                break;
            case 'GiftCardReplace':
                $rvalue = HpsGiftCardReplace::fromDict($response, $txnType, 'HpsGiftCardReplace');
                break;
            case 'GiftCardReward':
                $rvalue = HpsGiftCardReward::fromDict($response, $txnType, 'HpsGiftCardReward');
                break;
            case 'GiftCardSale':
                $rvalue = HpsGiftCardSale::fromDict($response, $txnType, 'HpsGiftCardSale');
                break;
            case 'GiftCardVoid':
                $rvalue = HpsGiftCardVoid::fromDict($response, $txnType, 'HpsGiftCardVoid');
                break;
            case 'GiftCardReversal':
                $rvalue = HpsGiftCardReversal::fromDict($response, $txnType, 'HpsGiftCardReversal');
                break;
            default:
                break;
        }

        return $rvalue;
    }
666892
public static function checkResponse($transactionId, $responseCode, $responseText, $type = 'credit')
    {
        $e = HpsIssuerResponseValidation::getException(
            (string)$transactionId,
            (string)$responseCode,
            (string)$responseText,
            $type
        );

        if ($e != null) {
            throw $e;
        }
    }
1114173
public static function fromDict($rsp, $txnType, $returnType = 'HpsRefund')
    {
        $refund = parent::fromDict($rsp, $txnType, $returnType);
        $refund->responseCode = '00';
        $refund->responseText = '';
        return $refund;
    }