From 41cbabc4038f4f0c7a5d101fb538cddcbc2a4330 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Thu, 17 May 2018 15:19:25 -0300 Subject: [PATCH 1/5] Minor updates --- includes/admin/class-api.php | 4 +- includes/admin/class-emails.php | 50 +++++++++---------- .../emails/class-nfe-email-receipt-issued.php | 10 ++-- package.json | 2 +- templates/emails/nfe-receipt-issued.php | 5 +- templates/emails/plain/nfe-receipt-issued.php | 3 +- tests/bootstrap.php | 1 - tests/test-sample.php | 14 +----- woo-nfe.php | 4 +- 9 files changed, 38 insertions(+), 55 deletions(-) diff --git a/includes/admin/class-api.php b/includes/admin/class-api.php index f6d46e8..debfad4 100755 --- a/includes/admin/class-api.php +++ b/includes/admin/class-api.php @@ -65,7 +65,7 @@ public function issue_invoice( $order_ids = array() ) { $this->logger( $log ); $order->add_order_note( $log ); - // If value is 0, don't issue it. + // If value is 0.00, don't issue it. if ( '0.00' === $order->get_total() ) { $log = sprintf( __( 'Not possible to issue NFe without an order value! Order: #%d', 'woo-nfe' ), $order_id ); $this->logger( $log ); @@ -701,7 +701,7 @@ protected function country_iso_codes() { 'VNM' => 'VN', // Vietnam 'YEM' => 'YE', // Yemen 'ZAF' => 'ZA', // South Africa - 'ZWE' => 'ZW', // Zimbabwe + 'ZWE' => 'ZW', // Zimbabwe. ); } diff --git a/includes/admin/class-emails.php b/includes/admin/class-emails.php index db96839..7da1cfb 100644 --- a/includes/admin/class-emails.php +++ b/includes/admin/class-emails.php @@ -1,38 +1,36 @@ customer_email = true; // Triggers. - add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $this, 'trigger' ) ); - add_action( 'woocommerce_order_status_pending_to_completed_notification', array( $this, 'trigger' ) ); - add_action( 'woocommerce_order_status_completed_notification', array( $this, 'trigger' ) ); - add_action( 'woocommerce_renewal_order_payment_complete', array( $this, 'trigger') ); + add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $this, 'trigger' ) ); + add_action( 'woocommerce_order_status_pending_to_completed_notification', array( $this, 'trigger' ) ); + add_action( 'woocommerce_order_status_completed_notification', array( $this, 'trigger' ) ); + add_action( 'woocommerce_renewal_order_payment_complete', array( $this, 'trigger') ); parent::__construct(); } diff --git a/package.json b/package.json index a951e42..649d057 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "nfe", "title": "WooCommerce NFe", - "version": "1.2.4", + "version": "1.2.5", "author": "NFe.io", "homepage": "https://github.com/nfe/woo-nfe", "description": "WooCommerce extension for issuing invoices using the NFe.io API", diff --git a/templates/emails/nfe-receipt-issued.php b/templates/emails/nfe-receipt-issued.php index 22eaf1d..5c34ee6 100644 --- a/templates/emails/nfe-receipt-issued.php +++ b/templates/emails/nfe-receipt-issued.php @@ -1,5 +1,4 @@ -

+

download_pdf_invoice( array( $order ) ); - - $this->assertNotNull($pdf); - } - /** * NFe Fields */ public function test_nfe_options_fields() { $nfe_fields = nfe_get_field(); - $this->assertNotNull($nfe_fields); + $this->assertNotNull( $nfe_fields ); } } diff --git a/woo-nfe.php b/woo-nfe.php index 019c49a..91cc51b 100644 --- a/woo-nfe.php +++ b/woo-nfe.php @@ -20,8 +20,8 @@ * Domain Path: /languages * Network: false * - * WC requires at least: 3.3.3 - * WC tested up to: 3.3.3 + * WC requires at least: 3.3.5 + * WC tested up to: 3.3.5 * * Copyright: © 2018 NFe.io * License: GNU General Public License v3.0 From 8a349087322cbe75d033c90510a96e90c19eb07a Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Thu, 17 May 2018 15:33:21 -0300 Subject: [PATCH 2/5] Updating readme.txt file --- README.txt | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/README.txt b/README.txt index 8debe4f..0f9a8f8 100644 --- a/README.txt +++ b/README.txt @@ -22,22 +22,18 @@ WooCommerce NFe is a WooCommerce extension for issuing invoices using the NFe.io Thanks in advance for your help on any translation efforts! -== Frequently Asked Questions == - == Installation == -1. Upload woo-nfe.zip to wp-content/plugins -2. Click "Activate" in the WordPress plugins menu - -== Changelog == +1. Go the *Plugins* menu and click *Add New*. +2. Search for *WooCommerce NFe*. +3. Click *Install Now*. -= 1.0.0 = -* Initial commit +or -= 1.0.1 = -* Fix issue #6 +1. Upload woo-nfe.zip to wp-content/plugins folder +2. Click "Activate" in the WordPress plugins menu -== Upgrade Notice == +== Changelog == = 1.0.0 = * Initial release @@ -64,3 +60,5 @@ Thanks in advance for your help on any translation efforts! * Fixed a bug that gave fatal error when on before PHP 5.5 versions. * Fix - load_textdomain first from WP_LANG_DIR before load_plugin_textdomain * Tweak - Tweak load_plugin_textdomain to be relative - this falls back to WP_LANG_DIR automatically. Can prevent "open_basedir restriction in effect". + +== Upgrade Notice == From 0686a5b2a3f6fad8a1ed64cf1d7bc4838dc67ad2 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Thu, 17 May 2018 16:06:51 -0300 Subject: [PATCH 3/5] Fixing lib folder loading --- woo-nfe.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/woo-nfe.php b/woo-nfe.php index 0bb8112..ba7cca0 100644 --- a/woo-nfe.php +++ b/woo-nfe.php @@ -105,7 +105,7 @@ private function includes() { $composer_path = $this->plugin_dir . 'vendor/autoload.php'; if ( ! file_exists( $composer_path ) ) { - require( $this->plugin_dir . 'lib/client-php/lib/init.php' ); + require( $this->plugin_dir . 'li/client-php/lib/init.php' ); } else { require( $composer_path ); } From 2c4e595e4c1fcd6ff308318a5b5eb28b2323a608 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Mon, 9 Jul 2018 19:04:52 -0300 Subject: [PATCH 4/5] =?UTF-8?q?Corre=C3=A7=C3=A3o:=20A=20forma=20como=20es?= =?UTF-8?q?t=C3=A1vamos=20verificando=20o=20tipo=20de=20cliente=20estava?= =?UTF-8?q?=20criando=20falsos=20positivos.=20J=C3=A1=20que=20o=20campo=20?= =?UTF-8?q?retornada=20string=20e=20estava=20verifiando=20(int).=20Esse=20?= =?UTF-8?q?commit=20corrige=20esse=20erro/bug.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/admin/class-api.php | 86 +++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/includes/admin/class-api.php b/includes/admin/class-api.php index debfad4..0f3db56 100755 --- a/includes/admin/class-api.php +++ b/includes/admin/class-api.php @@ -160,33 +160,33 @@ public function order_info( $order_id ) { $order = nfe_wc_get_order( $order_id ); $address = [ - 'postalCode' => $this->check_customer_info( 'cep', $order_id ), - 'street' => $this->remover_caracter( $this->check_customer_info( 'street', $order_id ) ), - 'number' => $this->remover_caracter( $this->check_customer_info( 'address_number', $order_id ) ), + 'postalCode' => $this->check_customer_info( 'cep', $order_id ), + 'street' => $this->remover_caracter( $this->check_customer_info( 'street', $order_id ) ), + 'number' => $this->remover_caracter( $this->check_customer_info( 'address_number', $order_id ) ), 'additionalInformation' => $this->remover_caracter( get_post_meta( $order_id, '_billing_address_2', true ) ), - 'district' => $this->remover_caracter( $this->check_customer_info( 'district', $order_id ) ), - 'country' => $this->remover_caracter( $this->billing_country( $order_id ) ), - 'state' => $this->remover_caracter( $this->check_customer_info( 'state', $order_id ) ), - 'city' => [ - 'code' => $this->ibge_code( $order_id ), - 'name' => $this->remover_caracter( $this->check_customer_info( 'city', $order_id ) ), + 'district' => $this->remover_caracter( $this->check_customer_info( 'district', $order_id ) ), + 'country' => $this->remover_caracter( $this->billing_country( $order_id ) ), + 'state' => $this->remover_caracter( $this->check_customer_info( 'state', $order_id ) ), + 'city' => [ + 'code' => $this->ibge_code( $order_id ), + 'name' => $this->remover_caracter( $this->check_customer_info( 'city', $order_id ) ), ], ]; - $borrower = array( - 'name' => $this->remover_caracter( $this->check_customer_info( 'name', $order_id ) ), - 'email' => get_post_meta( $order_id, '_billing_email', true ), - 'federalTaxNumber' => $this->removepontotraco( $this->check_customer_info( 'number', $order_id ) ), - 'address' => $address, - ); + $borrower = [ + 'name' => $this->check_customer_info( 'name', $order_id ), + 'email' => get_post_meta( $order_id, '_billing_email', true ), + 'federalTaxNumber' => $this->removepontotraco( $this->check_customer_info( 'number', $order_id ) ), + 'address' => $address, + ]; - $data = array( - 'cityServiceCode' => $this->city_service_info( 'code', $order_id ), - 'federalServiceCode' => $this->city_service_info( 'fed_code', $order_id ), - 'description' => $this->remover_caracter( $this->city_service_info( 'desc', $order_id ) ), - 'servicesAmount' => $order->get_total(), - 'borrower' => $borrower, - ); + $data = [ + 'cityServiceCode' => $this->city_service_info( 'code', $order_id ), + 'federalServiceCode' => $this->city_service_info( 'fed_code', $order_id ), + 'description' => $this->remover_caracter( $this->city_service_info( 'desc', $order_id ) ), + 'servicesAmount' => $order->get_total(), + 'borrower' => $borrower, + ]; // Removes empty, false and null fields from the array. return array_filter( $data ); @@ -222,7 +222,7 @@ protected function billing_country( $order_id ) { * Fetche the IBGE Code. * * @param int $order_id Order ID. - * @return string + * @return string|null */ protected function ibge_code( $order_id ) { $key = $this->get_key(); @@ -317,31 +317,37 @@ protected function check_customer_info( $field = '', $order ) { return; } - // Customer Person Type. - (int) $type = get_post_meta( $order, '_billing_persontype', true ); + // Person Type. + $type = get_post_meta( $order, '_billing_persontype', true ); switch ( $field ) { - case 'number': // Customer ID Number. - if ( 1 === $type || empty( $type ) ) { - $output = $this->cpf( get_post_meta( $order, '_billing_cpf', true ) ); - } elseif ( 2 === $type || empty( $type ) || empty( $output ) ) { - $output = $this->cnpj( get_post_meta( $order, '_billing_cnpj', true ) ); + case 'number': + if ( ! empty( $type ) ) { + if ( '1' === $type ) { + $output = $this->cpf( get_post_meta( $order, '_billing_cpf', true ) ); + } else { + $output = $this->cnpj( get_post_meta( $order, '_billing_cnpj', true ) ); + } } break; - case 'name': // Customer Name/Razão Social. - if ( 1 === $type || empty( $type ) ) { - $output = get_post_meta( $order, '_billing_first_name', true ) . ' ' . get_post_meta( $order, '_billing_last_name', true ); - } elseif ( 2 === $type || empty( $type ) || empty( $output ) ) { - $output = get_post_meta( $order, '_billing_company', true ); + case 'name': + if ( ! empty( $type ) ) { + if ( '1' === $type ) { + $output = get_post_meta( $order, '_billing_first_name', true ) . ' ' . get_post_meta( $order, '_billing_last_name', true ); + } else { + $output = get_post_meta( $order, '_billing_company', true ); + } } break; - case 'type': // Customer Type. - if ( 1 === $type || empty( $type ) ) { - $output = __( 'Customers', 'woo-nfe' ); - } elseif ( 2 === $type ) { - $output = __( 'Company', 'woo-nfe' ); + case 'type': + if ( ! empty( $type ) ) { + if ( '1' === $type ) { + $output = __( 'Customers', 'woo-nfe' ); + } else { + $output = __( 'Company', 'woo-nfe' ); + } } break; From 40b2dad209c10beb0aa47280e940dede843bf019 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Mon, 9 Jul 2018 19:18:20 -0300 Subject: [PATCH 5/5] Bumping the version and updating readme --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++-- README.txt | 7 +++++-- composer.json | 2 +- package.json | 2 +- woo-nfe.php | 4 ++-- 5 files changed, 52 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6567d60..1d5b719 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,12 @@ +# WooCommerce NFe (NFe.io) -# Woo NFe +WooCommerce NFe é uma extensão do WooCommerce para emitir notas fiscais utilizando a API do NFe.io. -Woo NFe é uma extensão do WooCommerce para emitir notas fiscais utilizando a API do NFe.io +## Requisitos + +* PHP >= 5.5 +* WP >= 4.9 +* WooCommerce >= 3.3.5 ## Instalação @@ -9,3 +14,39 @@ Woo NFe é uma extensão do WooCommerce para emitir notas fiscais utilizando a A 2. Pesquise por *WooCommerce NFe*. 3. Clique em *Instalar Agora*. 4. Ativar o plugin + +Ou você pode colocar este plugin no diretório wp-content/plugins e ativá-lo. + +## Changelog ## + +### 1.0 +* Initial release + +### 1.0.1 +* Fix issue #6 + +### 1.0.2 +* Added trigger to issue invoices on specific status +* Fixed when issue invoices federal tax number must be only numbers + +### 1.0.3 +* Added support to issue invoices without all address fields filled + +### 1.0.4 +* Fix support to issue invoices without all address fields filled +* Fix trigger to issue invoices on specific status + +### 1.2.5 +* Added option to require an address when issuing an invoice. +* Fixed a bug where zero orders could be issued. +* Added notice in the order list when a order is zeroed. +* Added php require header on the readme.txt +* Fixed a bug that gave fatal error when on before PHP 5.5 versions. +* Fix - load_textdomain first from WP_LANG_DIR before load_plugin_textdomain +* Tweak - Tweak load_plugin_textdomain to be relative - this falls back to WP_LANG_DIR automatically. Can prevent "open_basedir restriction in effect". + +### 1.2.6 +* Fixing client-php folder conflict. + +### 1.2.7 +* Fixing how we verify the type of customer to output its information on the NFe receipt. diff --git a/README.txt b/README.txt index d161f75..35f786f 100644 --- a/README.txt +++ b/README.txt @@ -3,9 +3,9 @@ Contributors: nfe, espellcaste Tags: woocommerce, shop, receipt, nfe, nota fiscal, nota, receita, sefaz, nfse, emitir nfse, emitir nfe Requires at least: 4.7 Tested up to: 4.9.4 -Stable tag: 1.2.6 +Stable tag: 1.2.7 Requires PHP: 5.5 -WC tested up to: 3.3.5 +WC tested up to: 3.4.3 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -63,3 +63,6 @@ or = 1.2.6 = * Fixing client-php folder conflict. + += 1.2.7 = +* Fixing how we verify the type of customer to output its information on the NFe receipt. diff --git a/composer.json b/composer.json index c866f58..3d3de7c 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ }, { "name" : "Renato Alves", - "homepage": "http://ralv.es/" + "homepage": "https://ralv.es/" } ], "support": { diff --git a/package.json b/package.json index 649d057..5d7df72 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "nfe", "title": "WooCommerce NFe", - "version": "1.2.5", + "version": "1.2.7", "author": "NFe.io", "homepage": "https://github.com/nfe/woo-nfe", "description": "WooCommerce extension for issuing invoices using the NFe.io API", diff --git a/woo-nfe.php b/woo-nfe.php index ba7cca0..fab0998 100644 --- a/woo-nfe.php +++ b/woo-nfe.php @@ -11,7 +11,7 @@ * Plugin Name: WooCommerce NFe * Plugin URI: https://github.com/nfe/woo-nfe * Description: WooCommerce extension for the NFe API - * Version: 1.2.6 + * Version: 1.2.7 * Author: NFe.io * Author URI: https://nfe.io * Developer: Project contributors @@ -21,7 +21,7 @@ * Network: false * * WC requires at least: 3.3.5 - * WC tested up to: 3.3.5 + * WC tested up to: 3.4.3 * * Copyright: © 2018 NFe.io * License: GNU General Public License v3.0