Skip to content

Commit

Permalink
Release v5.2.1 (#390)
Browse files Browse the repository at this point in the history
* 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 <aashish@omise.co>

* Updated metadata for v5.2.1

---------

Co-authored-by: (AJ) Zin Kyaw Kyaw <108650842+ajzkk@users.noreply.github.com>
Co-authored-by: Aashish <aashish@omise.co>
  • Loading branch information
3 people committed Aug 9, 2023
1 parent 8b92392 commit e44d980
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
8 changes: 1 addition & 7 deletions assets/javascripts/omise-embedded-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 22 additions & 1 deletion includes/gateway/class-omise-payment-installment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions omise-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,7 +22,7 @@ class Omise
*
* @var string
*/
public $version = '5.2.0';
public $version = '5.2.1';

/**
* The Omise Instance.
Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

use PHPUnit\Framework\TestCase;
use Mockery;

class Omise_Payment_Installment_Test extends TestCase
{
public function setUp(): void
{
// Mocking the parent class
$offsite = Mockery::mock('overload:Omise_Payment_Offsite');
$offsite->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);
}
}

0 comments on commit e44d980

Please sign in to comment.