public static function fromDict($rsp, $txnType, $filterBy = null, $returnType = 'HpsReportTransactionSummary') { $transactions = array(); if ((string) $rsp->Transaction->ReportActivity->Header->TxnCnt == "0") { return $transactions; } if ($filterBy != null && is_string($filterBy)) { $filterBy = HpsTransaction::serviceNameToTransactionType($filterBy); } $summary = null; $serviceName = isset($filterBy) ? HpsTransaction::transactionTypeToServiceName($filterBy) : null; foreach ($rsp->Transaction->ReportActivity->Details as $charge) { if (isset($serviceName) && $serviceName != (string) $charge->ServiceName) { continue; } $summary = new HpsReportTransactionSummary(); // Hydrate the header $summary->_header = new HpsTransactionHeader(); $summary->_header->gatewayResponseCode = (string) $charge->GatewayRspCode; $summary->_header->gatewayResponseMessage = (string) $charge->GatewayRspMsg; $summary->transactionId = (string) $charge->GatewayTxnId; $summary->originalTransactionId = isset($charge->OriginalGatewayTxnId) ? (string) $charge->OriginalGatewayTxnId : null; $summary->maskedCardNumber = isset($charge->MaskedCardNbr) ? (string) $charge->MaskedCardNbr : null; $summary->responseCode = isset($charge->IssuerRspCode) ? (string) $charge->IssuerRspCode : null; $summary->responseText = isset($charge->IssuerRspText) ? (string) $charge->IssuerRspText : null; $summary->amount = isset($charge->Amt) ? (string) $charge->Amt : null; $summary->settlementAmount = isset($charge->SettlementAmt) ? (string) $charge->SettlementAmt : null; $summary->transactionType = isset($charge->ServiceName) ? HpsTransaction::serviceNameToTransactionType((string) $charge->ServiceName) : null; $summary->transactionUTCDate = isset($charge->TxnUtcDT) ? (string) $charge->TxnUtcDT : null; $gwResponseCode = isset($charge->GatewayRspCode) ? (string) $charge->GatewayRspCode : null; $issuerResponseCode = isset($charge->IssuerRspCode) ? (string) $charge->IssuerRspCode : null; if ($gwResponseCode != "0" || $issuerResponseCode != "00") { $exceptions = new HpsChargeExceptions(); if ($gwResponseCode != "0") { $message = (string) $charge->GatewayRspMsg; $exceptions->hpsException = HpsGatewayResponseValidation::getException((string) $charge->GatewayTxnId, $gwResponseCode, $message); } if ($issuerResponseCode != "00") { $message = (string) $charge->IssuerRspText; $exceptions->cardException = HpsIssuerResponseValidation::getException((string) $charge->GatewayTxnId, $issuerResponseCode, $message); } $summary->exceptions = $exceptions; } $transactions[] = $summary; } return $transactions; }
public static function fromDict($rsp, $txnType, $filterBy = null, $returnType = 'HpsReportTransactionSummary') { $transactions = array(); if ($rsp->Transaction->ReportActivity->Header->TxnCnt == "0") { return $transactions; } $summary = null; $serviceName = isset($filterBy) ? HpsTransaction::transactionTypeToServiceName($filterBy) : null; foreach ($rsp->Transaction->ReportActivity->Details as $charge) { if ($filterBy == null || $charge->ServiceName != $serviceName) { $summary = parent::fromDict($rsp, $txnType, $returnType); $summary->originalTransactionId = isset($charge->OriginalGatewayTxnId) ? $charge->OriginalGatewayTxnId : null; $summary->maskedCardNumber = isset($charge->MaskedCardNbr) ? $charge->MaskedCardNbr : null; $summary->responseCode = isset($charge->IssuerRspCode) ? $charge->IssuerRspCode : null; $summary->responseText = isset($charge->IssuerRspText) ? $charge->IssuerRspText : null; $summary->amount = isset($charge->Amt) ? $charge->Amt : null; $summary->settlementAmount = isset($charge->SettlementAmt) ? $charge->SettlementAmt : null; $summary->transactionType = isset($charge->ServiceName) ? HpsTransaction::serviceNameToTransactionType($charge->ServiceName) : null; $summary->transactionUTCDate = isset($charge->TxnUtcDT) ? $charge->TxnUtcDT : null; if ($filterBy != null) { $summary->transactionType = $filterBy; } $gwResponseCode = isset($charge->GatewayRspCode) ? $charge->GatewayRspCode : null; $issuerResponseCode = isset($charge->IssuerRspCode) ? $charge->IssuerRspCode : null; if ($gwResponseCode != "0" || $issuerResponseCode != "00") { $exceptions = new HpsChargeExceptions(); if ($gwResponseCode != "0") { $message = $charge->GatewayRspMsg; $exceptions->gatewayException = HpsGatewayResponseValidation::getException($charge->GatewayTxnId, $gwResponseCode, $message); } if ($issuerResponseCode != "00") { $message = $charge->IssuerRspText; $exceptions->issuerException = HpsIssuerResponseValidation::getException($charge->GatewayTxnId, $issuerResponseCode, $message); } $summary->exceptions = $exceptions; } } $transactions[] = $summary; } return $transactions; }
public function listTransactions($startDate, $endDate, $filterBy = null) { date_default_timezone_set("UTC"); $dateFormat = 'Y-m-d\\TH:i:s.00\\Z'; $current = new DateTime(); $currentTime = $current->format($dateFormat); if ($startDate > $currentTime) { throw $this->exceptionMapper->map_sdk_exception(HpsSdkCodes::$invalidStartDate); } else { if ($endDate > $currentTime) { throw $this->exceptionMapper->map_sdk_exception(HpsSdkCodes::$invalidEndDate); } } $xml = new DOMDocument(); $hpsTransaction = $xml->createElement('hps:Transaction'); $hpsReportActivity = $xml->createElement('hps:ReportActivity'); $hpsReportActivity->appendChild($xml->createElement('hps:RptStartUtcDT', $startDate)); $hpsReportActivity->appendChild($xml->createElement('hps:RptEndUtcDT', $endDate)); $hpsTransaction->appendChild($hpsReportActivity); $response = $this->doTransaction($hpsTransaction); // Gateway Exception if ($response->Header->GatewayRspCode != 0) { $transactionId = $response->Header->GatewayTxnId; $responseCode = $response->Header->GatewayRspCode; $responseMessage = $response->Header->GatewayRspMessage; throw $this->exceptionMapper->map_gateway_exception($transactionId, $responseCode, $responseMessage); } $result = array(); if ($response->Transaction->ReportActivity->Header->TxnCnt == "0") { return $result; } foreach ($response->Transaction->ReportActivity->Details as $charge) { if ($filterBy != null && $charge->ServiceName != HpsTransaction::transactionTypeToServiceName($filterBy)) { continue; } else { $summary = new HpsReportTransactionSummary(); $summary->transactionId = isset($charge->GatewayTxnId) ? $charge->GatewayTxnId : null; $summary->originalTransactionId = isset($charge->OriginalGatewayTxnId) ? $charge->OriginalGatewayTxnId : null; $summary->maskedCardNumber = isset($charge->MaskedCardNbr) ? $charge->MaskedCardNbr : null; $summary->responseCode = isset($charge->IssuerRspCode) ? $charge->IssuerRspCode : null; $summary->responseText = isset($charge->IssuerRspText) ? $charge->IssuerRspText : null; if ($filterBy != null) { $summary->transactionType = isset($charge->ServiceName) ? HpsTransaction::transactionTypeToServiceName($charge->ServiceName) : null; } $gwResponseCode = isset($charge->GatewayRspCode) ? $charge->GatewayRspCode : null; $issuerResponseCode = isset($charge->IssuerRspCode) ? $charge->IssuerRspCode : null; if ($gwResponseCode != "0" || $issuerResponseCode != "00") { $exceptions = new HpsChargeExceptions(); if ($gwResponseCode != "0") { $message = $charge->GatewayRspMsg; $exceptions->hpsException = $this->exceptionMapper->map_gateway_exception($charge->GatewayTxnId, $gwResponseCode, $message); } if ($issuerResponseCode != "00") { $message = $charge->IssuerRspText; $exceptions->cardException = $this->exceptionMapper->map_issuer_exception($charge->GatewayTxnId, $issuerResponseCode, $message); } $summary->exceptions = $exceptions; } } $result = $summary; } return $result; }