Skip to content

Commit a41866d

Browse files
authored
Merge pull request #57 from htdat/1.4.3-dev
Merge 1.4.3
2 parents 98d2a83 + 975a41f commit a41866d

File tree

4 files changed

+85
-29
lines changed

4 files changed

+85
-29
lines changed

inc/class-wooviet-vnd-paypal-standard.php

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class WooViet_VND_PayPal_Standard {
2525
*/
2626
protected $paypal_currency = 'USD';
2727

28+
//@todo - declare two vars
29+
2830
/**
2931
* WooViet_VND_PayPal_Standard constructor.
3032
*
@@ -44,8 +46,12 @@ public function __construct( $exchange_rate_to_vnd = 22770, $paypal_currency ) {
4446
// Add the exchange rate info for this gateway in the checkout page before proceeding in the PayPal pages
4547
add_filter( 'option_woocommerce_paypal_settings', array( $this, 'add_exchange_rate_info' ), 11 );
4648

47-
// Match currency of Paypal with local order
48-
add_action( 'valid-paypal-standard-ipn-request', array( $this, 'match_currency_order' ), 10 );
49+
// Match currency and amount between Paypal and WC Order
50+
add_action( 'valid-paypal-standard-ipn-request', array( $this, 'match_order_currency_and_amount' ), 5 );
51+
52+
// Restore currency and amount for WC Order
53+
add_action( 'valid-paypal-standard-ipn-request', array( $this, 'restore_order_currency_and_amount' ), 15 );
54+
4955
}
5056

5157
/**
@@ -111,17 +117,78 @@ public function add_exchange_rate_info( $value ) {
111117
}
112118

113119
/*
114-
* Match response currency from Paypal IPN with the order
120+
* Match currency and amount from Paypal IPN with the order
115121
*
116122
* Topic https://wordpress.org/support/topic/loi-order-bi-on-hold/
117123
*
118-
* @author Longkt
119-
* @since 1.4
124+
* @author htdat
125+
* @since 1.4.3
126+
*/
127+
public function match_order_currency_and_amount($posted) {
128+
129+
$order = ! empty( $posted['custom'] ) ? $this->get_paypal_order( $posted['custom'] ) : false;
130+
131+
if ( $order ) {
132+
$this->original_order_currency = $order->get_currency();
133+
$this->original_order_total = $order->get_total();
134+
135+
$order->set_currency( $posted['mc_currency'] );
136+
$order->set_total( $posted['mc_gross'] );
137+
138+
$order->save();
139+
}
140+
141+
}
142+
143+
/*
144+
* Restore currency and amount of the order after the 'match_order_currency_and_amount' action
145+
*
146+
* @author htdat
147+
* @since 1.4.3
120148
*/
121-
public function match_currency_order($posted) {
122-
if($posted['mc_currency']) {
123-
$posted['mc_currency'] = $order->get_currency();
124-
}
149+
public function restore_order_currency_and_amount($posted) {
150+
151+
$order = ! empty( $posted['custom'] ) ? $this->get_paypal_order( $posted['custom'] ) : false;
152+
153+
if ( $order ) {
154+
155+
$order->set_currency( $this->original_order_currency );
156+
$order->set_total( $this->original_order_total );
157+
158+
$order->save();
159+
}
160+
125161
}
126162

163+
164+
/**
165+
* @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
166+
*
167+
* @since 1.4.3
168+
* @author htdat
169+
*/
170+
protected function get_paypal_order( $raw_custom ) {
171+
// We have the data in the correct format, so get the order.
172+
$custom = json_decode( $raw_custom );
173+
if ( $custom && is_object( $custom ) ) {
174+
$order_id = $custom->order_id;
175+
$order_key = $custom->order_key;
176+
} else {
177+
// Nothing was found.
178+
WC_Gateway_Paypal::log( 'Order ID and key were not found in "custom".', 'error' );
179+
return false;
180+
}
181+
$order = wc_get_order( $order_id );
182+
if ( ! $order ) {
183+
// We have an invalid $order_id, probably because invoice_prefix has changed.
184+
$order_id = wc_get_order_id_by_order_key( $order_key );
185+
$order = wc_get_order( $order_id );
186+
}
187+
if ( ! $order || $order->get_order_key() !== $order_key ) {
188+
WC_Gateway_Paypal::log( 'Order Keys do not match.', 'error' );
189+
return false;
190+
}
191+
return $order;
192+
}
193+
127194
}

readme.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ Xem phiên bản tiếng Việt tại đây https://vi.wordpress.org/plugins/woo
88

99
## Changelog
1010

11-
### 1.4.2 - 2018.04.26 =
11+
### 1.4.3 - 2018.07.31
12+
13+
* Fix fatal error when handling PayPal IPN #56
14+
* Other small improvements #53
15+
16+
### 1.4.2 - 2018.04.26
1217

1318
* Fix the fatal error when WooCommerce PayPal Express Checkout Gateway is not active.
1419

15-
### 1.4.1 - 2018.04.26 =
20+
### 1.4.1 - 2018.04.26
1621

1722
* Fix the SVN command, missing some files on WP.org repo.
1823

readme.txt

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: OnePay WooCommerce, OnePay Vietnam, WooCommerce Vietnam, vietnam, vietname
44
Requires at least: 4.3
55
Tested up to: 4.9.5
66
Requires PHP: 5.6
7-
Stable tag: 1.4.2
7+
Stable tag: 1.4.3
88
License: GPLv2 or later
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1010

@@ -73,22 +73,6 @@ Follow these steps to install and use the plugin:
7373

7474
== Changelog ==
7575

76-
= 1.4.2 - 2018.04.26 =
77-
78-
* Fix the fatal error when WooCommerce PayPal Express Checkout Gateway is not active.
79-
80-
= 1.4.1 - 2018.04.26 =
81-
82-
* Fix the SVN command, missing some files on WP.org repo.
83-
84-
= 1.4 - 2018.04.24 =
85-
86-
* Fix the on-hold order issue with PayPal Standard.
87-
* Fix the issue in OnePay Domestic gateway when users cancel payment.
88-
* Add enhancement: arrange the address fields to the Vietnam standard: Country - Province - District - Address.
89-
* Add supporting VND for [the PayPal Express Checkout gateway](https://docs.woocommerce.com/document/paypal-express-checkout/).
90-
* Add "Settings" link in the Plugins list page when the plugin is active.
91-
9276
See all change logs on [GitHub repo](https://github.com/htdat/woo-viet#changelog).
9377

9478
== Upgrade Notice ==

woo-viet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Author URI: https://profiles.wordpress.org/htdat
88
* Text Domain: woo-viet
99
* Domain Path: /languages
10-
* Version: 1.4.2
10+
* Version: 1.4.3
1111
*
1212
* WC requires at least: 2.6
1313
* WC tested up to: 2.3

0 commit comments

Comments
 (0)