/**
  * Get from webservice installments for direct payment.
  * @param PagSeguroCredentials $credentials
  * @param $amount
  * @param $cardBrand
  * @param $maxInstallmentNoInterest
  * @return bool|PagSeguroInstallment
  * @throws Exception
  * @throws PagSeguroServiceException
  */
 public static function getInstallments(PagSeguroCredentials $credentials, $amount, $cardBrand = null, $maxInstallmentNoInterest = null)
 {
     $amount = PagSeguroHelper::decimalFormat($amount);
     LogPagSeguro::info("PagSeguroInstallmentService.getInstallments(" . $amount . ") - begin");
     self::$connectionData = new PagSeguroConnectionData($credentials, self::SERVICE_NAME);
     try {
         $connection = new PagSeguroHttpConnection();
         $connection->get(self::buildInstallmentURL(self::$connectionData, $amount, $cardBrand, $maxInstallmentNoInterest), self::$connectionData->getServiceTimeout(), self::$connectionData->getCharset());
         $httpStatus = new PagSeguroHttpStatus($connection->getStatus());
         switch ($httpStatus->getType()) {
             case 'OK':
                 $installments = PagSeguroInstallmentParser::readInstallments($connection->getResponse());
                 LogPagSeguro::info("PagSeguroInstallmentService.getInstallments() - end ");
                 break;
             case 'BAD_REQUEST':
                 $errors = PagSeguroInstallmentParser::readErrors($connection->getResponse());
                 $e = new PagSeguroServiceException($httpStatus, $errors);
                 LogPagSeguro::error("PagSeguroInstallmentService.getInstallments() - error " . $e->getOneLineMessage());
                 throw $e;
                 break;
             default:
                 $e = new PagSeguroServiceException($httpStatus);
                 LogPagSeguro::error("PagSeguroInstallmentService.getInstallments() - error " . $e->getOneLineMessage());
                 throw $e;
                 break;
         }
         return isset($installments) ? $installments : false;
     } catch (PagSeguroServiceException $e) {
         throw $e;
     } catch (Exception $e) {
         LogPagSeguro::error("Exception: " . $e->getMessage());
         throw $e;
     }
 }