Skip to content

Commit

Permalink
Merge pull request #54 from nfe/atualizar-client-php
Browse files Browse the repository at this point in the history
Client PHP Atualizado
  • Loading branch information
gblmarquez authored May 9, 2018
2 parents a2d9a7f + 56a2274 commit d41b1c5
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 70 deletions.
4 changes: 2 additions & 2 deletions includes/admin/class-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function issue_invoice( $order_ids = array() ) {
$company_id = $this->get_company();
$issue_when_status = nfe_get_field( 'issue_when_status' );

NFe::setApiKey( $key );
NFe_io::setApiKey( $key );

foreach ( $order_ids as $order_id ) {

Expand Down Expand Up @@ -123,7 +123,7 @@ public function download_pdf_invoice( $order_ids = array() ) {
$key = $this->get_key();
$company_id = $this->get_company();

NFe::setApiKey( $key );
NFe_io::setApiKey( $key );

foreach ( $order_ids as $order_id ) {
$nfe = get_post_meta( $order_id, 'nfe_issued', true );
Expand Down
2 changes: 1 addition & 1 deletion includes/admin/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ protected function get_companies() {
return $company_list;
}

NFe::setApiKey( $key );
NFe_io::setApiKey( $key );

$companies = NFe_Company::search();

Expand Down
2 changes: 2 additions & 0 deletions lib/client-php/CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### 2.5 2017-01-22
* Fix a conflict in the name of the main class

### 2.4 2016-08-31
* Fix strtolower on api resource
Expand Down
16 changes: 10 additions & 6 deletions lib/client-php/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@

### Criar empresa
```php
NFe::setApiKey("c73d49f9649046eeba36dcf69f6334fd"); // Ache sua chave API no painel (https://app.nfe.io/account/apikeys)
NFe_io::setApiKey("c73d49f9649046eeba36dcf69f6334fd"); // Ache sua chave API no painel (https://app.nfe.io/account/apikeys)

NFe_Company::create(
$companyCreated = NFe_Company::create(
array(
'federalTaxNumber' => 87502637000164, // Use esse gerador para testar: http://www.geradordecnpj.org/
'name' => 'BANCO DO BRASIL SA',
Expand Down Expand Up @@ -84,13 +84,15 @@ NFe_Company::create(
)
)
);

echo($companyCreated->id);
```

### Emitir nota fiscal
```php
NFe::setApiKey('c73d49f9649046eeba36dcf69f6334fd'); // Ache sua chave API no painel (https://app.nfe.io/account/apikeys)
NFe_io::setApiKey('c73d49f9649046eeba36dcf69f6334fd'); // Ache sua chave API no painel (https://app.nfe.io/account/apikeys)

NFe_ServiceInvoice::create(
$invoiceCreated = NFe_ServiceInvoice::create(
// ID da empresa, você deve copiar exatamente como está no painel
'64555e0ee340420fdc94ad09',
// Dados da nota fiscal de serviço
Expand Down Expand Up @@ -136,11 +138,13 @@ NFe_ServiceInvoice::create(
)
)
);

echo($invoiceCreated->id);
```

### Cancelar nota fiscal
```php
NFe::setApiKey("c73d49f9649046eeba36dcf69f6334fd"); // Ache sua chave API no painel (https://app.nfe.io/account/apikeys)
NFe_io::setApiKey("c73d49f9649046eeba36dcf69f6334fd"); // Ache sua chave API no painel (https://app.nfe.io/account/apikeys)

$invoice = NFe_ServiceInvoice::fetch(
'64555e0ee340420fdc94ad09', // ID da empresa, você deve copiar exatamente como está no painel
Expand All @@ -154,7 +158,7 @@ if ( $invoice->status == 'Issued' ) {

### Download do PDF da nota fiscal
```php
NFe::setApiKey('c73d49f9649046eeba36dcf69f6334fd'); // Ache sua chave API no painel (https://app.nfe.io/account/apikeys)
NFe_io::setApiKey('c73d49f9649046eeba36dcf69f6334fd'); // Ache sua chave API no painel (https://app.nfe.io/account/apikeys)

$url = NFe_ServiceInvoice::pdf(
'64555e0ee340420fdc94ad09', // ID da empresa, você deve copiar exatamente como está no painel
Expand Down
2 changes: 1 addition & 1 deletion lib/client-php/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4
2.5
2 changes: 1 addition & 1 deletion lib/client-php/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nfe/nfe",
"description": "NFe.io PHP Library",
"homepage": "https://nfe.io",
"version": "2.4",
"version": "2.5",
"keywords": [
"nfe",
"nfse",
Expand Down
12 changes: 6 additions & 6 deletions lib/client-php/lib/NFe/APIRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class NFe_APIRequest {
public function __construct() {}

private function _defaultHeaders( $headers = array() ) {
$headers[] = "Authorization: Basic " . NFe::getApiKey();
$headers[] = "Authorization: Basic " . NFe_io::getApiKey();
$headers[] = "Content-Type: application/json";
$headers[] = "Accept: application/json";
$headers[] = "Accept-Charset: UTF-8";
Expand All @@ -17,12 +17,12 @@ private function _defaultHeaders( $headers = array() ) {
public function request( $method, $url, $data = array() ) {
global $last_api_response_code;

if ( NFe::getApiKey() == null ) {
if ( NFe_io::getApiKey() == null ) {
NFe_Utilities::authFromEnv();
}

if ( NFe::getApiKey() == null ) {
return new NFeAuthenticationException("Chave de API não configurada. Utilize NFe::setApiKey(...) para configurar.");
if ( NFe_io::getApiKey() == null ) {
return new NFeAuthenticationException("Chave de API não configurada. Utilize NFe_io::setApiKey(...) para configurar.");
}

$headers = $this->_defaultHeaders();
Expand Down Expand Up @@ -86,7 +86,7 @@ private function requestWithCURL( $method, $url, $headers, $data = array() ) {
$opts[CURLOPT_TIMEOUT] = 80;
$opts[CURLOPT_CONNECTTIMEOUT] = 30;
$opts[CURLOPT_HTTPHEADER] = $headers;
if ( NFe::$verifySslCerts == false ) {
if ( NFe_io::$verifySslCerts == false ) {
$opts[CURLOPT_SSL_VERIFYPEER] = false;
}
$opts[CURLOPT_SSL_VERIFYHOST] = 2;
Expand All @@ -107,7 +107,7 @@ private function requestWithCURL( $method, $url, $headers, $data = array() ) {
curl_setopt_array($curl, $opts);

// For debugging
if ( NFe::$debug == true ) {
if ( NFe_io::$debug == true ) {
curl_setopt( $curl, CURLOPT_PROXY, "127.0.0.1:8888" );
curl_setopt( $curl, CURLOPT_VERBOSE, 1 );
}
Expand Down
2 changes: 1 addition & 1 deletion lib/client-php/lib/NFe/APIResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static function endpointAPI( $object = null, $uri_path = '' ) {
$path = '/' . $object['id'];
}

return strtolower( NFe::getBaseURI() . $uri_path . '/' . self::objectBaseURI() . $path );
return strtolower( NFe_io::getBaseURI() . $uri_path . '/' . self::objectBaseURI() . $path );
}

public static function url( $object = null ) {
Expand Down
2 changes: 1 addition & 1 deletion lib/client-php/lib/NFe/NFe.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

abstract class NFe {
abstract class NFe_io {

// @var string The NFe API key to be used for requests.
public static $api_key = null;
Expand Down
4 changes: 2 additions & 2 deletions lib/client-php/lib/NFe/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class NFe_Utilities {
public static function authFromEnv() {
$apiKey = getenv('NFE_API_KEY');
if ($apiKey) {
NFe::setApiKey($apiKey);
NFe_io::setApiKey($apiKey);
}
}

Expand All @@ -30,7 +30,7 @@ public static function arrayToParams($array, $prefix = null) {
}

public static function arrayToParamsUrl($array, $prefix = null) {
if ( !is_array($array) ) {
if ( !is_array($array) ) {
return $array;
}

Expand Down
22 changes: 0 additions & 22 deletions lib/client-php/lib/Nfe.php

This file was deleted.

30 changes: 16 additions & 14 deletions lib/client-php/lib/init.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
<?php

$dir = dirname(__FILE__);

// NFe Base
require( dirname(__FILE__) . '/NFe/NFe.php' );
require( $dir . '/NFe/NFe.php' );

// NFe Errors
require( dirname(__FILE__) . '/NFe/Error.php' );
require( $dir . '/NFe/Error.php' );

// NFe Utilities
require( dirname(__FILE__) . '/NFe/Backward_Compatibility.php' );
require( dirname(__FILE__) . '/NFe/Utilities.php' );
require( $dir . '/NFe/Backward_Compatibility.php' );
require( $dir . '/NFe/Utilities.php' );

// NFe API Plumbing
require( dirname(__FILE__) . '/NFe/Object.php' );
require( dirname(__FILE__) . '/NFe/APIRequest.php' );
require( dirname(__FILE__) . '/NFe/APIResource.php' );
require( dirname(__FILE__) . '/NFe/APIChildResource.php' );
require( $dir . '/NFe/Object.php' );
require( $dir . '/NFe/APIRequest.php' );
require( $dir . '/NFe/APIResource.php' );
require( $dir . '/NFe/APIChildResource.php' );

// NFe API Resources
require( dirname(__FILE__) . '/NFe/Company.php' );
require( dirname(__FILE__) . '/NFe/LegalPerson.php' );
require( dirname(__FILE__) . '/NFe/NaturalPerson.php' );
require( dirname(__FILE__) . '/NFe/ServiceInvoice.php' );
require( dirname(__FILE__) . '/NFe/SearchResult.php' );
require( dirname(__FILE__) . '/NFe/Webhook.php' );
require( $dir . '/NFe/Company.php' );
require( $dir . '/NFe/LegalPerson.php' );
require( $dir . '/NFe/NaturalPerson.php' );
require( $dir . '/NFe/ServiceInvoice.php' );
require( $dir . '/NFe/SearchResult.php' );
require( $dir . '/NFe/Webhook.php' );
2 changes: 1 addition & 1 deletion lib/client-php/test/NFe/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
class NFe_TestCase extends UnitTestCase {
public function __construct() {
$apiKey = getenv('NFE_API_KEY');
NFe::setApiKey($apiKey);
NFe_io::setApiKey($apiKey);
}
}
18 changes: 10 additions & 8 deletions lib/client-php/test/Nfe.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?php

include_once( dirname(__FILE__) . '/../vendor/simpletest/simpletest/autorun.php');
$dir = dirname(__FILE__);

include_once( $dir . '/../vendor/simpletest/simpletest/autorun.php');

error_reporting( E_ALL | E_STRICT );

echo 'Running NFe.io PHP Test Suite - ';

include_once(dirname(__FILE__) . '/../lib/init.php');
include_once(dirname(__FILE__) . '/NFe/TestCase.php');
include_once(dirname(__FILE__) . '/NFe/CompanyTest.php');
include_once(dirname(__FILE__) . '/NFe/LegalPersonTest.php');
include_once(dirname(__FILE__) . '/NFe/NaturalPersonTest.php');
include_once(dirname(__FILE__) . '/NFe/WebhookTest.php');
include_once(dirname(__FILE__) . '/NFe/ServiceInvoiceTest.php');
include_once( $dir . '/../lib/init.php');
include_once( $dir . '/NFe/TestCase.php');
include_once( $dir . '/NFe/CompanyTest.php');
include_once( $dir . '/NFe/LegalPersonTest.php');
include_once( $dir . '/NFe/NaturalPersonTest.php');
include_once( $dir . '/NFe/WebhookTest.php');
include_once( $dir . '/NFe/ServiceInvoiceTest.php');
4 changes: 0 additions & 4 deletions lib/client-php/test/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
//o-------------------------------o
// Libraries
//o-------------------------------o
<<<<<<< Updated upstream
require( realpath(dirname(__FILE__) . "/../") . "/lib/init.php" );
=======
require( realpath(dirname(__FILE__) . "/../") . "/lib/NFe.php" );
>>>>>>> Stashed changes

//o-------------------------------o
// Configure time as GMT
Expand Down

0 comments on commit d41b1c5

Please sign in to comment.