From 9489f14c04c37c627f9a7a8f88eda558ee305ff2 Mon Sep 17 00:00:00 2001 From: Aashish Gurung <101558497+aashishgurung@users.noreply.github.com> Date: Wed, 17 May 2023 11:28:36 +0700 Subject: [PATCH 1/4] [ENGA3-1334]: Fix invalid product issue with variance item (#377) * [ENGA3-1334]: Added WC_Product_Variation class when the item is a variant to fix the invalid prodcut issue. Atome logo is also added. * Fixed formatting. --------- Co-authored-by: Aashish --- assets/images/atome.png | Bin 0 -> 3415 bytes .../gateway/class-omise-payment-atome.php | 25 ++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 assets/images/atome.png diff --git a/assets/images/atome.png b/assets/images/atome.png new file mode 100644 index 0000000000000000000000000000000000000000..9cc14007292b0f5771fd91c201e4427824ad22d0 GIT binary patch literal 3415 zcma)9c{G%58-HeOl@NK!l6_w%TcIr3#aLrdwlU+ijj@a^dzK_>n5HnaI5H-3Jft%V|0zi}$0K_K&z&a@8` z2bevtnHT~`$6skzWi~y-5^82?#InM`&LF4+WAkhT09G$ELw);*j~kC7(e_3{1G)!N z`GZDTgX&pHN#YWoH*6R+|F~=L*j@%}%WbIV2%D%KY6?(V3Nwx(tOLP7Z8$Yv?MZPBGvh!p}H*)sCHEyo{7j6A;SHL67 z4fpMuy4jTj;Am@`!NDoEM~=h+L;M8QD(JdDq_EUA{*J$%Biu0bPjIXjNZ;$8D|cmp z0Ts;J7)+}xQ->qK6W_Oh+%Oj>>2&G&)z(hvv42@*u@+1CL|)YzfBL43&_DPkh*=7n zY4VzueL*L%7YtGVI0!?1wv9bYAvlaHkO&nOOz&8!lPe$w>b%QP@y%T9G}~TJ8-+UO zl<2bOg60*5THlx?7Z8ls*8Lri=KaGS5HE8qB^yf!w|SN@DFDy<`g1aJFJYeVSFAgA ze;|5bgvNO)t;F{{dJ;!<#~XbDKw-~*Rje!JlJ^vo1+{HgM?;8KU>?2OgT}8nxIx8A24lI=4nqk!Xv-HkItYlIGa`yV;SSffHy zI1RD4A-fS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+>H>FP%H7Upw5tz(D!EUM84%WSuchsCxme^q3>v zjzo^=fx$_RxiU3$;hCj=v?2Fy;WRbkvj=J-f6=6!8e}p~X76)VPq;G0)I!^0Y(>zW zGoM#35)lTV!tp<3?%F>!E#oBTJtWr#63)(2IQpOg?`#voxrD3hnUG&~C>CE`K@<4hvA0TJdLKXDT$A zkW;w)K-yahdqz0%S~8_&0>s+mi)oC#uA}MwP_tFwx})Dx`V%9%5F4BOURtHCnwhal zkDRe^FHP!SET=Xmv#wY?BKej!zk2V{;OK=4Z3wjDTaxZS%eheWWg~WTM&tN~Xs?=DpW>(ohjq?UXJRGGrk{nbMX+cM_!3pWuBaEo^6^aWL@ijG%Ke=wHX)LqT4Llw9G?EJSpavIn3x{yQRgpXjl1lLhUT}m_`oOk+ zFaI*x%Huu!n}|DAoVhhX$%{6^r9{aOidqmfh)Bvwef?_t_j7%VD20R*T|9nG*}rE> zAh#ybzEy!C5q&28Drol!nuJgKytqfb zrQE!ECzK-Pq*RudY`6Hh61TeLms)Z&?P}Zuy?RP@6b8=?X?Mpt1^MGcXI~^o_g(Qa*7g6iy2AW*N_yoA)F_z=>7YzPm_|upqi$BJ z3f#=Q&6N6)2H+SEddNe`UT9N{3)rJUH-_}k)<6hv zIr_Ub0bkbm>xB|x5f_1cEAYX`yy&i&1S18(3N=JAvh{%XxZF49f;%P1bRUeEKbHnGuFByZyy<1n<45d@gdw|T9UEhTDj5kn8`%R>ZOa{5N7-dh6tD$($W%;qsJ!zP^u5WNRL2t $item) { - $product_variation_id = $item['variation_id']; - // Check if product has variation. - $productId = $product_variation_id ? $item['variation_id'] : $item['product_id']; - $product = new WC_Product($productId); + $product = $item['variation_id'] ? + new WC_Product_Variation($item['variation_id']) + : new WC_Product($item['product_id']); + $sku = $product->get_sku(); // item don't have price. So we have to take subtotal and divide it by quantity to get the price $pricePerItem = $item['subtotal'] / $item['qty']; @@ -204,10 +204,25 @@ private function getItems($order, $currency) 'quantity' => $item['qty'], 'name' => $item['name'], 'amount' => Omise_Money::to_subunit($pricePerItem, $currency), - 'sku' => empty($sku) ? $productId : $sku // if sku is not present then pass productId + 'sku' => empty($sku) ? $product->get_id() : $sku // if sku is not present then pass productId ]; } return $products; } + + /** + * Get icons + * + * @see WC_Payment_Gateway::get_icon() + */ + public function get_icon() { + $icon = Omise_Image::get_image([ + 'file' => 'atome.png', + 'alternate_text' => 'Atome logo', + 'width' => 20, + 'height' => 20 + ]); + return apply_filters('woocommerce_gateway_icon', $icon, $this->id); + } } From 1488f57d6799663148ca43927cdc01dee13bb6f6 Mon Sep 17 00:00:00 2001 From: Aashish Gurung <101558497+aashishgurung@users.noreply.github.com> Date: Tue, 23 May 2023 15:25:41 +0700 Subject: [PATCH 2/4] [ENGA3-1334]: Remove free products from the Atome bill (#378) * [ENGA3-1334]: Remove free products from Atome product list. * [ENGA3-1134]: Updated the message for Atome on freebie products. * [ENGA3-1134]: Check subtotal instead of price per item when comparing to zero. --------- Co-authored-by: Aashish --- .../gateway/class-omise-payment-atome.php | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/includes/gateway/class-omise-payment-atome.php b/includes/gateway/class-omise-payment-atome.php index 5cdddb44..765ba6a8 100644 --- a/includes/gateway/class-omise-payment-atome.php +++ b/includes/gateway/class-omise-payment-atome.php @@ -80,12 +80,12 @@ private function register_omise_atome_scripts() { public function payment_fields() { parent::payment_fields(); - $viewData = $this->validateMinRequiredAmount(); + $viewData = $this->validateAtomeRequest(); Omise_Util::render_view('templates/payment/form-atome.php', $viewData); } - private function validateMinRequiredAmount() + private function validateAtomeRequest() { $limits = [ 'thb' => [ @@ -103,7 +103,14 @@ private function validateMinRequiredAmount() ]; $currency = strtolower(get_woocommerce_currency()); - $cartTotal = WC()->cart->total; + $cart = WC()->cart; + + if ($cart->subtotal === 0) { + return [ + 'status' => false, + 'message' => 'Complimentary products cannot be billed.' + ]; + } if (!isset($limits[$currency])) { return [ @@ -114,7 +121,7 @@ private function validateMinRequiredAmount() $limit = $limits[$currency]; - if ($cartTotal < $limit['min']) { + if ($cart->total < $limit['min']) { return [ 'status' => false, 'message' => sprintf( @@ -125,7 +132,7 @@ private function validateMinRequiredAmount() ]; } - if ($cartTotal > $limit['max']) { + if ($cart->total > $limit['max']) { return [ 'status' => false, 'message' => __( @@ -191,14 +198,20 @@ private function getItems($order, $currency) // Loop through ordered items foreach ($items as $key => $item) { + // item don't have price. So we have to take subtotal and divide it by quantity to get the price + $pricePerItem = $item['subtotal'] / $item['qty']; + + // Remove product from the list if the price is 0 + if ((float)$item['subtotal'] === 0.00) { + continue; + } + // Check if product has variation. $product = $item['variation_id'] ? new WC_Product_Variation($item['variation_id']) : new WC_Product($item['product_id']); $sku = $product->get_sku(); - // item don't have price. So we have to take subtotal and divide it by quantity to get the price - $pricePerItem = $item['subtotal'] / $item['qty']; $products[$key] = [ 'quantity' => $item['qty'], From 8d85f1b1482e0bd55edad7d78253e09a22f2d72b Mon Sep 17 00:00:00 2001 From: "(AJ) Zin Kyaw Kyaw" <108650842+ajzkk@users.noreply.github.com> Date: Wed, 7 Jun 2023 11:13:40 +0700 Subject: [PATCH 3/4] fixed not compatible with country based payments plugin (#379) --- assets/javascripts/omise-payment-form-handler.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/omise-payment-form-handler.js b/assets/javascripts/omise-payment-form-handler.js index ee3b824f..e346f84d 100755 --- a/assets/javascripts/omise-payment-form-handler.js +++ b/assets/javascripts/omise-payment-form-handler.js @@ -255,9 +255,10 @@ } function initializeSecureCardForm() { - if (Boolean(omise_params.secure_form_enabled)) { + const omiseCardElement = document.getElementById('omise-card'); + if (omiseCardElement && Boolean(omise_params.secure_form_enabled)) { showOmiseEmbeddedCardForm({ - element: document.getElementById('omise-card'), + element: omiseCardElement, publicKey: omise_params.key, hideRememberCard: HIDE_REMEMBER_CARD, locale: LOCALE, From 4f3802f3ed4025c3c0a57d7ae6c8aa8c64e99a9f Mon Sep 17 00:00:00 2001 From: Aashish Date: Mon, 12 Jun 2023 11:10:52 +0700 Subject: [PATCH 4/4] Preparing release of v5.1.1 --- CHANGELOG.md | 4 ++++ omise-woocommerce.php | 4 ++-- readme.txt | 7 ++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b00cffbc..9f2e60ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +### [v5.1.1 _(Jun 13, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v5.1.1) +- Remove free products from the Atome bill. (PR [#378](https://github.com/omise/omise-woocommerce/pull/378)) +- Fix incompatible issue with country based payments plugin. (PR [#379](https://github.com/omise/omise-woocommerce/pull/379)) + ### [v5.1.0 _(May 15, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v5.1.0) - Added Atome payment method. (PR [#364](https://github.com/omise/omise-woocommerce/pull/364)) - Installment minimum amount from capability API. (PR [#365](https://github.com/omise/omise-woocommerce/pull/365)) diff --git a/omise-woocommerce.php b/omise-woocommerce.php index ee1782c5..84bb6de3 100644 --- a/omise-woocommerce.php +++ b/omise-woocommerce.php @@ -4,7 +4,7 @@ * Plugin Name: Opn Payments * Plugin URI: https://www.omise.co/woocommerce * Description: Opn Payments is a WordPress plugin designed specifically for WooCommerce. The plugin adds support for Opn Payments Payment Gateway's payment methods to WooCommerce. - * Version: 5.1.0 + * Version: 5.1.1 * Author: Opn Payments and contributors * Author URI: https://github.com/omise/omise-woocommerce/graphs/contributors * Text Domain: omise @@ -22,7 +22,7 @@ class Omise * * @var string */ - public $version = '5.1.0'; + public $version = '5.1.1'; /** * The Omise Instance. diff --git a/readme.txt b/readme.txt index cebbfb23..e1bf264f 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: Opn Payments Tags: opn payments, payment, payment gateway, woocommerce plugin, omise, opn, installment, internet banking, alipay, paynow, truemoney wallet, woocommerce payment Requires at least: 4.3.1 Tested up to: 6.0.2 -Stable tag: 5.1.0 +Stable tag: 5.1.1 License: MIT License URI: https://opensource.org/licenses/MIT @@ -34,6 +34,11 @@ From there: == Changelog == += 5.1.1 = + +- Remove free products from the Atome bill. (PR [#378](https://github.com/omise/omise-woocommerce/pull/378)) +- Fix incompatible issue with country based payments plugin. (PR [#379](https://github.com/omise/omise-woocommerce/pull/379)) + = 5.1.0 = - Added Atome payment method. (PR [#364](https://github.com/omise/omise-woocommerce/pull/364))