Esempio n. 1
0
 /**
  * Perform an API call, and interpret the results and convert them to correct objects.
  *
  * @param      $http_method
  * @param      $api_method
  * @param null $http_body
  *
  * @return object
  * @throws Mollie_API_Exception
  */
 protected function performApiCall($http_method, $api_method, $http_body = NULL)
 {
     $body = $this->api->performHttpCall($http_method, $api_method, $http_body);
     if (!($object = @json_decode($body))) {
         throw new Mollie_API_Exception("Unable to decode Mollie response: '{$body}'.");
     }
     if (!empty($object->error)) {
         $exception = new Mollie_API_Exception("Error executing API call ({$object->error->type}): {$object->error->message}.");
         if (!empty($object->error->field)) {
             $exception->setField($object->error->field);
         }
         throw $exception;
     }
     return $object;
 }
Esempio n. 2
0
 /**
  * Perform an API call, and interpret the results and convert them to correct objects.
  *
  * @param      $http_method
  * @param      $api_method
  * @param null $http_body
  *
  * @return object
  * @throws Mollie_API_Exception
  */
 protected function performApiCall($http_method, $api_method, $http_body = NULL)
 {
     $body = $this->api->performHttpCall($http_method, $api_method, $http_body);
     if ($this->api->getLastHttpResponseStatusCode() == Mollie_API_Client::HTTP_STATUS_NO_CONTENT) {
         return NULL;
     }
     if (empty($body)) {
         throw new Mollie_API_Exception("Unable to decode Mollie response: '{$body}'.");
     }
     $object = @json_decode($body);
     if (json_last_error() != JSON_ERROR_NONE) {
         throw new Mollie_API_Exception("Unable to decode Mollie response: '{$body}'.");
     }
     if (!empty($object->error)) {
         $exception = new Mollie_API_Exception("Error executing API call ({$object->error->type}): {$object->error->message}.");
         if (!empty($object->error->field)) {
             $exception->setField($object->error->field);
         }
         throw $exception;
     }
     return $object;
 }