From 690312dd8733bc9561590e5e39e620a40914c819 Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sat, 12 May 2018 07:28:54 +0000 Subject: [PATCH 1/4] Revert this commit 1ad14ee9b898412432cd75dee7bc6b802d0ceb0a. Wrong approach --- inc/class-wooviet-vnd-paypal-standard.php | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/inc/class-wooviet-vnd-paypal-standard.php b/inc/class-wooviet-vnd-paypal-standard.php index 74f9861..a515164 100644 --- a/inc/class-wooviet-vnd-paypal-standard.php +++ b/inc/class-wooviet-vnd-paypal-standard.php @@ -43,9 +43,6 @@ class WooViet_VND_PayPal_Standard { // Add the exchange rate info for this gateway in the checkout page before proceeding in the PayPal pages add_filter( 'option_woocommerce_paypal_settings', array( $this, 'add_exchange_rate_info' ), 11 ); - - // Match currency of Paypal with local order - add_action( 'valid-paypal-standard-ipn-request', array( $this, 'match_currency_order' ), 10 ); } /** @@ -110,18 +107,4 @@ class WooViet_VND_PayPal_Standard { return $value; } - /* - * Match response currency from Paypal IPN with the order - * - * Topic https://wordpress.org/support/topic/loi-order-bi-on-hold/ - * - * @author Longkt - * @since 1.4 - */ - public function match_currency_order($posted) { - if($posted['mc_currency']) { - $posted['mc_currency'] = $order->get_currency(); - } - } - } \ No newline at end of file From 12649806c3012835410bb27b964ec9fea6cc08f6 Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sat, 12 May 2018 09:48:47 +0000 Subject: [PATCH 2/4] Fix fatal error when handling PayPal IPN #56 --- inc/class-wooviet-vnd-paypal-standard.php | 84 +++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/inc/class-wooviet-vnd-paypal-standard.php b/inc/class-wooviet-vnd-paypal-standard.php index a515164..c87d277 100644 --- a/inc/class-wooviet-vnd-paypal-standard.php +++ b/inc/class-wooviet-vnd-paypal-standard.php @@ -25,6 +25,8 @@ class WooViet_VND_PayPal_Standard { */ protected $paypal_currency = 'USD'; + //@todo - declare two vars + /** * WooViet_VND_PayPal_Standard constructor. * @@ -43,6 +45,13 @@ class WooViet_VND_PayPal_Standard { // Add the exchange rate info for this gateway in the checkout page before proceeding in the PayPal pages add_filter( 'option_woocommerce_paypal_settings', array( $this, 'add_exchange_rate_info' ), 11 ); + + // Match currency and amount between Paypal and WC Order + add_action( 'valid-paypal-standard-ipn-request', array( $this, 'match_order_currency_and_amount' ), 5 ); + + // Restore currency and amount for WC Order + add_action( 'valid-paypal-standard-ipn-request', array( $this, 'restore_order_currency_and_amount' ), 15 ); + } /** @@ -107,4 +116,79 @@ class WooViet_VND_PayPal_Standard { return $value; } + /* + * Match currency and amount from Paypal IPN with the order + * + * Topic https://wordpress.org/support/topic/loi-order-bi-on-hold/ + * + * @author htdat + * @since 1.4.3 + */ + public function match_order_currency_and_amount($posted) { + + $order = ! empty( $posted['custom'] ) ? $this->get_paypal_order( $posted['custom'] ) : false; + + if ( $order ) { + $this->original_order_currency = $order->get_currency(); + $this->original_order_total = $order->get_total(); + + $order->set_currency( $posted['mc_currency'] ); + $order->set_total( $posted['mc_gross'] ); + + $order->save(); + } + + } + + /* + * Restore currency and amount of the order after the 'match_order_currency_and_amount' action + * + * @author htdat + * @since 1.4.3 + */ + public function restore_order_currency_and_amount($posted) { + + $order = ! empty( $posted['custom'] ) ? $this->get_paypal_order( $posted['custom'] ) : false; + + if ( $order ) { + + $order->set_currency( $this->original_order_currency ); + $order->set_total( $this->original_order_total ); + + $order->save(); + } + + } + + + /** + * @see Grab this code from - can not call it directly https://github.com/woocommerce/woocommerce/blob/f5c2f89af6a9421af8edc2a4aa20d372e5be40f8/includes/gateways/paypal/includes/class-wc-gateway-paypal-response.php#L30 + * + * @since 1.4.3 + * @author htdat + */ + protected function get_paypal_order( $raw_custom ) { + // We have the data in the correct format, so get the order. + $custom = json_decode( $raw_custom ); + if ( $custom && is_object( $custom ) ) { + $order_id = $custom->order_id; + $order_key = $custom->order_key; + } else { + // Nothing was found. + WC_Gateway_Paypal::log( 'Order ID and key were not found in "custom".', 'error' ); + return false; + } + $order = wc_get_order( $order_id ); + if ( ! $order ) { + // We have an invalid $order_id, probably because invoice_prefix has changed. + $order_id = wc_get_order_id_by_order_key( $order_key ); + $order = wc_get_order( $order_id ); + } + if ( ! $order || $order->get_order_key() !== $order_key ) { + WC_Gateway_Paypal::log( 'Order Keys do not match.', 'error' ); + return false; + } + return $order; + } + } \ No newline at end of file From 832d8ea491b10e36612e04b34109f7dc05ea9c0a Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sat, 12 May 2018 20:04:29 +0700 Subject: [PATCH 3/4] Add the development version 1.4.3 --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 803cb49..1888011 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: OnePay WooCommerce, OnePay Vietnam, WooCommerce Vietnam, vietnam, vietname Requires at least: 4.3 Tested up to: 4.9.5 Requires PHP: 5.6 -Stable tag: 1.4.2 +Stable tag: 1.4.3-dev License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html From 975a41f8076d38dd4c961168aeb9bf0b6e99a923 Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Tue, 31 Jul 2018 13:05:41 +0700 Subject: [PATCH 4/4] Prepare for the release of 1.4.3 #53 --- readme.md | 9 +++++++-- readme.txt | 18 +----------------- woo-viet.php | 2 +- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/readme.md b/readme.md index 59a46e9..6d091af 100644 --- a/readme.md +++ b/readme.md @@ -8,11 +8,16 @@ Xem phiên bản tiếng Việt tại đây https://vi.wordpress.org/plugins/woo ## Changelog -### 1.4.2 - 2018.04.26 = +### 1.4.3 - 2018.07.31 + +* Fix fatal error when handling PayPal IPN #56 +* Other small improvements #53 + +### 1.4.2 - 2018.04.26 * Fix the fatal error when WooCommerce PayPal Express Checkout Gateway is not active. -### 1.4.1 - 2018.04.26 = +### 1.4.1 - 2018.04.26 * Fix the SVN command, missing some files on WP.org repo. diff --git a/readme.txt b/readme.txt index 1888011..b411e7d 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: OnePay WooCommerce, OnePay Vietnam, WooCommerce Vietnam, vietnam, vietname Requires at least: 4.3 Tested up to: 4.9.5 Requires PHP: 5.6 -Stable tag: 1.4.3-dev +Stable tag: 1.4.3 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -73,22 +73,6 @@ Follow these steps to install and use the plugin: == Changelog == -= 1.4.2 - 2018.04.26 = - -* Fix the fatal error when WooCommerce PayPal Express Checkout Gateway is not active. - -= 1.4.1 - 2018.04.26 = - -* Fix the SVN command, missing some files on WP.org repo. - -= 1.4 - 2018.04.24 = - -* Fix the on-hold order issue with PayPal Standard. -* Fix the issue in OnePay Domestic gateway when users cancel payment. -* Add enhancement: arrange the address fields to the Vietnam standard: Country - Province - District - Address. -* Add supporting VND for [the PayPal Express Checkout gateway](https://docs.woocommerce.com/document/paypal-express-checkout/). -* Add "Settings" link in the Plugins list page when the plugin is active. - See all change logs on [GitHub repo](https://github.com/htdat/woo-viet#changelog). == Upgrade Notice == diff --git a/woo-viet.php b/woo-viet.php index 30e7dac..667056b 100644 --- a/woo-viet.php +++ b/woo-viet.php @@ -7,7 +7,7 @@ * Author URI: https://profiles.wordpress.org/htdat * Text Domain: woo-viet * Domain Path: /languages - * Version: 1.4.2 + * Version: 1.4.3 * * WC requires at least: 2.6 * WC tested up to: 2.3