コード例 #1
0
ファイル: Request.php プロジェクト: nahakiole/cloudrexx
 /**
  * Sends a request based on the provided request model and according to the argumented method
  * @param \Paymill\Models\Request\Base $model
  * @param string $method (Create, update, delete, getAll, getOne)
  * @throws PaymillException
  * @return \Paymill\Models\Response\Base|\Paymill\Models\Response\Error
  */
 private function _request(Base $model, $method)
 {
     if (!is_a($this->_connectionClass, '\\Paymill\\API\\CommunicationAbstract')) {
         throw new PaymillException(null, 'The connenction class is missing!');
     }
     $httpMethod = $this->_getHTTPMethod($method);
     $parameter = $model->parameterize($method);
     $serviceResource = $model->getServiceResource() . $model->getId();
     try {
         $this->_lastRequest = $parameter;
         $response = $this->_connectionClass->requestApi($serviceResource, $parameter, $httpMethod);
         $this->_lastResponse = $response;
         $responseHandler = new ResponseHandler();
         if ($method === 'getAll') {
             if ($responseHandler->validateResponse($response)) {
                 $convertedResponse = $response['body']['data'];
             } else {
                 $convertedResponse = $responseHandler->convertResponse($response, $model->getServiceResource());
             }
         } else {
             $convertedResponse = $responseHandler->convertResponse($response, $model->getServiceResource());
         }
     } catch (Exception $e) {
         $errorModel = new Error();
         $convertedResponse = $errorModel->setErrorMessage($e->getMessage());
     }
     if (is_a($convertedResponse, '\\Paymill\\Models\\Response\\Error')) {
         throw new PaymillException($convertedResponse->getResponseCode(), $convertedResponse->getErrorMessage(), $convertedResponse->getHttpStatusCode());
     }
     return $convertedResponse;
 }
コード例 #2
0
ファイル: Request.php プロジェクト: ukrosoft/virtuals
 /**
  * Sends a request based on the provided request model and according to the argumented method
  * @param \Paymill\Models\Request\Base $model
  * @param string $method (Create, update, delete, getAll, getOne)
  * @throws PaymillException
  * @return \Paymill\Models\Response\Base|\Paymill\Models\Response\Error
  */
 private function _request(Base $model, $method)
 {
     if (!is_a($this->_connectionClass, '\\Paymill\\API\\CommunicationAbstract')) {
         throw new PaymillException(null, 'The connection class is missing!');
     }
     $convertedResponse = null;
     $httpMethod = $this->_getHTTPMethod($method);
     $parameter = $model->parameterize($method);
     $serviceResource = $model->getServiceResource() . $model->getId();
     if (is_a($model, "\\Paymill\\Models\\Request\\Transaction") && $method === "create") {
         $source = !array_key_exists('source', $parameter) ? "PhpLib" . $this->getVersion() : "PhpLib" . $this->getVersion() . "_" . $parameter['source'];
         $parameter['source'] = $source;
     }
     try {
         $this->_lastRequest = $parameter;
         $response = $this->_connectionClass->requestApi($serviceResource, $parameter, $httpMethod);
         var_dump($parameter);
         var_dump($response);
         $this->_lastResponse = $response;
         $responseHandler = new ResponseHandler();
         if ($method === "getAllAsModel" && $responseHandler->validateResponse($response) && $this->_util->isNumericArray($response['body']['data'])) {
             foreach ($response['body']['data'] as $object) {
                 $convertedResponse[] = $responseHandler->convertResponse($object, $model->getServiceResource());
             }
         } elseif ($method === "getAll" && $responseHandler->validateResponse($response)) {
             $convertedResponse = $response['body']['data'];
         } elseif ($responseHandler->validateResponse($response)) {
             $convertedResponse = $responseHandler->convertResponse($response['body']['data'], $model->getServiceResource());
         } else {
             $convertedResponse = $responseHandler->convertErrorToModel($response, $model->getServiceResource());
         }
     } catch (\Exception $e) {
         $errorModel = new Error();
         $convertedResponse = $errorModel->setErrorMessage($e->getMessage());
     }
     if (is_a($convertedResponse, '\\Paymill\\Models\\Response\\Error')) {
         throw new PaymillException($convertedResponse->getResponseCode(), $convertedResponse->getErrorMessage(), $convertedResponse->getHttpStatusCode(), $convertedResponse->getRawObject());
     }
     return $convertedResponse;
 }