예제 #1
0
 public function _submitTransaction($transaction, $txnType, $clientTransactionId = null)
 {
     $rsp = $this->doRequest($transaction, $clientTransactionId);
     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;
 }
 public static function checkResponse($response, $expectedType)
 {
     $rspCode = $response->Header->GatewayRspCode;
     $rspText = $response->Header->GatewayRspMsg;
     $e = HpsGatewayResponseValidation::getException($rspCode, $rspText, $response);
     if ($e != null) {
         throw $e;
     }
     if (!isset($response->Transaction) || !isset($response->Transaction->{$expectedType})) {
         throw new HpsGatewayException(HpsExceptionCodes::UNEXPECTED_GATEWAY_ERROR, 'Unexpected response from HPS gateway');
     }
 }
 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;
 }
예제 #4
0
 public function closeBatch()
 {
     $xml = new DOMDocument();
     $hpsTransaction = $xml->createElement('hps:Transaction');
     $hpsBatchClose = $xml->createElement('hps:BatchClose');
     $hpsTransaction->appendChild($hpsBatchClose);
     $response = $this->doTransaction($hpsTransaction);
     HpsGatewayResponseValidation::checkResponse($response, 'BatchClose');
     //Process the response
     $batchClose = $response->Transaction->BatchClose;
     $result = new HpsBatch();
     $result->id = isset($batchClose->BatchId) ? $batchClose->BatchId : null;
     $result->sequenceNumber = isset($batchClose->BatchSeqNbr) ? $batchClose->BatchSeqNbr : null;
     $result->totalAmount = isset($batchClose->TotalAmt) ? $batchClose->TotalAmt : null;
     $result->transactionCount = isset($batchClose->TxnCnt) ? $batchClose->TxnCnt : null;
     return $result;
 }
 public function _submitTransaction($transaction, $txnType, $clientTxnId = null)
 {
     $response = $this->doTransaction($transaction, $clientTxnId);
     HpsGatewayResponseValidation::checkResponse($response, $txnType);
     HpsIssuerResponseValidation::checkResponse($response->Header->GatewayTxnId, $response->Transaction->{$txnType}->RspCode, $response->Transaction->{$txnType}->RspText);
     $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;
 }
 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;
 }
 private function _submitTransaction($transaction, $txnType, $clientTxnId = null)
 {
     $response = $this->doTransaction($transaction, $clientTxnId);
     HpsGatewayResponseValidation::checkResponse($response, $txnType);
     HpsIssuerResponseValidation::checkResponse($response->Header->GatewayTxnId, $response->Transaction->{$txnType}->RspCode, $response->Transaction->{$txnType}->RspText);
     $rvalue = '';
     if ($txnType == 'GiftCardActivate') {
         $rvalue = HpsGiftCardActivate::fromDict($response, $txnType, 'HpsGiftCardActivate');
     } else {
         if ($txnType == 'GiftCardAddValue') {
             $rvalue = HpsGiftCardAddValue::fromDict($response, $txnType, 'HpsGiftCardAddValue');
         } else {
             if ($txnType == 'GiftCardAlias') {
                 $rvalue = HpsGiftCardAlias::fromDict($response, $txnType, 'HpsGiftCardAlias');
             } else {
                 if ($txnType == 'GiftCardBalance') {
                     $rvalue = HpsGiftCardBalance::fromDict($response, $txnType, 'HpsGiftCardBalance');
                 } else {
                     if ($txnType == 'GiftCardDeactivate') {
                         $rvalue = HpsGiftCardDeactivate::fromDict($response, $txnType, 'HpsGiftCardDeactivate');
                     } else {
                         if ($txnType == 'GiftCardReplace') {
                             $rvalue = HpsGiftCardReplace::fromDict($response, $txnType, 'HpsGiftCardReplace');
                         } else {
                             if ($txnType == 'GiftCardReward') {
                                 $rvalue = HpsGiftCardReward::fromDict($response, $txnType, 'HpsGiftCardReward');
                             } else {
                                 if ($txnType == 'GiftCardSale') {
                                     $rvalue = HpsGiftCardSale::fromDict($response, $txnType, 'HpsGiftCardSale');
                                 } else {
                                     if ($txnType == 'GiftCardVoid') {
                                         $rvalue = HpsGiftCardVoid::fromDict($response, $txnType, 'HpsGiftCardVoid');
                                     } else {
                                         if ($txnType == 'GiftCardReversal') {
                                             $rvalue = HpsGiftCardReversal::fromDict($response, $txnType, 'HpsGiftCardReversal');
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $rvalue;
 }
예제 #8
0
 private function _processChargeGatewayResponse($response, $expectedType)
 {
     $gatewayRspCode = isset($response->Header->GatewayRspCode) ? $response->Header->GatewayRspCode : null;
     $transactionId = isset($response->Header->GatewayTxnId) ? $response->Header->GatewayTxnId : null;
     if ($gatewayRspCode == '0') {
         return;
     }
     if ($gatewayRspCode == '30') {
         try {
             $this->reverse($transactionId, $this->_amount, $this->_currency);
         } catch (Exception $e) {
             throw new HpsGatewayException(HpsExceptionCodes::GATEWAY_TIMEOUT_REVERSAL_ERROR, 'Error occurred while reversing a charge due to HPS gateway timeout', $e);
         }
     }
     HpsGatewayResponseValidation::checkResponse($response, $expectedType);
 }
예제 #9
0
 /**
  * @param SimpleXMLElement $response raw XML response
  * @param string $expectedType
  * @throws HpsAuthenticationException
  * @throws HpsGatewayException
  * @throws null
  */
 private function _processGatewayResponse($response, $expectedType)
 {
     $gatewayRspCode = isset($response->Header->GatewayRspCode) ? $response->Header->GatewayRspCode : null;
     $transactionId = isset($response->Header->GatewayTxnId) ? (double) $response->Header->GatewayTxnId : null;
     if ($gatewayRspCode == '0') {
         return;
     }
     if ($gatewayRspCode == '3') {
         throw new HpsGatewayException(HpsExceptionCodes::GATEWAY_ERROR, 'Image could not be retrieved for ' . $transactionId);
     }
     HpsGatewayResponseValidation::checkResponse($response, $expectedType);
 }