WooCommerce Square - Version 2.5.2

Version Description

  • 2021.07.21 =
  • Fix - Product and inventory data not being synced due to duplicate/orphaned product metadata in database. PR#625
  • Fix - Bypass SSL verification when checking background job processing eligibility. PR#624
  • Fix - Correctly apply taxes in the Order API request and report accurate percentages. PR#559
Download this release

Release Info

Developer automattic
Plugin Icon 128x128 WooCommerce Square
Version 2.5.2
Comparing to
See all releases

Code changes from version 2.5.1 to 2.5.2

composer.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "woocommerce/woocommerce-square",
3
+ "description": "WooCommerce Square",
4
+ "homepage": "https://woocommerce.com/products/woocommerce-square/",
5
+ "license": "GPL 3.0",
6
+ "minimum-stability": "dev",
7
+ "repositories": [
8
+ {
9
+ "type": "vcs",
10
+ "url": "https://github.com/skyverge/wc-plugin-framework"
11
+ }
12
+ ],
13
+ "require": {
14
+ "square/connect": "2.20190814.2",
15
+ "skyverge/wc-plugin-framework": "5.4.0",
16
+ "prospress/action-scheduler" : "2.2.0"
17
+ },
18
+ "require-dev": {
19
+ "woocommerce/woocommerce-sniffs": "0.1.0"
20
+ },
21
+ "scripts": {
22
+ "phpcs": [
23
+ "vendor/bin/phpcs"
24
+ ]
25
+ }
26
+ }
i18n/languages/woocommerce-square.pot CHANGED
@@ -2,10 +2,10 @@
2
  # This file is distributed under the GNU General Public License v3.0.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: WooCommerce Square 2.5.1\n"
6
  "Report-Msgid-Bugs-To: "
7
  "https://wordpress.org/support/plugin/woocommerce-square\n"
8
- "POT-Creation-Date: 2021-05-18 04:58:33+00:00\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=utf-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
@@ -433,14 +433,14 @@ msgstr ""
433
  msgid "The sync job has failed. Check sync records, or %s."
434
  msgstr ""
435
 
436
- #: includes/Gateway/API/Requests/Orders.php:88
437
  #: includes/Gateway/Digital_Wallet.php:416
438
  #: vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/apple-pay/class-sv-wc-payment-gateway-apple-pay.php:555
439
  msgid "Discount"
440
  msgstr ""
441
 
442
- #: includes/Gateway/API/Requests/Orders.php:297
443
- #: includes/Gateway/API/Requests/Orders.php:343
444
  msgid "Adjustment"
445
  msgstr ""
446
 
@@ -716,19 +716,19 @@ msgstr ""
716
  msgid " An error occurred, please try again or try an alternate form of payment."
717
  msgstr ""
718
 
719
- #: includes/Handlers/Background_Job.php:347
720
  msgid "Clear Square Sync"
721
  msgstr ""
722
 
723
- #: includes/Handlers/Background_Job.php:348
724
  msgid "Clear"
725
  msgstr ""
726
 
727
- #: includes/Handlers/Background_Job.php:349
728
  msgid "This tool will clear any ongoing Square product syncs."
729
  msgstr ""
730
 
731
- #: includes/Handlers/Background_Job.php:368
732
  msgid "Success! You can now sync your products."
733
  msgstr ""
734
 
@@ -1132,50 +1132,50 @@ msgstr ""
1132
  msgid "Product %s could not be updated in Square."
1133
  msgstr ""
1134
 
1135
- #: includes/Sync/Product_Import.php:560
1136
  #. translators: Placeholders: %1$s - Square item name, %2$s - Square item
1137
  #. variation name, %3$s - failure reason
1138
  msgid "Could not import \"%1$s - %2$s\" from Square. %3$s"
1139
  msgstr ""
1140
 
1141
- #: includes/Sync/Product_Import.php:605
1142
  #. translators: Placeholders: %1$s - Square item name, %2$s - failure reason
1143
  msgid "Could not import \"%1$s\" from Square. %2$s"
1144
  msgstr ""
1145
 
1146
- #: includes/Sync/Product_Import.php:634
1147
  msgid "Items with variable pricing cannot be imported."
1148
  msgstr ""
1149
 
1150
- #: includes/Sync/Product_Import.php:638
1151
  msgid "Variations with missing SKUs cannot be imported."
1152
  msgstr ""
1153
 
1154
- #: includes/Sync/Product_Import.php:731 includes/Sync/Product_Import.php:1007
1155
  msgid "The SKU already exists on another product"
1156
  msgstr ""
1157
 
1158
- #: includes/Sync/Product_Import.php:923
1159
  #. translators: Placeholders: %1$s - variation ID, %2$s - product name
1160
  msgid "Variation #%1$s of %2$s"
1161
  msgstr ""
1162
 
1163
- #: includes/Sync/Product_Import.php:1301
1164
  #. translators: Placeholders: %s - missing parameter name
1165
  msgid "Missing parameter %s"
1166
  msgstr ""
1167
 
1168
- #: includes/Sync/Product_Import.php:1307
1169
  #. translators: Placeholders: %s - comma separated list of valid product types
1170
  msgid "Invalid product type - the product type must be any of these: %s"
1171
  msgstr ""
1172
 
1173
- #: includes/Sync/Product_Import.php:1358
1174
  #. translators: Placeholders: %1$s - Square item name, %2$s - Failure reason
1175
  msgid "Could not update %1$s from Square. %2$s"
1176
  msgstr ""
1177
 
1178
- #: includes/Sync/Product_Import.php:1361
1179
  #. translators: Placeholders: %1$s - Square item name, %2$s - Failure reason
1180
  msgid "Could not import %1$s from Square. %2$s"
1181
  msgstr ""
@@ -1852,15 +1852,15 @@ msgstr ""
1852
  msgid "Docs"
1853
  msgstr ""
1854
 
1855
- #: vendor/skyverge/wc-plugin-framework/woocommerce/class-sv-wc-plugin.php:622
1856
  msgid "%1$s - A minimum of %2$s is required."
1857
  msgstr ""
1858
 
1859
- #: vendor/skyverge/wc-plugin-framework/woocommerce/class-sv-wc-plugin.php:631
1860
  msgid "Set as %1$s - %2$s is required."
1861
  msgstr ""
1862
 
1863
- #: vendor/skyverge/wc-plugin-framework/woocommerce/class-sv-wc-plugin.php:854
1864
  msgid "Configure"
1865
  msgstr ""
1866
 
2
  # This file is distributed under the GNU General Public License v3.0.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: WooCommerce Square 2.5.2\n"
6
  "Report-Msgid-Bugs-To: "
7
  "https://wordpress.org/support/plugin/woocommerce-square\n"
8
+ "POT-Creation-Date: 2021-07-21 05:31:33+00:00\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=utf-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
433
  msgid "The sync job has failed. Check sync records, or %s."
434
  msgstr ""
435
 
436
+ #: includes/Gateway/API/Requests/Orders.php:84
437
  #: includes/Gateway/Digital_Wallet.php:416
438
  #: vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/apple-pay/class-sv-wc-payment-gateway-apple-pay.php:555
439
  msgid "Discount"
440
  msgstr ""
441
 
442
+ #: includes/Gateway/API/Requests/Orders.php:302
443
+ #: includes/Gateway/API/Requests/Orders.php:348
444
  msgid "Adjustment"
445
  msgstr ""
446
 
716
  msgid " An error occurred, please try again or try an alternate form of payment."
717
  msgstr ""
718
 
719
+ #: includes/Handlers/Background_Job.php:344
720
  msgid "Clear Square Sync"
721
  msgstr ""
722
 
723
+ #: includes/Handlers/Background_Job.php:345
724
  msgid "Clear"
725
  msgstr ""
726
 
727
+ #: includes/Handlers/Background_Job.php:346
728
  msgid "This tool will clear any ongoing Square product syncs."
729
  msgstr ""
730
 
731
+ #: includes/Handlers/Background_Job.php:365
732
  msgid "Success! You can now sync your products."
733
  msgstr ""
734
 
1132
  msgid "Product %s could not be updated in Square."
1133
  msgstr ""
1134
 
1135
+ #: includes/Sync/Product_Import.php:563
1136
  #. translators: Placeholders: %1$s - Square item name, %2$s - Square item
1137
  #. variation name, %3$s - failure reason
1138
  msgid "Could not import \"%1$s - %2$s\" from Square. %3$s"
1139
  msgstr ""
1140
 
1141
+ #: includes/Sync/Product_Import.php:608
1142
  #. translators: Placeholders: %1$s - Square item name, %2$s - failure reason
1143
  msgid "Could not import \"%1$s\" from Square. %2$s"
1144
  msgstr ""
1145
 
1146
+ #: includes/Sync/Product_Import.php:637
1147
  msgid "Items with variable pricing cannot be imported."
1148
  msgstr ""
1149
 
1150
+ #: includes/Sync/Product_Import.php:641
1151
  msgid "Variations with missing SKUs cannot be imported."
1152
  msgstr ""
1153
 
1154
+ #: includes/Sync/Product_Import.php:734 includes/Sync/Product_Import.php:1011
1155
  msgid "The SKU already exists on another product"
1156
  msgstr ""
1157
 
1158
+ #: includes/Sync/Product_Import.php:926
1159
  #. translators: Placeholders: %1$s - variation ID, %2$s - product name
1160
  msgid "Variation #%1$s of %2$s"
1161
  msgstr ""
1162
 
1163
+ #: includes/Sync/Product_Import.php:1305
1164
  #. translators: Placeholders: %s - missing parameter name
1165
  msgid "Missing parameter %s"
1166
  msgstr ""
1167
 
1168
+ #: includes/Sync/Product_Import.php:1311
1169
  #. translators: Placeholders: %s - comma separated list of valid product types
1170
  msgid "Invalid product type - the product type must be any of these: %s"
1171
  msgstr ""
1172
 
1173
+ #: includes/Sync/Product_Import.php:1362
1174
  #. translators: Placeholders: %1$s - Square item name, %2$s - Failure reason
1175
  msgid "Could not update %1$s from Square. %2$s"
1176
  msgstr ""
1177
 
1178
+ #: includes/Sync/Product_Import.php:1365
1179
  #. translators: Placeholders: %1$s - Square item name, %2$s - Failure reason
1180
  msgid "Could not import %1$s from Square. %2$s"
1181
  msgstr ""
1852
  msgid "Docs"
1853
  msgstr ""
1854
 
1855
+ #: vendor/skyverge/wc-plugin-framework/woocommerce/class-sv-wc-plugin.php:623
1856
  msgid "%1$s - A minimum of %2$s is required."
1857
  msgstr ""
1858
 
1859
+ #: vendor/skyverge/wc-plugin-framework/woocommerce/class-sv-wc-plugin.php:632
1860
  msgid "Set as %1$s - %2$s is required."
1861
  msgstr ""
1862
 
1863
+ #: vendor/skyverge/wc-plugin-framework/woocommerce/class-sv-wc-plugin.php:855
1864
  msgid "Configure"
1865
  msgstr ""
1866
 
includes/Gateway/API/Requests/Orders.php CHANGED
@@ -15,10 +15,6 @@
15
  * Do not edit or add to this file if you wish to upgrade WooCommerce Square to newer
16
  * versions in the future. If you wish to customize WooCommerce Square for your
17
  * needs please refer to https://docs.woocommerce.com/document/woocommerce-square/
18
- *
19
- * @author WooCommerce
20
- * @copyright Copyright: (c) 2019, Automattic, Inc.
21
- * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
22
  */
23
 
24
  namespace WooCommerce\Square\Gateway\API\Requests;
@@ -68,6 +64,7 @@ class Orders extends API\Request {
68
 
69
  $order_model = new SquareModel\Order();
70
  $order_model->setReferenceId( $order->get_order_number() );
 
71
  if ( ! empty( $order->square_customer_id ) ) {
72
  $order_model->setCustomerId( $order->square_customer_id );
73
  }
@@ -75,9 +72,8 @@ class Orders extends API\Request {
75
  $line_items = array_merge( $this->get_product_line_items( $order ), $this->get_fee_line_items( $order ), $this->get_shipping_line_items( $order ) );
76
  $taxes = $this->get_order_taxes( $order );
77
 
78
- $this->apply_taxes( $taxes, $line_items );
79
- $order_model->setLineItems( $line_items );
80
- $order_model->setTaxes( $taxes );
81
 
82
  if ( $order->get_discount_total() ) {
83
 
@@ -111,7 +107,7 @@ class Orders extends API\Request {
111
  * @since 2.0.0
112
  *
113
  * @param \WC_Order $order order object
114
- * @return SquareModel\OrderLineItem[]
115
  */
116
  protected function get_product_line_items( \WC_Order $order ) {
117
 
@@ -123,20 +119,7 @@ class Orders extends API\Request {
123
  continue;
124
  }
125
 
126
- $line_item = new SquareModel\OrderLineItem();
127
-
128
- $line_item->setQuantity( (string) $item->get_quantity() );
129
- $line_item->setBasePriceMoney( Money_Utility::amount_to_money( $order->get_item_subtotal( $item ), $order->get_currency() ) );
130
-
131
- $square_id = $item->get_meta( Product::SQUARE_VARIATION_ID_META_KEY );
132
-
133
- if ( $square_id ) {
134
- $line_item->setCatalogObjectId( $square_id );
135
- } else {
136
- $line_item->setName( $item->get_name() );
137
- }
138
-
139
- $line_items[] = $line_item;
140
  }
141
 
142
  return $line_items;
@@ -149,7 +132,7 @@ class Orders extends API\Request {
149
  * @since 2.0.0
150
  *
151
  * @param \WC_Order $order order object
152
- * @return SquareModel\OrderLineItem[]
153
  */
154
  protected function get_fee_line_items( \WC_Order $order ) {
155
 
@@ -161,14 +144,7 @@ class Orders extends API\Request {
161
  continue;
162
  }
163
 
164
- $line_item = new SquareModel\OrderLineItem();
165
-
166
- $line_item->setQuantity( (string) 1 );
167
-
168
- $line_item->setName( $item->get_name() );
169
- $line_item->setBasePriceMoney( Money_Utility::amount_to_money( $item->get_total(), $order->get_currency() ) );
170
-
171
- $line_items[] = $line_item;
172
  }
173
 
174
  return $line_items;
@@ -181,7 +157,7 @@ class Orders extends API\Request {
181
  * @since 2.0.0
182
  *
183
  * @param \WC_Order $order order object
184
- * @return SquareModel\OrderLineItem[]
185
  */
186
  protected function get_shipping_line_items( \WC_Order $order ) {
187
 
@@ -193,17 +169,49 @@ class Orders extends API\Request {
193
  continue;
194
  }
195
 
196
- $line_item = new SquareModel\OrderLineItem();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
 
198
- $line_item->setQuantity( (string) 1 );
199
 
200
- $line_item->setName( $item->get_name() );
201
- $line_item->setBasePriceMoney( Money_Utility::amount_to_money( $item->get_total(), $order->get_currency() ) );
202
 
203
- $line_items[] = $line_item;
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  }
205
 
206
- return $line_items;
207
  }
208
 
209
 
@@ -220,7 +228,6 @@ class Orders extends API\Request {
220
  $taxes = array();
221
 
222
  foreach ( $order->get_taxes() as $tax ) {
223
-
224
  $tax_item = new SquareModel\OrderLineItemTax(
225
  array(
226
  'uid' => uniqid(),
@@ -230,14 +237,9 @@ class Orders extends API\Request {
230
  )
231
  );
232
 
233
- $pre_tax_total = (float) $order->get_total() - (float) $order->get_total_tax();
234
- $total_tax = (float) $tax->get_tax_total() + (float) $tax->get_shipping_tax_total();
235
-
236
- $percentage = ( $total_tax / $pre_tax_total ) * 100;
237
-
238
- $tax_item->setPercentage( Framework\SV_WC_Helper::number_format( $percentage ) );
239
 
240
- $taxes[] = $tax_item;
241
  }
242
 
243
  return $taxes;
@@ -245,30 +247,33 @@ class Orders extends API\Request {
245
 
246
 
247
  /**
248
- * Applies taxes on each Square line item.
249
  *
250
  * @since 2.0.4
251
  *
252
  * @param SquareModel\OrderLineItemTax[] $taxes
253
- * @param SquareModel\OrderLineItem[] $line_items
 
254
  */
255
- protected function apply_taxes( $taxes, $line_items ) {
256
 
257
- foreach ( $line_items as $line_item ) {
258
 
259
- $applied_taxes = array();
 
 
260
 
261
- foreach ( $taxes as $tax ) {
262
 
263
- $applied_taxes[] = new SquareModel\OrderLineItemAppliedTax(
264
- array(
265
- 'tax_uid' => $tax->getUid(),
266
- )
267
- );
268
- }
 
269
 
270
- $line_item->setAppliedTaxes( $applied_taxes );
271
- }
272
  }
273
 
274
 
15
  * Do not edit or add to this file if you wish to upgrade WooCommerce Square to newer
16
  * versions in the future. If you wish to customize WooCommerce Square for your
17
  * needs please refer to https://docs.woocommerce.com/document/woocommerce-square/
 
 
 
 
18
  */
19
 
20
  namespace WooCommerce\Square\Gateway\API\Requests;
64
 
65
  $order_model = new SquareModel\Order();
66
  $order_model->setReferenceId( $order->get_order_number() );
67
+
68
  if ( ! empty( $order->square_customer_id ) ) {
69
  $order_model->setCustomerId( $order->square_customer_id );
70
  }
72
  $line_items = array_merge( $this->get_product_line_items( $order ), $this->get_fee_line_items( $order ), $this->get_shipping_line_items( $order ) );
73
  $taxes = $this->get_order_taxes( $order );
74
 
75
+ $order_model->setLineItems( $this->get_api_line_items( $order, $line_items, $taxes ) );
76
+ $order_model->setTaxes( array_values( $taxes ) );
 
77
 
78
  if ( $order->get_discount_total() ) {
79
 
107
  * @since 2.0.0
108
  *
109
  * @param \WC_Order $order order object
110
+ * @return \WC_Order_Item_Product[]
111
  */
112
  protected function get_product_line_items( \WC_Order $order ) {
113
 
119
  continue;
120
  }
121
 
122
+ $line_items[] = $item;
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  }
124
 
125
  return $line_items;
132
  * @since 2.0.0
133
  *
134
  * @param \WC_Order $order order object
135
+ * @return \WC_Order_Item_Fee[]
136
  */
137
  protected function get_fee_line_items( \WC_Order $order ) {
138
 
144
  continue;
145
  }
146
 
147
+ $line_items[] = $item;
 
 
 
 
 
 
 
148
  }
149
 
150
  return $line_items;
157
  * @since 2.0.0
158
  *
159
  * @param \WC_Order $order order object
160
+ * @return \WC_Order_Item_Shipping[]
161
  */
162
  protected function get_shipping_line_items( \WC_Order $order ) {
163
 
169
  continue;
170
  }
171
 
172
+ $line_items[] = $item;
173
+ }
174
+
175
+ return $line_items;
176
+ }
177
+
178
+
179
+ /**
180
+ * Gets Square API line item objects.
181
+ *
182
+ * @since 2.2.6
183
+ *
184
+ * @param \WC_Order $order
185
+ * @param \WC_Order_Item[] $line_items
186
+ * @param SquareModel\OrderLineItemTax[] $taxes
187
+ * @return SquareModel\OrderLineItem[]
188
+ */
189
+ protected function get_api_line_items( \WC_Order $order, $line_items, $taxes ) {
190
+
191
+ $api_line_items = array();
192
 
193
+ foreach ( $line_items as $item ) {
194
 
195
+ $line_item = new SquareModel\OrderLineItem();
196
+ $is_product = $item instanceof WC_Order_Item_Product;
197
 
198
+ $line_item->setQuantity( $is_product ? (string) $item->get_quantity() : (string) 1 );
199
+ $line_item->setBasePriceMoney( Money_Utility::amount_to_money( $is_product ? $order->get_item_subtotal( $item ) : $item->get_total(), $order->get_currency() ) );
200
+
201
+ if ( $is_product && $item->get_meta( Product::SQUARE_VARIATION_ID_META_KEY ) ) {
202
+ $line_item->setCatalogObjectId( $item->get_meta( Product::SQUARE_VARIATION_ID_META_KEY ) );
203
+ } else {
204
+ $line_item->setName( $item->get_name() );
205
+ }
206
+
207
+ $applied_taxes = $this->apply_taxes( $taxes, $item );
208
+
209
+ $line_item->setAppliedTaxes( $applied_taxes );
210
+
211
+ $api_line_items[] = $line_item;
212
  }
213
 
214
+ return $api_line_items;
215
  }
216
 
217
 
228
  $taxes = array();
229
 
230
  foreach ( $order->get_taxes() as $tax ) {
 
231
  $tax_item = new SquareModel\OrderLineItemTax(
232
  array(
233
  'uid' => uniqid(),
237
  )
238
  );
239
 
240
+ $tax_item->setPercentage( Framework\SV_WC_Helper::number_format( (float) $tax->get_rate_percent() ) );
 
 
 
 
 
241
 
242
+ $taxes[ $tax->get_rate_id() ] = $tax_item;
243
  }
244
 
245
  return $taxes;
247
 
248
 
249
  /**
250
+ * Creates applied taxes array for each Square line item.
251
  *
252
  * @since 2.0.4
253
  *
254
  * @param SquareModel\OrderLineItemTax[] $taxes
255
+ * @param WC_Order_Item $line_item
256
+ * @return SquareModel\OrderLineItemAppliedTax[] $taxes
257
  */
258
+ protected function apply_taxes( $taxes, $line_item ) {
259
 
260
+ $tax_ids = array();
261
 
262
+ foreach ( $line_item->get_taxes()['total'] as $key => $value ) {
263
+ $tax_ids[] = $key;
264
+ }
265
 
266
+ $applied_taxes = array();
267
 
268
+ foreach ( $tax_ids as $tax_id ) {
269
+ $applied_taxes[] = new SquareModel\OrderLineItemAppliedTax(
270
+ array(
271
+ 'tax_uid' => $taxes[ $tax_id ]->getUid(),
272
+ )
273
+ );
274
+ };
275
 
276
+ return $applied_taxes;
 
277
  }
278
 
279
 
includes/Handlers/Background_Job.php CHANGED
@@ -16,9 +16,6 @@
16
  * versions in the future. If you wish to customize WooCommerce Square for your
17
  * needs please refer to https://docs.woocommerce.com/document/woocommerce-square/
18
  *
19
- * @author WooCommerce
20
- * @copyright Copyright: (c) 2019, Automattic, Inc.
21
- * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
22
  */
23
 
24
  namespace WooCommerce\Square\Handlers;
@@ -370,5 +367,26 @@ class Background_Job extends Framework\SV_WP_Background_Job_Handler {
370
  return true;
371
  }
372
 
373
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374
  }
16
  * versions in the future. If you wish to customize WooCommerce Square for your
17
  * needs please refer to https://docs.woocommerce.com/document/woocommerce-square/
18
  *
 
 
 
19
  */
20
 
21
  namespace WooCommerce\Square\Handlers;
367
  return true;
368
  }
369
 
370
+ /**
371
+ * Tests the background handler's connection.
372
+ *
373
+ * Override of SV_WP_Background_Job_Handler::test_connection().
374
+ *
375
+ * SV's Framework version of this function doesn't set sslverify to false for local requests.
376
+ * WP considers 'local' to be one to `localhost` or to the same host as the site itself.
377
+ *
378
+ * This sslverify is handled in SV_WP_Async_Request::dispatch(), but wasn't handled in the test connection.
379
+ *
380
+ * @see SV_WP_Background_Job_Handler::test_connection()
381
+ * @return bool
382
+ */
383
+ public function test_connection() {
384
+ $test_url = add_query_arg( 'action', "{$this->identifier}_test", admin_url( 'admin-ajax.php' ) );
385
+ $result = wp_remote_get( $test_url, array( 'sslverify' => apply_filters( 'https_local_ssl_verify', false ) ) );
386
+ $body = ! is_wp_error( $result ) ? wp_remote_retrieve_body( $result ) : null;
387
+
388
+ // some servers may add a UTF8-BOM at the beginning of the response body, so we check if our test
389
+ // string is included in the body, as an equal check would produce a false negative test result
390
+ return $body && Framework\SV_WC_Helper::str_exists( $body, '[TEST_LOOPBACK]' );
391
+ }
392
  }
includes/Handlers/Product.php CHANGED
@@ -620,7 +620,18 @@ class Product {
620
  public static function get_product_id_by_square_variation_id( $variation_id ) {
621
  global $wpdb;
622
 
623
- return $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_key = %s AND meta_value = %s", self::SQUARE_VARIATION_ID_META_KEY, $variation_id ) );
 
 
 
 
 
 
 
 
 
 
 
624
  }
625
 
626
 
@@ -655,7 +666,18 @@ class Product {
655
  public static function get_product_id_by_square_id( $square_id ) {
656
  global $wpdb;
657
 
658
- return $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_key = %s AND meta_value = %s", self::SQUARE_ID_META_KEY, $square_id ) );
 
 
 
 
 
 
 
 
 
 
 
659
  }
660
 
661
 
@@ -1377,4 +1399,27 @@ class Product {
1377
 
1378
  return $inventory_change;
1379
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1380
  }
620
  public static function get_product_id_by_square_variation_id( $variation_id ) {
621
  global $wpdb;
622
 
623
+ return $wpdb->get_var(
624
+ $wpdb->prepare(
625
+ "
626
+ SELECT pm.post_id
627
+ FROM {$wpdb->prefix}postmeta AS pm
628
+ INNER JOIN {$wpdb->prefix}posts AS p ON pm.post_id = p.ID
629
+ WHERE pm.meta_key = %s AND pm.meta_value = %s
630
+ ",
631
+ self::SQUARE_VARIATION_ID_META_KEY,
632
+ $variation_id
633
+ )
634
+ );
635
  }
636
 
637
 
666
  public static function get_product_id_by_square_id( $square_id ) {
667
  global $wpdb;
668
 
669
+ return $wpdb->get_var(
670
+ $wpdb->prepare(
671
+ "
672
+ SELECT pm.post_id
673
+ FROM {$wpdb->prefix}postmeta AS pm
674
+ INNER JOIN {$wpdb->prefix}posts AS p ON pm.post_id = p.ID
675
+ WHERE pm.meta_key = %s AND pm.meta_value = %s
676
+ ",
677
+ self::SQUARE_ID_META_KEY,
678
+ $square_id
679
+ )
680
+ );
681
  }
682
 
683
 
1399
 
1400
  return $inventory_change;
1401
  }
1402
+
1403
+ /**
1404
+ * Helper function to get the variation product's parent ID from posts table but only if the parent product still exists.
1405
+ *
1406
+ * @since 2.5.2
1407
+ * @param int|object $variation_id
1408
+ * @return bool
1409
+ */
1410
+ public static function get_parent_product_id_by_variation_id( $variation_id ) {
1411
+ global $wpdb;
1412
+
1413
+ return $wpdb->get_var(
1414
+ $wpdb->prepare(
1415
+ "
1416
+ SELECT pr.post_parent
1417
+ FROM wp_posts pr
1418
+ INNER JOIN wp_posts pp ON pp.ID = pr.post_parent
1419
+ WHERE pr.ID=%d AND pr.post_type IN ('product', 'product_variation') AND pp.post_type = 'product';
1420
+ ",
1421
+ $variation_id
1422
+ )
1423
+ );
1424
+ }
1425
  }
includes/Plugin.php CHANGED
@@ -42,7 +42,7 @@ class Plugin extends Framework\SV_WC_Payment_Gateway_Plugin {
42
 
43
 
44
  /** plugin version number */
45
- const VERSION = '2.5.1';
46
 
47
  /** plugin ID */
48
  const PLUGIN_ID = 'square';
42
 
43
 
44
  /** plugin version number */
45
+ const VERSION = '2.5.2';
46
 
47
  /** plugin ID */
48
  const PLUGIN_ID = 'square';
includes/Sync/Product_Import.php CHANGED
@@ -340,8 +340,11 @@ class Product_Import extends Stepped_Job {
340
  return (bool) wc_get_product_id_by_sku( $data['sku'] );
341
  } else {
342
  foreach ( $data['variations'] as $variation ) {
343
- if ( wc_get_product_id_by_sku( $variation['sku'] ) ) {
344
- return true;
 
 
 
345
  }
346
  }
347
  }
@@ -950,8 +953,9 @@ class Product_Import extends Stepped_Job {
950
  } else {
951
 
952
  $update_variation = array(
953
- 'post_title' => $variation_post_title,
954
- 'menu_order' => $menu_order,
 
955
  );
956
 
957
  if ( isset( $variation['visible'] ) ) {
340
  return (bool) wc_get_product_id_by_sku( $data['sku'] );
341
  } else {
342
  foreach ( $data['variations'] as $variation ) {
343
+ $variation_id = wc_get_product_id_by_sku( $variation['sku'] );
344
+
345
+ if ( $variation_id ) {
346
+ // found variation with matching SKU, check if parent still exists and return that result
347
+ return (bool) Product::get_parent_product_id_by_variation_id( $variation_id );
348
  }
349
  }
350
  }
953
  } else {
954
 
955
  $update_variation = array(
956
+ 'post_title' => $variation_post_title,
957
+ 'menu_order' => $menu_order,
958
+ 'post_parent' => $product_id,
959
  );
960
 
961
  if ( isset( $variation['visible'] ) ) {
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: credit card, square, woocommerce, inventory sync
4
  Requires at least: 4.6
5
  Tested up to: 5.7
6
  Requires PHP: 5.6
7
- Stable tag: 2.5.1
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -71,6 +71,11 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
71
  2. The payment gateway settings.
72
 
73
  == Changelog ==
 
 
 
 
 
74
  = 2.5.1 - 2021.05.18 =
75
  * Fix - Pay for Order and Add Payment Method forms sometimes not working when choosing another payment method other than Square. PR#618
76
 
4
  Requires at least: 4.6
5
  Tested up to: 5.7
6
  Requires PHP: 5.6
7
+ Stable tag: 2.5.2
8
  License: GPLv3
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.html
10
 
71
  2. The payment gateway settings.
72
 
73
  == Changelog ==
74
+ = 2.5.2 - 2021.07.21 =
75
+ * Fix - Product and inventory data not being synced due to duplicate/orphaned product metadata in database. PR#625
76
+ * Fix - Bypass SSL verification when checking background job processing eligibility. PR#624
77
+ * Fix - Correctly apply taxes in the Order API request and report accurate percentages. PR#559
78
+
79
  = 2.5.1 - 2021.05.18 =
80
  * Fix - Pay for Order and Add Payment Method forms sometimes not working when choosing another payment method other than Square. PR#618
81
 
woocommerce-square.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * Plugin Name: WooCommerce Square
4
- * Version: 2.5.1
5
  * Plugin URI: https://woocommerce.com/products/square/
6
  * Description: Adds ability to sync inventory between WooCommerce and Square POS. In addition, you can also make purchases through the Square payment gateway.
7
  * Author: WooCommerce
@@ -19,7 +19,7 @@
19
  * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
20
  *
21
  * WC requires at least: 3.0
22
- * WC tested up to: 5.3
23
  */
24
 
25
  defined( 'ABSPATH' ) || exit;
1
  <?php
2
  /**
3
  * Plugin Name: WooCommerce Square
4
+ * Version: 2.5.2
5
  * Plugin URI: https://woocommerce.com/products/square/
6
  * Description: Adds ability to sync inventory between WooCommerce and Square POS. In addition, you can also make purchases through the Square payment gateway.
7
  * Author: WooCommerce
19
  * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
20
  *
21
  * WC requires at least: 3.0
22
+ * WC tested up to: 5.5
23
  */
24
 
25
  defined( 'ABSPATH' ) || exit;