Exemple #1
0
 protected function processTransaction(SOAP $sSOAPClient, $szMessageXMLPath, $szGatewayOutputXMLPath, $szTransactionMessageXMLPath, SimpleXMLElement &$sxXmlDocument = null, GatewayOutput &$goGatewayOutput = null, GatewayEntryPointList &$lgepGatewayEntryPoints = null)
 {
     $boTransactionSubmitted = false;
     $nOverallRetryCount = 0;
     $nOverallGatewayEntryPointCount = 0;
     $nGatewayEntryPointCount = 0;
     $nErrorMessageCount = 0;
     $rgepCurrentGatewayEntryPoint;
     $nStatusCode;
     $szMessage = null;
     $lszErrorMessages;
     $szString;
     $sbXMLString;
     $szXMLFormatString;
     $nCount = 0;
     $szEntryPointURL;
     $nMetric;
     $nTempValue = 0;
     $gepGatewayEntryPoint = null;
     $boAuthorisationAttempted = null;
     $boTempValue;
     $szPassOutData = null;
     //$szPreviousCrossReference = null;
     $nPreviousStatusCode = null;
     $szPreviousMessage = null;
     $ptdPreviousTransactionResult = null;
     $ResponseDocument = null;
     $ResponseMethod = null;
     $lgepGatewayEntryPoints = null;
     $goGatewayOutput = null;
     if ($sSOAPClient == null) {
         return false;
     }
     // populate the merchant details
     if ($this->m_mdMerchantAuthentication != null) {
         if (!SharedFunctions::isStringNullOrEmpty($this->m_mdMerchantAuthentication->getMerchantID())) {
             $sSOAPClient->addParamAttribute($szMessageXMLPath . '.MerchantAuthentication', 'MerchantID', $this->m_mdMerchantAuthentication->getMerchantID());
         }
         if (!SharedFunctions::isStringNullOrEmpty($this->m_mdMerchantAuthentication->getPassword())) {
             $sSOAPClient->addParamAttribute($szMessageXMLPath . '.MerchantAuthentication', 'Password', $this->m_mdMerchantAuthentication->getPassword());
         }
     }
     // populate the passout data
     if (!SharedFunctions::isStringNullOrEmpty($this->m_szPassOutData)) {
         $sSOAPClient->addParam($szMessageXMLPath . '.PassOutData', $this->m_szPassOutData, null);
     }
     // first need to sort the gateway entry points into the correct usage order
     $number = $this->m_lrgepRequestGatewayEntryPoints->sort('GatewayTransaction', 'Compare');
     // loop over the overall number of transaction attempts
     while (!$boTransactionSubmitted && $nOverallRetryCount < $this->m_nRetryAttempts) {
         $nOverallGatewayEntryPointCount = 0;
         // loop over the number of gateway entry points in the list
         while (!$boTransactionSubmitted && $nOverallGatewayEntryPointCount < $this->m_lrgepRequestGatewayEntryPoints->getCount()) {
             $rgepCurrentGatewayEntryPoint = $this->m_lrgepRequestGatewayEntryPoints->getAt($nOverallGatewayEntryPointCount);
             // ignore if the metric is "-1" this indicates that the entry point is offline
             if ($rgepCurrentGatewayEntryPoint->getMetric() >= 0) {
                 $nGatewayEntryPointCount = 0;
                 $sSOAPClient->setURL($rgepCurrentGatewayEntryPoint->getEntryPointURL());
                 // loop over the number of times to try this specific entry point
                 while (!$boTransactionSubmitted && $nGatewayEntryPointCount < $rgepCurrentGatewayEntryPoint->getRetryAttempts()) {
                     if ($sSOAPClient->sendRequest($ResponseDocument, $ResponseMethod)) {
                         //getting the valid transaction type document format
                         $sxXmlDocument = $ResponseDocument->{$ResponseMethod};
                         $lszErrorMessages = new StringList();
                         $nStatusCode = (int) current($ResponseDocument->{$ResponseMethod}->{$szGatewayOutputXMLPath}->StatusCode[0]);
                         // a status code of 50 means that this entry point is not to be used
                         if ($nStatusCode != 50) {
                             // the transaction was submitted
                             $boTransactionSubmitted = true;
                             if ($ResponseDocument->{$ResponseMethod}->{$szGatewayOutputXMLPath}->Message) {
                                 $szMessage = current($ResponseDocument->{$ResponseMethod}->{$szGatewayOutputXMLPath}->Message[0]);
                             }
                             if ($ResponseDocument->{$ResponseMethod}->{$szGatewayOutputXMLPath}->ErrorMessages) {
                                 foreach ($ResponseDocument->{$ResponseMethod}->{$szGatewayOutputXMLPath}->ErrorMessages->MessageDetail as $key => $value) {
                                     $lszErrorMessages->add(current($value->Detail));
                                 }
                             }
                             if ($ResponseDocument->{$ResponseMethod}->{$szGatewayOutputXMLPath}->attributes()) {
                                 foreach ($ResponseDocument->{$ResponseMethod}->{$szGatewayOutputXMLPath}->attributes() as $key => $value) {
                                     $boAuthorisationAttempted = current($value);
                                     if (strtolower($boAuthorisationAttempted) == 'false') {
                                         $boAuthorisationAttempted = new NullableBool(false);
                                     } elseif (strtolower($boAuthorisationAttempted) == 'true') {
                                         $boAuthorisationAttempted = new NullableBool(true);
                                     } else {
                                         throw new Exception('Return value must be true or false');
                                     }
                                 }
                             }
                             if ($ResponseDocument->{$ResponseMethod}->{$szGatewayOutputXMLPath}->PassOutData) {
                                 $szPassOutData = current($ResponseDocument->{$ResponseMethod}->{$szGatewayOutputXMLPath}->PassOutData[0]);
                             } else {
                                 $szPassOutData = null;
                             }
                             //check to see if there is any previous transaction data
                             if ($ResponseDocument->{$ResponseMethod}->{$szGatewayOutputXMLPath}->PreviousTransactionResult->StatusCode) {
                                 $nPreviousStatusCode = new NullableInt(current($ResponseDocument->{$ResponseMethod}->{$szGatewayOutputXMLPath}->PreviousTransactionResult->StatusCode[0]));
                             } else {
                                 $nPreviousStatusCode = null;
                             }
                             if ($ResponseDocument->{$ResponseMethod}->{$szGatewayOutputXMLPath}->PreviousTransactionResult->Message) {
                                 $szPreviousMessage = current($ResponseDocument->{$ResponseMethod}->{$szGatewayOutputXMLPath}->PreviousTransactionResult->Message[0]);
                             }
                             if ($nPreviousStatusCode != null && !SharedFunctions::isStringNullOrEmpty($szPreviousMessage)) {
                                 $ptdPreviousTransactionResult = new PreviousTransactionResult($nPreviousStatusCode, $szPreviousMessage);
                             }
                             $goGatewayOutput = new GatewayOutput($nStatusCode, $szMessage, $szPassOutData, $boAuthorisationAttempted, $ptdPreviousTransactionResult, $lszErrorMessages);
                             // look to see if there are any gateway entry points
                             $nCount = 0;
                             //$szXMLFormatString = $ResponseDocument->$ResponseMethod->$szTransactionMessageXMLPath->GatewayEntryPoints->GatewayEntryPoint;
                             $nMetric = -1;
                             if ($ResponseDocument->{$ResponseMethod}->{$szTransactionMessageXMLPath}->GatewayEntryPoints) {
                                 if ($ResponseDocument->{$ResponseMethod}->{$szTransactionMessageXMLPath}->GatewayEntryPoints->GatewayEntryPoint) {
                                     $szXMLFormatString = $ResponseDocument->{$ResponseMethod}->{$szTransactionMessageXMLPath}->GatewayEntryPoints->GatewayEntryPoint;
                                     foreach ($szXMLFormatString->attributes() as $key => $value) {
                                         if (is_numeric(current($value))) {
                                             $nMetric = current($value);
                                         } else {
                                             $szEntryPointURL = current($value);
                                         }
                                     }
                                     //$gepGatewayEntryPoint = new GatewayEntryPoint($szEntryPointURL, $nMetric);
                                     if ($lgepGatewayEntryPoints == null) {
                                         $lgepGatewayEntryPoints = new GatewayEntryPointList();
                                     }
                                     $lgepGatewayEntryPoints->add($szEntryPointURL, $nMetric);
                                     //$lgepGatewayEntryPoints->add($gepGatewayEntryPoint);
                                 }
                             }
                             $nCount++;
                         }
                     }
                     $nGatewayEntryPointCount++;
                 }
             }
             $nOverallGatewayEntryPointCount++;
         }
         $nOverallRetryCount++;
     }
     $this->m_szLastRequest = $sSOAPClient->getSOAPPacket();
     $this->m_szLastResponse = $sSOAPClient->getLastResponse();
     $this->m_eLastException = $sSOAPClient->getLastException();
     return $boTransactionSubmitted;
 }
 protected function processTransactionBase(SOAP $sSOAPClient, $szMessageXMLPath, $szGatewayOutputXMLPath, $szTransactionMessageXMLPath, SimpleXMLElement &$sxXmlDocument = null, GatewayOutput &$goGatewayOutput = null, GatewayEntryPointList &$lgepGatewayEntryPoints = null)
 {
     $boTransactionSubmitted = false;
     $nOverallRetryCount = 0;
     $nOverallGatewayEntryPointCount = 0;
     $nGatewayEntryPointCount = 0;
     $nErrorMessageCount = 0;
     $rgepCurrentGatewayEntryPoint;
     $nStatusCode;
     $szMessage = null;
     $lszErrorMessages;
     $szString;
     $sbXMLString;
     $szXMLFormatString;
     $nCount = 0;
     $szEntryPointURL;
     $nMetric;
     $gepGatewayEntryPoint = null;
     $ResponseDocument = null;
     $ResponseMethod = null;
     $lgepGatewayEntryPoints = null;
     $goGatewayOutput = null;
     $this->m_szEntryPointUsed = null;
     if ($sSOAPClient == null) {
         return false;
     }
     // populate the merchant details
     if ($this->m_maMerchantAuthentication != null) {
         if (!SharedFunctions::isStringNullOrEmpty($this->m_maMerchantAuthentication->getMerchantID())) {
             $sSOAPClient->addParamAttribute($szMessageXMLPath . '.MerchantAuthentication', 'MerchantID', $this->m_maMerchantAuthentication->getMerchantID());
         }
         if (!SharedFunctions::isStringNullOrEmpty($this->m_maMerchantAuthentication->getPassword())) {
             $sSOAPClient->addParamAttribute($szMessageXMLPath . '.MerchantAuthentication', 'Password', $this->m_maMerchantAuthentication->getPassword());
         }
     }
     // first need to sort the gateway entry points into the correct usage order
     $number = $this->m_lrgepRequestGatewayEntryPoints->sort('GatewayTransaction', 'Compare');
     // loop over the overall number of transaction attempts
     while (!$boTransactionSubmitted && $nOverallRetryCount < $this->m_nRetryAttempts) {
         $nOverallGatewayEntryPointCount = 0;
         // loop over the number of gateway entry points in the list
         while (!$boTransactionSubmitted && $nOverallGatewayEntryPointCount < $this->m_lrgepRequestGatewayEntryPoints->getCount()) {
             $rgepCurrentGatewayEntryPoint = $this->m_lrgepRequestGatewayEntryPoints->getAt($nOverallGatewayEntryPointCount);
             // ignore if the metric is "-1" this indicates that the entry point is offline
             if ($rgepCurrentGatewayEntryPoint->getMetric() >= 0) {
                 $nGatewayEntryPointCount = 0;
                 $sSOAPClient->setURL($rgepCurrentGatewayEntryPoint->getEntryPointURL());
                 // loop over the number of times to try this specific entry point
                 while (!$boTransactionSubmitted && $nGatewayEntryPointCount < $rgepCurrentGatewayEntryPoint->getRetryAttempts()) {
                     if ($sSOAPClient->sendRequest($ResponseDocument, $ResponseMethod)) {
                         //getting the valid transaction type document format
                         $sxXmlDocument = $ResponseDocument->{$ResponseMethod};
                         $lszErrorMessages = new StringList();
                         $nStatusCode = (int) current($ResponseDocument->{$ResponseMethod}->{$szGatewayOutputXMLPath}->StatusCode[0]);
                         // a status code of 50 means that this entry point is not to be used
                         if ($nStatusCode != 50) {
                             $this->m_szEntryPointUsed = $rgepCurrentGatewayEntryPoint->getEntryPointURL();
                             // the transaction was submitted
                             $boTransactionSubmitted = true;
                             if ($ResponseDocument->{$ResponseMethod}->{$szGatewayOutputXMLPath}->Message) {
                                 $szMessage = current($ResponseDocument->{$ResponseMethod}->{$szGatewayOutputXMLPath}->Message[0]);
                             }
                             if ($ResponseDocument->{$ResponseMethod}->{$szGatewayOutputXMLPath}->ErrorMessages) {
                                 foreach ($ResponseDocument->{$ResponseMethod}->{$szGatewayOutputXMLPath}->ErrorMessages->MessageDetail as $key => $value) {
                                     $lszErrorMessages->add(current($value->Detail));
                                 }
                             }
                             $goGatewayOutput = new GatewayOutput($nStatusCode, $szMessage, $lszErrorMessages);
                             // look to see if there are any gateway entry points
                             $nCount = 0;
                             $nMetric = -1;
                             if ($ResponseDocument->{$ResponseMethod}->{$szTransactionMessageXMLPath}->GatewayEntryPoints) {
                                 if ($ResponseDocument->{$ResponseMethod}->{$szTransactionMessageXMLPath}->GatewayEntryPoints->GatewayEntryPoint) {
                                     $szXMLFormatString = $ResponseDocument->{$ResponseMethod}->{$szTransactionMessageXMLPath}->GatewayEntryPoints->GatewayEntryPoint;
                                     foreach ($szXMLFormatString->attributes() as $key => $value) {
                                         if (is_numeric(current($value))) {
                                             $nMetric = current($value);
                                         } else {
                                             $szEntryPointURL = current($value);
                                         }
                                     }
                                     //$gepGatewayEntryPoint = new GatewayEntryPoint($szEntryPointURL, $nMetric);
                                     if ($lgepGatewayEntryPoints == null) {
                                         $lgepGatewayEntryPoints = new GatewayEntryPointList();
                                     }
                                     $lgepGatewayEntryPoints->add($szEntryPointURL, $nMetric);
                                     //$lgepGatewayEntryPoints->add($gepGatewayEntryPoint);
                                 }
                             }
                             $nCount++;
                         }
                     } else {
                         error_log("send failed" . "\n", 3, SITE_PATH . "plugins/Payment_Sense/paymentSense.log");
                     }
                     $nGatewayEntryPointCount++;
                 }
             }
             $nOverallGatewayEntryPointCount++;
         }
         $nOverallRetryCount++;
     }
     $this->m_szLastRequest = $sSOAPClient->getSOAPPacket();
     $this->m_szLastResponse = $sSOAPClient->getLastResponse();
     $this->m_eLastException = $sSOAPClient->getLastException();
     return $boTransactionSubmitted;
 }