Skip to content

Commit

Permalink
Merge pull request #4 from dingo-d/develop
Browse files Browse the repository at this point in the history
Update to version 1.5
  • Loading branch information
dingo-d authored Mar 1, 2018
2 parents a4e868d + 281bb17 commit aa100ea
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 22 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[![GitHub tag](https://img.shields.io/github/tag/dingo-d/woo-solo-api.svg)](https://github.com/dingo-d/woo-solo-api)

# Woo Solo Api

**Contributors**: dingo_bastard
**Tags**: woocommerce, api, solo api, solo, api integration, shop, payment, woo
**Requires at least**: 4.4
**Requires PHP**: 5.6
**Tested up to**: 4.9.4
**Stable tag**: 1.4
**Stable tag**: 1.5
**WC requires at least**: 3.0.0
**WC tested up to**: 3.3.3
**License**: GPLv2 or later
Expand Down Expand Up @@ -59,6 +61,11 @@ Be sure you have WooCommerce plugin installed first, otherwise you'll get an err

## Changelog

### 1.5

* Fixed the currency rate to pull it from the official hnb site
* Set the transient validity to 6 hours so every 6 hours it will expire and be created again

### 1.4

* Added automatic conversion rate from Croatian National Bank (https://www.hnb.hr/temeljne-funkcije/monetarna-politika/tecajna-lista/tecajna-lista)
Expand Down Expand Up @@ -91,6 +98,10 @@ Be sure you have WooCommerce plugin installed first, otherwise you'll get an err

## Additional notes

The 1.5 update fixed the currency rate. I parsed the results from https://www.hnb.hr/tecajn/htecajn.htm and created my own currency rate array. I also tested it with included taxes and it seems to be working ok. If for any reason the taxes are not being calculated or pulled in the solo api, there must be some third party plugin that is messing stuff up. Be mindful of that.

----

The 1.4 update fixed a lot of issues with the taxes, and tax rates. Although this has been fixed, the taxes probably wont't be picked up by the SOLO API if you set the option in the WooCommerce to include taxes in the price of the product. This is why you should separate the two. Also when creating a shipping tax class, be sure to create it as aseparate class, and leave the standard tax class for the product. So for instance the product will have a standard tax of 5%, and the shipping can have a separate class with tax rate of 25% (be sure to tick the shipping checkbox in this class).
The including prices will be fixed in the next update.

Expand Down
13 changes: 12 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: woocommerce, api, solo api, solo, api integration, shop, payment, woo
Requires at least: 4.4
Requires PHP: 5.6
Tested up to: 4.9.4
Stable tag: 1.4
Stable tag: 1.5
WC requires at least: 3.0.0
WC tested up to: 3.3.3
License: GPLv2 or later
Expand Down Expand Up @@ -65,12 +65,19 @@ Be sure you have WooCommerce plugin installed first, otherwise you'll get an err

== Changelog ==

= 1.5 =

* Fixed the currency rate to pull it from the official hnb site
* Set the transient validity to 6 hours so every 6 hours it will expire and be created again

= 1.4 =

* Added automatic conversion rate from Croatian National Bank (https://www.hnb.hr/temeljne-funkcije/monetarna-politika/tecajna-lista/tecajna-lista)
* Add a fix for duplicated orders - you can now choose if you want to make SOLO API call on the checkout or when changing order status manually
* Fix for taxes rounding error on shipping

= 1.3 =

* Add additional debug methods
* Code sniffer fixes
* Add tax check - tax rate can be separate for shipping and for items, and are handled by WooCommerce
Expand All @@ -95,6 +102,10 @@ Be sure you have WooCommerce plugin installed first, otherwise you'll get an err

== Additional notes ==

The 1.5 update fixed the currency rate. I parsed the results from https://www.hnb.hr/tecajn/htecajn.htm and created my own currency rate array. I also tested it with included taxes and it seems to be working ok. If for any reason the taxes are not being calculated or pulled in the solo api, there must be some third party plugin that is messing stuff up. Be mindful of that.

----

The 1.4 update fixed a lot of issues with the taxes, and tax rates. Although this has been fixed, the taxes probably wont't be picked up by the SOLO API if you set the option in the WooCommerce to include taxes in the price of the product. This is why you should separate the two. Also when creating a shipping tax class, be sure to create it as aseparate class, and leave the standard tax class for the product. So for instance the product will have a standard tax of 5%, and the shipping can have a separate class with tax rate of 25% (be sure to tick the shipping checkbox in this class).
The including prices will be fixed in the next update.

Expand Down
36 changes: 26 additions & 10 deletions admin/class-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* The plugin helpers class.
*
* @link https://madebydenis.com
* @since 1.5.0 Change hnb API to an official one.
* @since 1.3.0
*
* @package Woo_Solo_Api\Admin
Expand All @@ -22,10 +23,10 @@ class Helpers {
/**
* Returns the Croatian exchange rates
*
* The link from which the exchange rates are pulled from
* http://hnbex.eu/api/v1/rates/daily/, is not an official API
* from HNB, but they are pulling the rates from the official
* site.
* @link https://www.hnb.hr/tecajn/htecajn.htm
*
* @since 1.5.0 Change link for the currency fetch.
* @since 1.3.0
*
* @return array Exchange rates.
*/
Expand All @@ -34,17 +35,32 @@ public function get_exchange_rates() {
$currency_rates = get_transient( 'exchange_rate_transient' ); // Get transient.

if ( false === $currency_rates ) { // If no valid transient exists, run this.
$currency_api_url = 'http://hnbex.eu/api/v1/rates/daily/';
$currency_remote = wp_remote_get( $currency_api_url );
$url = 'https://www.hnb.hr/tecajn/htecajn.htm';

$headers = get_headers( $url );
$status = substr( $headers[0], 9, 3 );

// Is the API up?
if ( ! 200 === wp_remote_retrieve_response_code( $currency_remote ) ) {
// Is the link up?
if ( $status !== '200' ) {
return false;
}

$currency_rates = json_decode( wp_remote_retrieve_body( $currency_remote ), true );
$contents = file_get_contents( $url );

$array = explode( "\n", $contents );
unset( $array[0] );
$array = array_values( $array );

$currency_rates = [];

foreach ( $array as $arr_key => $arr_value ) {
$single_rate = array_values( array_filter( explode( ' ', $arr_value ) ) );
$currency_name = preg_replace( '/[^a-zA-Z]+/', '', $single_rate[0] );

$currency_rates[ $currency_name ] = $single_rate[2];
}

set_transient( 'exchange_rate_transient', $currency_rates, 1 * DAY_IN_SECONDS );
set_transient( 'exchange_rate_transient', $currency_rates, 6 * HOUR_IN_SECONDS );
}

// Are the results in an array?
Expand Down
8 changes: 2 additions & 6 deletions admin/class-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,10 @@ public function execute_solo_api_call( $order ) {
$api_rates = $this->helper->get_exchange_rates();
$currency = $currency_helper[ $solo_api_currency ];

$currency_rate = array_values( array_filter( array_map( function( $el ) use ( $currency ) {
if ( $el['currency_code'] === $currency ) {
return $el['median_rate'];
}
}, $api_rates ) ) );
$currency_rate = $api_rates[ $currency ];

if ( ! empty( $currency_rate ) ) {
$num = (float) str_replace( ',', '.', $currency_rate[0] );
$num = (float) str_replace( ',', '.', $currency_rate );
$post_url .= '&tecaj=' . str_replace( '.', ',', round( $num, 6 ) );

$customer_note .= "\n" . sprintf( '%1$s (1 %2$s = %3$s HRK)',
Expand Down
6 changes: 5 additions & 1 deletion includes/class-woo-solo-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct() {
if ( defined( 'SAWI_PLUGIN_VERSION' ) ) {
$this->version = SAWI_PLUGIN_VERSION;
} else {
$this->version = '1.4';
$this->version = '1.5';
}

if ( defined( 'SAWI_PLUGIN_NAME' ) ) {
Expand All @@ -77,6 +77,7 @@ public function __construct() {
$this->load_dependencies();
$this->set_locale();
$this->define_admin_hooks();

}
/**
* Load the required dependencies for this plugin.
Expand Down Expand Up @@ -116,9 +117,12 @@ private function set_locale() {
private function define_admin_hooks() {
$plugin_admin = new Admin\Admin( $this->get_plugin_name(), $this->get_version() );
$api_request = new Admin\Request();
$api_helpers = new Admin\Helpers();

$this->loader->add_action( 'woocommerce_email_order_details', $api_request, 'solo_api_send_api_request', 15, 4 );

$this->loader->add_action( 'init', $api_helpers, 'get_exchange_rates' );

$this->loader->add_filter( 'post_mime_types', $plugin_admin, 'add_pdf_post_mime_type' );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
Expand Down
6 changes: 3 additions & 3 deletions woo-solo-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* @package Woo_Solo_Api
*
* Plugin Name: Woo Solo Api
* Plugin URI: https://madebydenis.com/woo-solo-api
* Plugin URI: https://wordpress.org/plugins/woo-solo-api/
* Description: This plugin provides integration of the SOLO API service with WooCommerce.
* Version: 1.4
* Version: 1.5
* Author: Denis Žoljom
* Author URI: https://madebydenis.com
* License: GPL-2.0+
Expand All @@ -30,7 +30,7 @@
die;
}

define( 'SAWI_PLUGIN_VERSION', '1.4' );
define( 'SAWI_PLUGIN_VERSION', '1.5' );
define( 'SAWI_PLUGIN_NAME', 'woo-solo-api' );

// Include the autoloader so we can dynamically include the rest of the classes.
Expand Down

0 comments on commit aa100ea

Please sign in to comment.