protected function call($method, $data, $options = null)
 {
     $soapClient = $this->client;
     if (is_object($data[0])) {
         $data[0]->version = $this->version;
     }
     if ($this->isDebug) {
         MonetaSdkUtils::addToLog("soapCall method: {$method}\n");
         MonetaSdkUtils::addToLog("soapCall data:\n" . print_r($data, true));
     }
     $result = $soapClient->__soapCall($method, $data, $options, $this->inputHeaders, $this->outputHeaders);
     return $result;
 }
 /**
  * @param $method
  * @param $data
  * @param $options
  * @return array|mixed|null|object
  */
 private function jsonCall($method, $data, $options)
 {
     $data = json_decode(json_encode($data), true);
     if (!is_array($data) || !count($data)) {
         $data = array();
     }
     $inputData = array();
     foreach ($data as $itemKey => $itemVal) {
         if ($itemKey == "0") {
             $itemKey = "value";
         }
         if (!is_array($itemVal) || !count($itemVal)) {
             if (!empty($itemVal)) {
                 $inputData[$itemKey] = $itemVal;
             }
         } else {
             foreach ($itemVal as $requestBodyKey => $requestBodyVal) {
                 if (!empty($requestBodyVal)) {
                     $inputData[$requestBodyKey] = $requestBodyVal;
                 }
             }
         }
     }
     // no need to send version via json connector
     // $bodyData = array("{$method}Request" => array_merge(array("version" => $this->version), $inputData));
     // some methods needs special argument values defined
     if ($method == 'GetOperationDetailsById') {
         $inputData = $inputData['value'];
     }
     $bodyData = array("{$method}Request" => $inputData);
     // authorization data
     if (!$this->cert) {
         $requestData = array("Envelope" => array("Header" => array("Security" => array("UsernameToken" => array("Username" => $this->username, "Password" => $this->password))), "Body" => $bodyData));
     } else {
         $requestData = array("Envelope" => array("Body" => $bodyData));
     }
     if ($this->isDebug) {
         MonetaSdkUtils::addToLog("jsonCall request:\n" . print_r($requestData, true));
     }
     $requestData = json_encode($requestData);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $this->jsonConnectionUrl);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json;charset=UTF-8'));
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $requestData);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     if ($this->cert) {
         curl_setopt($ch, CURLOPT_SSLCERT, $this->cert);
     }
     $response = curl_exec($ch);
     curl_close($ch);
     if ($this->isDebug) {
         MonetaSdkUtils::addToLog("jsonCall curl response:\n{$response}");
     }
     $response = @json_decode($response, true);
     if (isset($response['Envelope']['Body'][$method . 'Response'])) {
         $result = $response['Envelope']['Body'][$method . 'Response'];
     } else {
         $result = $response;
     }
     return $result;
 }
 /**
  * @param $data
  * @return bool
  */
 public function parseJsonException($data)
 {
     $this->error = true;
     if ($this->getSettingValue('monetasdk_debug_mode')) {
         MonetaSdkUtils::addToLog("parseJsonException:\n" . $data);
     }
     if (isset($data['detail']['faultDetail'])) {
         $this->errorCode = $data['detail']['faultDetail'];
     }
     if (isset($data['faultstring'])) {
         $this->errorMessage = $data['faultstring'];
     }
     if ($this->errorCode && isset($this->settings[$this->errorCode])) {
         $this->errorMessageHumanConverted = $this->settings[$this->errorCode];
     } else {
         $this->errorMessageHumanConverted = $this->errorMessage;
         $handleServiceUnavailableEvent = MonetaSdkUtils::handleEvent('ServiceUnavailable', array('errorCode' => $this->errorCode, 'errorMessage' => $this->errorMessage, 'errorMessageHumanConverted' => $this->errorMessageHumanConverted), $this->getSettingValue('monetasdk_event_files_path'));
     }
 }
 /**
  * Switch and execute an action
  */
 public function processInputData($definedEventType = null)
 {
     $this->calledMethods[] = __FUNCTION__;
     $this->cleanResultData();
     $this->checkMonetaServiceConnection();
     $eventType = $this->detectEventTypeFromVars();
     if ($this->getSettingValue('monetasdk_debug_mode')) {
         MonetaSdkUtils::addToLog("processInputData event:\n" . $eventType);
         MonetaSdkUtils::addToLog("processInputData GET:\n" . print_r($_GET, true));
         MonetaSdkUtils::addToLog("processInputData POST:\n" . print_r($_POST, true));
     }
     $processResultData = array();
     if ($eventType && (!$definedEventType || $definedEventType == $eventType)) {
         // handle event
         $isEventHandled = MonetaSdkUtils::handleEvent($eventType, array('postVars' => $_POST, 'getVars' => $_GET, 'cookieVars' => $_COOKIE), $this->getSettingValue('monetasdk_event_files_path'));
         // handle internal event
         if (in_array($eventType, $this->getInternalEventNames())) {
             switch ($eventType) {
                 case 'ForwardPaymentForm':
                     $this->processForwardPaymentForm();
                     break;
                 case 'ForwardPaymentFormIframe':
                     $this->processForwardPaymentForm();
                     break;
                 case 'MonetaSendCallBack':
                     $this->processMonetaSendCallBack();
                     break;
                 case 'ForwardChoosePaymentSystemForm':
                     $this->processForwardChoosePaymentSystemForm();
                     $this->processCookieRedirect();
                     break;
                 case 'ForwardCreateUserForm':
                     $processResultData = $this->processForwardCreateUserForm($processResultData);
                     $this->processCookieRedirect();
                     break;
                 case 'ForwardAccountHistoryForm':
                     $processResultData = $this->processForwardAccountHistoryForm();
                     break;
                 case 'CancelRegularPayment':
                     $this->processCancelRegularPayment();
                     break;
             }
             $this->events[] = $eventType;
         }
         $this->data = array("event" => $eventType, "processResultData" => $processResultData);
         if ($this->getSettingValue('monetasdk_debug_mode')) {
             MonetaSdkUtils::addToLog("processInputData data:\n" . print_r($this->data, true));
         }
     }
     return $this->getCurrentMethodResult();
 }