Skip to content

Commit

Permalink
Merge pull request #57 from nfe/dev
Browse files Browse the repository at this point in the history
Versão 1.2.7
  • Loading branch information
gblmarquez authored Jul 9, 2018
2 parents 3a09cc7 + 40b2dad commit 0cfc9f2
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 112 deletions.
45 changes: 43 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,52 @@
# 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

1. Vá ao menu *Plugins* e clique *Adicionar Novo*.
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.
25 changes: 12 additions & 13 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
1. Go the *Plugins* menu and click *Add New*.
2. Search for *WooCommerce NFe*.
3. Click *Install Now*.

== Changelog ==

= 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
Expand Down Expand Up @@ -67,3 +63,6 @@ Thanks in advance for your help on any translation efforts!

= 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.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
{
"name" : "Renato Alves",
"homepage": "http://ralv.es/"
"homepage": "https://ralv.es/"
}
],
"support": {
Expand Down
90 changes: 48 additions & 42 deletions includes/admin/class-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -701,7 +707,7 @@ protected function country_iso_codes() {
'VNM' => 'VN', // Vietnam
'YEM' => 'YE', // Yemen
'ZAF' => 'ZA', // South Africa
'ZWE' => 'ZW', // Zimbabwe
'ZWE' => 'ZW', // Zimbabwe.
);
}

Expand Down
50 changes: 24 additions & 26 deletions includes/admin/class-emails.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
<?php

// Exit if accessed directly
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

if ( ! class_exists('WC_NFe_Emails') ) :
/**
* WooCommerce NFe Email Class
*
* @author NFe.io
* @package WooCommerce_NFe/Class/WC_NFe_Emails
* @version 1.0.1
*/
class WC_NFe_Emails {

/**
* WooCommerce NFe Email Class
*
* @author NFe.io
* @package WooCommerce_NFe/Class/WC_NFe_Emails
* @version 1.0.1
* Bootstraps the class and hooks required actions & filters.
*/
class WC_NFe_Emails {

/**
* Bootstraps the class and hooks required actions & filters.
*/
public static function init() {
add_action( 'woocommerce_email_classes', __CLASS__ . '::add_emails', 10, 1 );
}
public static function init() {
add_action( 'woocommerce_email_classes', __CLASS__ . '::add_emails', 10, 1 );
}

/**
* Add NFe's email classes.
*/
public static function add_emails( $email_classes ) {
require_once( 'emails/class-nfe-email-receipt-issued.php' );
/**
* Add NFe's email classes.
*
* @param array $email_classes Email classes.
*/
public static function add_emails( $email_classes ) {
require_once( 'emails/class-nfe-email-receipt-issued.php' );

$email_classes['WC_NFe_Email_Receipt_Issued'] = new WC_NFe_Email_Receipt_Issued();
$email_classes['WC_NFe_Email_Receipt_Issued'] = new WC_NFe_Email_Receipt_Issued();

return $email_classes;
}
return $email_classes;
}
}

WC_NFe_Emails::init();

endif;
WC_NFe_Emails::init();
10 changes: 5 additions & 5 deletions includes/admin/emails/class-nfe-email-receipt-issued.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

// Exit if accessed directly.
// Exit if accessed directly..
defined( 'ABSPATH' ) || exit;

/**
Expand Down Expand Up @@ -35,10 +35,10 @@ public function __construct() {
$this->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();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nfe",
"title": "WooCommerce NFe",
"version": "1.2.4",
"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",
Expand Down
5 changes: 2 additions & 3 deletions templates/emails/nfe-receipt-issued.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* The Template for displaying NFe issued
*
Expand All @@ -11,15 +10,15 @@
* @version 1.0.1
*/

// Exit if accessed directly
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

/**
* @hooked WC_Emails::email_header() Output the email header
*/
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>

<p><?php _e( 'NFe issued successfully. Here follows an email for your backing.', 'woo-nfe' ); ?></p>
<p><?php esc_html_e( 'NFe issued successfully. Here follows an email for your backing.', 'woo-nfe' ); ?></p>

<?php
/**
Expand Down
3 changes: 1 addition & 2 deletions templates/emails/plain/nfe-receipt-issued.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* The Template for displaying NFe issued (plain text)
*
Expand All @@ -11,7 +10,7 @@
* @version 1.0.0
*/

// Exit if accessed directly
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

echo "= " . $email_heading . " =\n\n";
Expand Down
1 change: 0 additions & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* PHPUnit bootstrap file
*
Expand Down
Loading

0 comments on commit 0cfc9f2

Please sign in to comment.