From e44d98043d83df54ce63807a3602c7aed1c58915 Mon Sep 17 00:00:00 2001 From: Aashish Gurung <101558497+aashishgurung@users.noreply.github.com> Date: Wed, 9 Aug 2023 13:16:25 +0700 Subject: [PATCH] Release v5.2.1 (#390) * Fixed Japanese translation issue in secure form. * Used locale instead of hardcoded en * Fix installment payment when admin manually pay for order (#388) * [MIT-1562]: Total amount for payment is pulled from order instead of cart when the payment page is triggered from admin. * Fixed the issue with Japanese language Support in the secure form. * Added unit test for installment * Added unit test for installment * Updated test * Fix indentation * Fix the tests after code chagne. * Fix the spelling mistake. * Reverted secure form changes. --------- Co-authored-by: Aashish * Updated metadata for v5.2.1 --------- Co-authored-by: (AJ) Zin Kyaw Kyaw <108650842+ajzkk@users.noreply.github.com> Co-authored-by: Aashish --- CHANGELOG.md | 4 + assets/javascripts/omise-embedded-card.js | 8 +- .../class-omise-payment-installment.php | 23 ++++- omise-woocommerce.php | 4 +- readme.txt | 7 +- .../class-omise-payment-installment-test.php | 85 +++++++++++++++++++ 6 files changed, 120 insertions(+), 11 deletions(-) create mode 100644 tests/unit/includes/gateway/class-omise-payment-installment-test.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c44f1c8..cd7744d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +### [v5.2.1 _(Aug 9, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v5.2.1) +- Fixed installment payment when admin manually pay for order. (PR [#388](https://github.com/omise/omise-woocommerce/pull/388)) +- Fixed Japanese translation issue in secure form. (PR [#389](https://github.com/omise/omise-woocommerce/pull/389)) + ### [v5.2.0 _(Aug 3, 2023)_](https://github.com/omise/omise-woocommerce/releases/tag/v5.2.0) - Declare High-Performance Order Storage (HPOS) as compatible. (PR [#385](https://github.com/omise/omise-woocommerce/pull/385)) - Added a script to run test `composer test`. (PR [#385](https://github.com/omise/omise-woocommerce/pull/385)) diff --git a/assets/javascripts/omise-embedded-card.js b/assets/javascripts/omise-embedded-card.js index e4ed6b1f..af0c676c 100644 --- a/assets/javascripts/omise-embedded-card.js +++ b/assets/javascripts/omise-embedded-card.js @@ -25,17 +25,11 @@ function showOmiseEmbeddedCardForm({ } element.style.height = iframeElementHeight + 'px' - const localeMatching = { - en_US: 'en', - ja_JP: 'ja', - th_TH: 'th' - } - OmiseCard.configure({ publicKey: publicKey, element, customCardForm: true, - locale: localeMatching[locale] ?? 'en', + locale: locale, customCardFormTheme: theme, customCardFormHideRememberCard: hideRememberCard ?? false, customCardFormBrandIcons: brandIcons ?? null, diff --git a/includes/gateway/class-omise-payment-installment.php b/includes/gateway/class-omise-payment-installment.php index ec7283a9..6fb7c675 100644 --- a/includes/gateway/class-omise-payment-installment.php +++ b/includes/gateway/class-omise-payment-installment.php @@ -70,7 +70,8 @@ public function payment_fields() parent::payment_fields(); $currency = get_woocommerce_currency(); - $cart_total = WC()->cart->total; + $cart_total = $this->getTotalAmount(); + $capabilities = $this->backend->capabilities(); $installmentMinLimit = $capabilities->getInstallmentMinLimit(); @@ -84,6 +85,26 @@ public function payment_fields() ); } + /** + * Get the total amount of an order + */ + public function getTotalAmount() + { + global $wp; + + if ( + isset($wp->query_vars['order-pay']) && + (int)$wp->query_vars['order-pay'] > 0 + ) { + $order_id = (int)$wp->query_vars['order-pay']; + $order = wc_get_order( $order_id ); + return $order->get_total(); + } + + // if not an order page then get total from the cart + return WC()->cart->total; + } + /** * @inheritdoc */ diff --git a/omise-woocommerce.php b/omise-woocommerce.php index fe210d24..b86fd9c0 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.2.0 + * Version: 5.2.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.2.0'; + public $version = '5.2.1'; /** * The Omise Instance. diff --git a/readme.txt b/readme.txt index 20fc7e33..a99002ec 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.2.0 +Stable tag: 5.2.1 License: MIT License URI: https://opensource.org/licenses/MIT @@ -34,6 +34,11 @@ From there: == Changelog == += 5.2.1 = + +- Fix installment payment when admin manually pay for order. (PR [#388](https://github.com/omise/omise-woocommerce/pull/388)) +- Fixed Japanese translation issue in secure form. (PR [#389](https://github.com/omise/omise-woocommerce/pull/389)) + = 5.2.0 = - Declare High-Performance Order Storage (HPOS) as compatible. (PR [#385](https://github.com/omise/omise-woocommerce/pull/385)) diff --git a/tests/unit/includes/gateway/class-omise-payment-installment-test.php b/tests/unit/includes/gateway/class-omise-payment-installment-test.php new file mode 100644 index 00000000..632c30c6 --- /dev/null +++ b/tests/unit/includes/gateway/class-omise-payment-installment-test.php @@ -0,0 +1,85 @@ +shouldReceive('init_settings'); + $offsite->shouldReceive('get_option'); + + // mocking WP built-in functions + if (!function_exists('wp_kses')) { + function wp_kses() {} + } + + if (!function_exists('add_action')) { + function add_action() {} + } + + require_once __DIR__ . '/../../../../includes/gateway/class-omise-payment-installment.php'; + } + + /** + * close mockery after tests are done + */ + public function teardown(): void + { + Mockery::close(); + } + + /** + * @test + */ + public function getTotalAmountFromAdminOrderpage() + { + // mocking built-in WooCommerce function + if (!function_exists('wc_get_order')) { + function wc_get_order() { + $class = new class { + public $property; + + public function get_total() { + return 999999; + } + }; + return $class; + } + } + + // mocking the WP global variable $wp + $wp = new stdClass(); + $wp->query_vars = ['order-pay' => 123]; + $GLOBALS['wp'] = $wp; + + $installment = new Omise_Payment_Installment(); + $total = $installment->getTotalAmount(); + + $this->assertEquals($total, 999999); + } + + /** + * @test + */ + public function getTotalAmountFromCart() + { + // mocking WC() method + if (!function_exists('WC')) { + function WC() { + $class = new stdClass(); + $class->cart = new stdClass(); + $class->cart->total = 999999; + return $class; + } + } + + $installment = new Omise_Payment_Installment(); + $total = $installment->getTotalAmount(); + + $this->assertEquals($total, 999999); + } +}