Skip to content

Commit

Permalink
Merge pull request #488 from omise/release-v6.0.1
Browse files Browse the repository at this point in the history
Release v6.0.1
  • Loading branch information
aashishgurung authored Nov 12, 2024
2 parents 67ebc85 + a3a9b8f commit b653a46
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 29 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## [v6.0.1 _(Nov 12, 2024)_](https://github.com/omise/omise-woocommerce/releases/tag/v6.0.1)
- Resolve issue of payment failing on installment when total amount is updated after selecting payment. (PR: [#485](https://github.com/omise/omise-woocommerce/pull/485))
- Fix Duitnow bank list issue. (PR: [#486](https://github.com/omise/omise-woocommerce/pull/486))
- Resolve the issue where no payment methods are displayed when the browser's back button is clicked from an issuer page. (PR: [#487](https://github.com/omise/omise-woocommerce/pull/487))

## [v6.0.0 _(Nov 5, 2024)_](https://github.com/omise/omise-woocommerce/releases/tag/v6.0.0)
- Support WooCommerce block. (PR: [#470](https://github.com/omise/omise-woocommerce/pull/470))
- Fix the loading issue in WooCommerce block cart. (PR: [#477](https://github.com/omise/omise-woocommerce/pull/477))
Expand Down
2 changes: 1 addition & 1 deletion assets/javascripts/omise-payment-form-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
showOmiseInstallmentForm({
element: omiseInstallmentElement,
publicKey: omise_installment_params.key,
amount: omise_installment_params.amount,
amount: OMISE_UPDATED_CART_AMOUNT,
locale: LOCALE,
onSuccess: handleCreateOrder,
onError: (error) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '9895ac689bce188c4a74717ce7c149c5');
<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => 'b1a7ad893b10317f131d580cebf99812');
2 changes: 1 addition & 1 deletion includes/blocks/assets/js/build/omise_duitnow_obw.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => 'c95a8877d63c5c3bb2fda93273b0a81a');
<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => 'e2436da6ade36f0dc6835eb771337040');
2 changes: 1 addition & 1 deletion includes/blocks/assets/js/build/omise_installment.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion includes/blocks/assets/js/omise-duitnow-obw.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const DuitNowOBWPaymentMethod = (props) => {
>
<option value="" disabled={true}>-- Select your option --</option>
{
banks.map((bank) => (
Object.values(banks).map((bank) => (
<option
key={bank['code']}
className={bank['code']}
Expand Down
28 changes: 26 additions & 2 deletions includes/blocks/assets/js/omise-installment.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useEffect, useRef} from '@wordpress/element';
import {useEffect, useRef, useState} from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { decodeEntities } from '@wordpress/html-entities';
import { registerPaymentMethod } from '@woocommerce/blocks-registry';
Expand All @@ -11,6 +11,9 @@ const Label = ( props ) => {
return <PaymentMethodLabel text={ label } />
}

const {select, subscribe} = window.wp.data;
const cartStoreKey = window.wc.wcBlocksData.CART_STORE_KEY;

const InstallmentPaymentMethod = (props) => {
const {eventRegistration, emitResponse} = props;
const {onPaymentSetup, onCheckoutValidation, onCheckoutFail} = eventRegistration;
Expand All @@ -20,17 +23,26 @@ const InstallmentPaymentMethod = (props) => {
const el = useRef(null);
const wlbInstallmentRef = useRef(null);
const cardFormErrors = useRef(null);
const totalAmount = useRef(null);

const loadInstallmentForm = () => {
if (installments_enabled) {
// Getting the new total price that might be updated when shipping method
// was updated while other payment method was selected
const cart = select( cartStoreKey ).getCartData();
totalAmount.current = cart.totals.total_price

let locale = settings.locale.toLowerCase();
let supportedLocales = ['en', 'th', 'ja'];
locale = supportedLocales.includes(locale) ? locale : 'en';

// removing previous iframe if there is any
el.current.innerHTML = "";

showOmiseInstallmentForm({
element: el.current,
publicKey: public_key,
amount: total_amount,
amount: totalAmount.current,
locale,
onSuccess: (payload) => {
wlbInstallmentRef.current = payload;
Expand All @@ -42,6 +54,18 @@ const InstallmentPaymentMethod = (props) => {
}
}

// Update total amount on cart update. We need this to send the update amount to the source API
const onCartChange = () => {
const cart = select( cartStoreKey ).getCartData();
totalAmount.current = cart.totals.total_price;
loadInstallmentForm()
}

useEffect(() => {
const unsubscribe = subscribe( onCartChange, cartStoreKey );
return unsubscribe;
}, [cartStoreKey])

useEffect(() => {
loadInstallmentForm();
}, [installments_enabled])
Expand Down
6 changes: 1 addition & 5 deletions includes/blocks/gateways/omise-block-duitnow-obw.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ class Omise_Block_DuitNow_OBW extends Omise_Block_Payment {
protected $name = 'omise_duitnow_obw';

public function set_additional_data() {
if (!$this->gateway->backend) {
$this->gateway->init_payment_config();
}

$this->additional_data = [ 'banks' => $this->gateway->backend->banks ];
$this->additional_data = [ 'banks' => $this->gateway->get_bank_list() ];
}
}
2 changes: 1 addition & 1 deletion includes/class-omise-capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static function isFromCheckoutPage()
return false;
}

$endpoints = ['checkout', 'batch'];
$endpoints = ['checkout', 'batch', 'cart', 'cart/select-shipping-rate'];

foreach($endpoints as $endpoint) {
if (trim($wp->request) !== '') {
Expand Down
85 changes: 77 additions & 8 deletions includes/gateway/class-omise-payment-duitnow-obw.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public function __construct()
$this->restricted_countries = array('MY');
$this->source_type = 'duitnow_obw';

$this->init_payment_config();

add_action('woocommerce_api_' . $this->id . '_callback', 'Omise_Callback::execute');
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
add_action('woocommerce_order_action_' . $this->id . '_sync_payment', array($this, 'sync_payment'));
Expand Down Expand Up @@ -58,11 +56,82 @@ public function init_form_fields()
);
}

public function init_payment_config() {
$capabilities = Omise_Capabilities::retrieve();
$this->backend = $capabilities
? $capabilities->getBackendByType($this->source_type)
: null;
public function get_bank_list()
{
return [
'affin' => [
'code' => 'affin',
'name' => 'Affin Bank'
],
'alliance' => [
'code' => 'alliance',
'name' => 'Alliance Bank'
],
'agro' => [
'code' => 'agro',
'name' => 'Agrobank'
],
'ambank' => [
'code' => 'ambank',
'name' => 'AmBank'
],
'cimb' => [
'code' => 'cimb',
'name' => 'CIMB Bank'
],
'islam' => [
'code' => 'islam',
'name' => 'Bank Islam'
],
'rakyat' => [
'code' => 'rakyat',
'name' => 'Bank Rakyat'
],
'muamalat' => [
'code' => 'muamalat',
'name' => 'Bank Muamalat'
],
'bsn' => [
'code' => 'bsn',
'name' => 'Bank Simpanan Nasional'
],
'hongleong' => [
'code' => 'hongleong',
'name' => 'Hong Leong'
],
'hsbc' => [
'code' => 'hsbc',
'name' => 'HSBC Bank'
],
'kfh' => [
'code' => 'kfh',
'name' => 'Kuwait Finance House'
],
'maybank2u' => [
'code' => 'maybank2u',
'name' => 'Maybank'
],
'ocbc' => [
'code' => 'ocbc',
'name' => 'OCBC'
],
'public' => [
'code' => 'public',
'name' => 'Public Bank'
],
'rhb' => [
'code' => 'rhb',
'name' => 'RHB Bank'
],
'sc' => [
'code' => 'sc',
'name' => 'Standard Chartered'
],
'uob' => [
'code' => 'uob',
'name' => 'United Overseas Bank'
],
];
}

/**
Expand All @@ -73,7 +142,7 @@ public function payment_fields()
parent::payment_fields();
Omise_Util::render_view(
'templates/payment/form-duitnow-obw.php',
[ 'duitnow_obw_banklist' => !$this->backend ? $this->backend->banks : [] ]
[ 'duitnow_obw_banklist' => $this->get_bank_list() ]
);
}

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: 6.0.0
* Version: 6.0.1
* Author: Opn Payments and contributors
* Author URI: https://github.com/omise/omise-woocommerce/graphs/contributors
* Text Domain: omise
Expand All @@ -23,7 +23,7 @@ class Omise
*
* @var string
*/
public $version = '6.0.0';
public $version = '6.0.1';

/**
* The Omise Instance.
Expand Down
8 changes: 7 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, woocommerce payment
Requires at least: 4.3.1
Tested up to: 6.6.2
Stable tag: 6.0.0
Stable tag: 6.0.1
License: MIT
License URI: https://opensource.org/licenses/MIT

Expand Down Expand Up @@ -34,6 +34,12 @@ From there:

== Changelog ==

= 6.0.1 =

- Resolve issue of payment failing on installment when total amount is updated after selecting payment. (PR: [#485](https://github.com/omise/omise-woocommerce/pull/485))
- Fix Duitnow bank list issue. (PR: [#486](https://github.com/omise/omise-woocommerce/pull/486))
- Resolve the issue where no payment methods are displayed when the browser's back button is clicked from an issuer page. (PR: [#487](https://github.com/omise/omise-woocommerce/pull/487))

= 6.0.0 =

- Support WooCommerce block. (PR: [#470](https://github.com/omise/omise-woocommerce/pull/470))
Expand Down
1 change: 1 addition & 0 deletions templates/payment/form-installment.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
if ( ! empty( $viewData['installments_enabled'] ) ) : ?>
<div id="omise-installment" style="width:100%; max-width: 400px;"></div>
<script>
window.OMISE_UPDATED_CART_AMOUNT= `<?php echo $viewData['total_amount']; ?>`;
window.LOCALE = `<?php echo get_locale(); ?>`;
window.OMISE_CUSTOM_FONT_OTHER = 'Other';
</script>
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/includes/blocks/gateways/traits/mock-gateways.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public function get_view_data() {
'currency' => 'thb',
];
}

public function get_bank_list() {
return [
'bank1',
'bank2',
];
}
};

$gateway->backend = new class {
Expand Down
Loading

0 comments on commit b653a46

Please sign in to comment.