From f01d45bb3c784d00bd4858f25b6c8e931a1a641b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=BDoljom?= Date: Sat, 28 Nov 2020 10:47:40 +0100 Subject: [PATCH 1/7] Remove shipping from all the variables, fix shipping tax calculation The shipping does not concern us really, so no need to pull any fields from there. Shipping was a bit changed so it didn't pick anything up and reported 0 tax on taxable shipping. This should fix it. --- src/Request/SoloApiRequest.php | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/src/Request/SoloApiRequest.php b/src/Request/SoloApiRequest.php index b4618a2..9597e82 100644 --- a/src/Request/SoloApiRequest.php +++ b/src/Request/SoloApiRequest.php @@ -99,17 +99,10 @@ public function executeApiCall($order): void $orderData = $order->get_data(); // The Order data. - // Check if billing or shipping. - $field = 'shipping'; - - if (!empty($orderData['billing']['first_name'])) { - $field = 'billing'; - } - // The bill data (invoice or offer) must be from billing fields! $firstName = $orderData['billing']['first_name'] ?? ''; $lastName = $orderData['billing']['last_name'] ?? ''; - $companyName = $orderData['billing']['billing_company'] ?? ''; // Used for R1. + $companyName = $orderData['billing']['company'] ?? ''; // Used for R1. $address1 = $orderData['billing']['address_1'] ?? ''; $address2 = $orderData['billing']['address_2'] ?? ''; $city = $orderData['billing']['city'] ?? ''; @@ -123,29 +116,19 @@ public function executeApiCall($order): void foreach ($metaData as $data => $metaValue) { $data = $metaValue->get_data(); - if ($data['key'] === '_shipping_pin_number') { + if ($data['key'] === '_billing_pin_number') { $pinNumber = $data['value'] ?? ''; } - if ($data['key'] === '_shipping_iban_number') { + if ($data['key'] === '_billing_iban_number') { $ibanNumber = $data['value'] ?? ''; } - - if ($field === 'billing') { - if ($data['key'] === '_billing_pin_number') { - $pinNumber = $data['value'] ?? ''; - } - - if ($data['key'] === '_billing_iban_number') { - $ibanNumber = $data['value'] ?? ''; - } - } } $orderBuyer = "$firstName $lastName"; // If the invoice is R1 the company name is required and used instead of first name and last name. - if (get_option('solo_api_invoice_type') !== '2') { + if (get_option('solo_api_invoice_type') === '2') { $orderBuyer = $companyName; } @@ -263,9 +246,10 @@ public function executeApiCall($order): void $shippingItems = $order->get_items('shipping'); foreach ($shippingItems as $shippingObject) { - $shippingTaxRates = array_values(WC_Tax::get_base_tax_rates($shippingObject->get_tax_class())); + $shippingTaxRates = array_values(WC_Tax::get_base_tax_rates()); } + // We're fetching the first value always. $shippingTaxRate = !empty($shippingTaxRates) ? (float)$shippingTaxRates[0]['rate'] : 0; $shippingPrice = number_format($totalShipping, 2, ',', '.'); @@ -608,6 +592,7 @@ private function prepareRequestData(array $requestBody): string */ private function detectLanguage(): string { + error_log(print_r(get_option('solo_api_languages'), true)); return get_option('solo_api_languages'); } } From f3e9af259bb085b370c76e1ea8150c08023a06ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=BDoljom?= Date: Sat, 28 Nov 2020 10:48:14 +0100 Subject: [PATCH 2/7] Fix the defaults in the settings --- src/Settings/PluginSettings.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Settings/PluginSettings.php b/src/Settings/PluginSettings.php index 6a29803..7e962c9 100644 --- a/src/Settings/PluginSettings.php +++ b/src/Settings/PluginSettings.php @@ -87,7 +87,7 @@ public function registerPluginSettings(): void esc_html__('Language of the bill or the invoice', 'woo-solo-api'), 'sanitize_text_field', true, - '' + '1' ) ); @@ -207,7 +207,7 @@ public function registerPluginSettings(): void esc_html__('Specify the due date on the bill or the invoice', 'woo-solo-api'), 'sanitize_text_field', true, - '' + '1' ) ); @@ -243,7 +243,7 @@ public function registerPluginSettings(): void esc_html__('When to send the PDF - on checkout or order confirmation', 'woo-solo-api'), 'sanitize_text_field', true, - '' + 'checkout' ) ); From ed486ec14363bb1568eb2aa8ddec97b38444ae1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=BDoljom?= Date: Sat, 28 Nov 2020 10:51:00 +0100 Subject: [PATCH 3/7] Remove error log --- src/Request/SoloApiRequest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Request/SoloApiRequest.php b/src/Request/SoloApiRequest.php index 9597e82..432c529 100644 --- a/src/Request/SoloApiRequest.php +++ b/src/Request/SoloApiRequest.php @@ -592,7 +592,6 @@ private function prepareRequestData(array $requestBody): string */ private function detectLanguage(): string { - error_log(print_r(get_option('solo_api_languages'), true)); return get_option('solo_api_languages'); } } From de01bbb60175ba1052ef95e60660a86b1ee51da3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=BDoljom?= Date: Sat, 28 Nov 2020 11:15:46 +0100 Subject: [PATCH 4/7] Raise the priority of the on completed hook --- src/ECommerce/WooCommerce/MakeApiRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ECommerce/WooCommerce/MakeApiRequest.php b/src/ECommerce/WooCommerce/MakeApiRequest.php index 185fae9..6aec9ba 100644 --- a/src/ECommerce/WooCommerce/MakeApiRequest.php +++ b/src/ECommerce/WooCommerce/MakeApiRequest.php @@ -64,7 +64,7 @@ public function __construct(SoloOrdersTable $ordersTable, ApiRequest $soloReques public function register(): void { add_action('woocommerce_email_order_details', [$this, 'sendApiRequestOnCheckout'], 15, 4); - add_action('woocommerce_order_status_completed', [$this, 'sendApiRequestOnOrderCompleted'], 10, 1); + add_action('woocommerce_order_status_completed', [$this, 'sendApiRequestOnOrderCompleted'], 30, 1); } /** From e7bf27f2be3c598885ae17d4423b12cb2d3d8ae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=BDoljom?= Date: Sat, 28 Nov 2020 11:16:53 +0100 Subject: [PATCH 5/7] Clear error message in the case of manual resending Manual resending towards api should be available, but this is for 2.1 version or later. --- src/Request/SoloApiRequest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Request/SoloApiRequest.php b/src/Request/SoloApiRequest.php index 432c529..2c0b19f 100644 --- a/src/Request/SoloApiRequest.php +++ b/src/Request/SoloApiRequest.php @@ -412,6 +412,14 @@ public function executeApiCall($order): void * Update - YES; */ SoloOrdersTable::updateOrdersTable($orderId, $soloOrderId, true, false, true); + + /** + * Clear the previous errors + * + * If curl error happened, for whatever reason, and you try to resend the order manually + * the error should be removed if the API call was successful. + */ + SoloOrdersTable::addApiResponseError($orderId, ''); // Send mail to the customer with the PDF of the invoice. $sendPdf = get_option('solo_api_send_pdf'); From 4849b0e47fc463d1050fab4579dde09c8d3483bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=BDoljom?= Date: Sat, 28 Nov 2020 11:19:19 +0100 Subject: [PATCH 6/7] phpcs fix --- src/Request/SoloApiRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Request/SoloApiRequest.php b/src/Request/SoloApiRequest.php index 2c0b19f..ab7d777 100644 --- a/src/Request/SoloApiRequest.php +++ b/src/Request/SoloApiRequest.php @@ -412,7 +412,7 @@ public function executeApiCall($order): void * Update - YES; */ SoloOrdersTable::updateOrdersTable($orderId, $soloOrderId, true, false, true); - + /** * Clear the previous errors * From 2e4f8960c8335dfe5ee5ba3d5c94b8c4bf44a50b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C5=BDoljom?= Date: Sat, 28 Nov 2020 11:28:12 +0100 Subject: [PATCH 7/7] Version bump --- CHANGELOG.md | 19 ++++++++++++++++++- README.md | 2 +- README.txt | 20 +++++++++++++++++++- woo-solo-api.php | 2 +- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 970090d..be99060 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,11 +13,28 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a _No documentation available about unreleased changes as of yet._ +## [2.0.4] - 2020-11-28 + +### Added + +* Clear error log message if order is manually triggered and succeeds. + +### Changed + +* Priority changed on the on completed WooCommerce hook. + +### Fixed + +* Remove shipping from all the variables, fix shipping tax calculation + *The shipping does not concern us really, so no need to pull any fields from there. + * Shipping was a bit changed, so it didn't pick anything up and reported 0 tax on taxable shipping. +* Fix the defaults in the settings (languages, checkout settings) in PHP. + ## [2.0.3] - 2020-11-25 ### Fixed -* * Add a default fallback on save in case a settings is undefined or null in settings +* Add a default fallback on save in case a settings is undefined or null in settings ## [2.0.2] - 2020-11-24 diff --git a/README.md b/README.md index a20646e..874372f 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ **Requires at least**: 5.1 **Requires PHP**: 7.3 **Tested up to**: 5.5 -**Stable tag**: 2.0.3 +**Stable tag**: 2.0.4 **WC requires at least**: 4.0.0 **WC tested up to**: 4.7.0 **License**: MIT diff --git a/README.txt b/README.txt index c7caf3a..f2f2758 100755 --- a/README.txt +++ b/README.txt @@ -4,7 +4,7 @@ Tags: woocommerce, api, solo api, solo, api integration, shop, payment, woo Requires at least: 5.2 Requires PHP: 7.3 Tested up to: 5.5 -Stable tag: 2.0.3 +Stable tag: 2.0.4 WC requires at least: 4.0.0 WC tested up to: 4.7.0 License: MIT @@ -66,6 +66,24 @@ Be sure you have WooCommerce plugin installed first, otherwise you'll get an err == Changelog == += 2.0.4 = +Release Date: November 28th, 2020 + +Added: + +* Clear error log message if order is manually triggered and succeeds. + +Changed: + +* Priority changed on the on completed WooCommerce hook. + +Fixed: + +* Remove shipping from all the variables, fix shipping tax calculation + *The shipping does not concern us really, so no need to pull any fields from there. + * Shipping was a bit changed, so it didn't pick anything up and reported 0 tax on taxable shipping. +* Fix the defaults in the settings (languages, checkout settings) in PHP. + = 2.0.3 = Release Date: November 25th, 2020 diff --git a/woo-solo-api.php b/woo-solo-api.php index feac7b4..c614916 100755 --- a/woo-solo-api.php +++ b/woo-solo-api.php @@ -10,7 +10,7 @@ * Plugin Name: Woo Solo Api * Plugin URI: https://madebydenis.com/woo-solo-api * Description: This plugin provides integration of the SOLO API service with WooCommerce. - * Version: 2.0.3 + * Version: 2.0.4 * Author: Denis Žoljom * Author URI: https://madebydenis.com * License: MIT