/** * Configura o objeto com a chave de API e o endpoint da instalação. * * @param string $endpoint Domínio da sua instalação * @param string $apiKey Chave de api gerada dentro do Fatura Simples */ public static function configure($endpoint, $apiKey, $apiVersion = null) { if (strlen($apiKey) > 10) { self::$apiKey = $apiKey; } else { throw new Exception(__CLASS__ . ': informe uma chave de api válida.'); } if (strlen($endpoint) > 0) { // Aceita que o endpoint seja passado completo como uma URL if (stripos($endpoint, 'http') !== false) { self::$endpoint = $endpoint; } else { self::$endpoint = "https://{$endpoint}.faturasimples.com.br"; } } if ($apiVersion !== null) { self::$apiVersion = $apiVersion; } if (!strlen(self::$endpoint) || !preg_match("/^https?:\\/\\/([a-z0-9]{1,})/", self::$endpoint)) { throw new Exception(__CLASS__ . ": informe uma domínio válido. Você deve informar somente o nome da empresa, ex: 'suaempresa'."); } return true; }
/** * Define os parâmetros de conexão com o servidor. */ public function setUp() { FaturaSimples::configure('https://docs.faturasimples.com.br/api-tests', '2y6v8qnX3SUHZb0sanKWrQUnTAY'); }
/** * Teste de configuração válida. */ public function testValido() { $this->assertTrue(FaturaSimples::configure('dominio', '2y6v8qnX3SUHZb0sanKWrQUnTAY')); }