From ebdb4cbcaa59856cde9ca64e01b2838acee417dc Mon Sep 17 00:00:00 2001 From: Dinwy Date: Thu, 23 May 2024 12:43:54 +0900 Subject: [PATCH 1/4] Fix plugin conflicts in 3.1.0 --- includes/js/komoju-checkout-blocks.js | 190 ++++++++++++++------------ index.php | 23 ++-- 2 files changed, 109 insertions(+), 104 deletions(-) diff --git a/includes/js/komoju-checkout-blocks.js b/includes/js/komoju-checkout-blocks.js index 7ed9a94..119b0ee 100644 --- a/includes/js/komoju-checkout-blocks.js +++ b/includes/js/komoju-checkout-blocks.js @@ -1,105 +1,113 @@ -const { useEffect, useCallback, useRef, createElement } = window.wp.element; +const KomojuPaymentModule = (() => { + const { useEffect, useCallback, useRef, createElement } = window.wp.element; -function registerPaymentMethod(paymentMethod) { - let name = `${paymentMethod.id}` - const settings = window.wc.wcSettings.getSetting(`${name}_data`, {}); + function registerPaymentMethod(paymentMethod) { + let name = `${paymentMethod.id}` + const settings = window.wc.wcSettings.getSetting(`${name}_data`, {}); - const komojuFields = createElement('komoju-fields', { - 'token': '', - 'name': 'komoju_payment_token', - 'komoju-api': settings.komojuApi, - 'publishable-key': settings.publishableKey, - 'session': settings.session, - 'payment-type': settings.paymentType, - 'locale': settings.locale, - style: { display: 'none' }, - }); + const komojuFields = createElement('komoju-fields', { + 'token': '', + 'name': 'komoju_payment_token', + 'komoju-api': settings.komojuApi, + 'publishable-key': settings.publishableKey, + 'session': settings.session, + 'payment-type': settings.paymentType, + 'locale': settings.locale, + style: { display: 'none' }, + }); - const label = createElement('div', { - style: { display: 'block', alignItems: 'center', justifyContent: 'center', width: '100%' } - }, - window.wp.htmlEntities.decodeEntities(settings.title || window.wp.i18n.__('NULL GATEWAY', 'test_komoju_gateway')), - settings.icon ? - createElement('img', { - src: settings.icon, - alt: settings.title || 'Payment Method Icon', - style: { display: 'flex', alignItems: 'center', justifyContent: 'center', marginLeft: '10px' } - }) : null, - komojuFields - ); + const label = createElement('div', { + style: { display: 'block', alignItems: 'center', justifyContent: 'center', width: '100%' } + }, + window.wp.htmlEntities.decodeEntities(settings.title || window.wp.i18n.__('NULL GATEWAY', 'test_komoju_gateway')), + settings.icon ? + createElement('img', { + src: settings.icon, + alt: settings.title || 'Payment Method Icon', + style: { display: 'flex', alignItems: 'center', justifyContent: 'center', marginLeft: '10px' } + }) : null, + komojuFields + ); - const KomojuComponent = ({ activePaymentMethod, emitResponse, eventRegistration }) => { - const { onPaymentSetup } = eventRegistration; - const komojuFieldEnabledMethods = ['komoju_credit_card', 'komoju_konbini', 'komoju_bank_transfer'] + const KomojuComponent = ({ activePaymentMethod, emitResponse, eventRegistration }) => { + const { onPaymentSetup } = eventRegistration; + const komojuFieldEnabledMethods = ['komoju_credit_card', 'komoju_konbini', 'komoju_bank_transfer'] - useEffect(() => { - const komojuField = document.querySelector(`komoju-fields[payment-type='${paymentMethod.paymentType}']`); - komojuField.style.display = 'block'; + useEffect(() => { + const komojuField = document.querySelector(`komoju-fields[payment-type='${paymentMethod.paymentType}']`); + komojuField.style.display = 'block'; - const unsubscribe = onPaymentSetup(async () => { - if (paymentMethod.id != activePaymentMethod) return; - if (!komojuFieldEnabledMethods.includes(paymentMethod.id)) return; + const unsubscribe = onPaymentSetup(async () => { + if (paymentMethod.id != activePaymentMethod) return; + if (!komojuFieldEnabledMethods.includes(paymentMethod.id)) return; - if (!(komojuField || typeof komojuField.submit === 'function')) { - return { - type: emitResponse.responseTypes.ERROR, - message: 'There was an error', - }; - } + if (!(komojuField || typeof komojuField.submit === 'function')) { + return { + type: emitResponse.responseTypes.ERROR, + message: 'There was an error', + }; + } - function submitFields(fields) { - return new Promise(async (resolve, reject) => { - fields.addEventListener("komoju-invalid", reject); - const token = await fields.submit(); - fields.removeEventListener("komoju-invalid", reject); - if (token) resolve(token); - }); - } + function submitFields(fields) { + return new Promise(async (resolve, reject) => { + fields.addEventListener("komoju-invalid", reject); + const token = await fields.submit(); + fields.removeEventListener("komoju-invalid", reject); + if (token) resolve(token); + }); + } - try { - const token = await submitFields(komojuField); - return { - type: emitResponse.responseTypes.SUCCESS, - meta: { - paymentMethodData: { - komoju_payment_token: token.id + try { + const token = await submitFields(komojuField); + return { + type: emitResponse.responseTypes.SUCCESS, + meta: { + paymentMethodData: { + komoju_payment_token: token.id + }, }, - }, - }; - } catch (e) { - return { - type: emitResponse.responseTypes.ERROR, - message: e.detail.errors[0].message, - }; - } - }); + }; + } catch (e) { + return { + type: emitResponse.responseTypes.ERROR, + message: e.detail.errors[0].message, + }; + } + }); - return () => { - komojuField.style.display = 'none'; - unsubscribe(); - }; - }, [ - activePaymentMethod, - emitResponse.responseTypes.ERROR, - emitResponse.responseTypes.SUCCESS - ]); - }; + return () => { + komojuField.style.display = 'none'; + unsubscribe(); + }; + }, [ + activePaymentMethod, + emitResponse.responseTypes.ERROR, + emitResponse.responseTypes.SUCCESS + ]); + }; - const Block_Gateway = { - name: name, - label: label, - content: createElement(KomojuComponent, null), - edit: createElement(KomojuComponent, null), - canMakePayment: () => true, - ariaLabel: settings.title || 'Payment Method', - supports: { - features: settings.supports || ['products'], - }, + const Block_Gateway = { + name: name, + label: label, + content: createElement(KomojuComponent, null), + edit: createElement(KomojuComponent, null), + canMakePayment: () => true, + ariaLabel: settings.title || 'Payment Method', + supports: { + features: settings.supports || ['products'], + }, + }; + window.wc.wcBlocksRegistry.registerPaymentMethod(Block_Gateway); + } + + return { + init: () => { + const paymentMethodData = window.wc.wcSettings.getSetting('paymentMethodData', {}); + Object.values(paymentMethodData).forEach((value) => { + registerPaymentMethod(value); + }); + } }; - window.wc.wcBlocksRegistry.registerPaymentMethod(Block_Gateway); -} +})(); -paymentMethodData = window.wc.wcSettings.getSetting('paymentMethodData', {}); -Object.values(paymentMethodData).forEach((value) => { - registerPaymentMethod(value); -}); +KomojuPaymentModule.init(); \ No newline at end of file diff --git a/index.php b/index.php index ecce7e7..f03cbae 100755 --- a/index.php +++ b/index.php @@ -119,19 +119,16 @@ function register_komoju_payment_method_type() return; } - $gateways = WC()->payment_gateways->payment_gateways(); - - if ($gateways) { - foreach ($gateways as $gateway) { - if ($gateway->enabled == 'yes' && $gateway instanceof WC_Gateway_Komoju_Single_Slug) { - add_action( - 'woocommerce_blocks_payment_method_type_registration', - function (Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry) use ($gateway) { - $payment_method_registry->register(new WC_Gateway_Komoju_Blocks($gateway)); - } - ); + add_action('woocommerce_blocks_payment_method_type_registration', function ($payment_method_registry) { + $gateways = WC()->payment_gateways()->payment_gateways(); + + if ($gateways) { + foreach ($gateways as $gateway) { + if ($gateway->enabled == 'yes' && $gateway instanceof WC_Gateway_Komoju_Single_Slug) { + $payment_method_registry->register(new WC_Gateway_Komoju_Blocks($gateway)); + } } } - } + }); } -} +} \ No newline at end of file From 185ab0619b4c45031304c3b1d2cbf4a6a704fc1e Mon Sep 17 00:00:00 2001 From: Dinwy Date: Thu, 23 May 2024 12:56:49 +0900 Subject: [PATCH 2/4] Update plugin version to 3.1.2 --- class-wc-gateway-komoju.php | 2 +- class-wc-settings-page-komoju.php | 2 +- index.php | 2 +- readme.txt | 4 ++++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/class-wc-gateway-komoju.php b/class-wc-gateway-komoju.php index 446a347..4882b4d 100755 --- a/class-wc-gateway-komoju.php +++ b/class-wc-gateway-komoju.php @@ -12,7 +12,7 @@ * * @extends WC_Payment_Gateway * - * @version 3.1.0 + * @version 3.1.2 * * @author Komoju */ diff --git a/class-wc-settings-page-komoju.php b/class-wc-settings-page-komoju.php index 2410756..70aa9ac 100644 --- a/class-wc-settings-page-komoju.php +++ b/class-wc-settings-page-komoju.php @@ -11,7 +11,7 @@ * * @extends WC_Settings_Page * - * @version 3.1.0 + * @version 3.1.2 * * @author Komoju */ diff --git a/index.php b/index.php index f03cbae..b9e07e2 100755 --- a/index.php +++ b/index.php @@ -3,7 +3,7 @@ Plugin Name: KOMOJU Payments Plugin URI: https://github.com/komoju/komoju-woocommerce Description: Extends WooCommerce with KOMOJU gateway. -Version: 3.1.0 +Version: 3.1.2 Author: KOMOJU Author URI: https://komoju.com */ diff --git a/readme.txt b/readme.txt index 38fa549..c6923b6 100644 --- a/readme.txt +++ b/readme.txt @@ -171,6 +171,10 @@ Go back to your Wordpress instance and set the "Webhook Secret Token" value on t == Changelog == += 3.1.2 = + +Fix plugin conflicts + = 3.1.0 = Updated to use WooCommerce version 8.8.3. Adds a user editable description field. From 03736198bf0370b8753b3e9c7ea41e532e54585c Mon Sep 17 00:00:00 2001 From: Dinwy Date: Thu, 23 May 2024 13:16:31 +0900 Subject: [PATCH 3/4] Fix lint --- index.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index b9e07e2..c722f55 100755 --- a/index.php +++ b/index.php @@ -119,7 +119,9 @@ function register_komoju_payment_method_type() return; } - add_action('woocommerce_blocks_payment_method_type_registration', function ($payment_method_registry) { + add_action( + 'woocommerce_blocks_payment_method_type_registration', + function ($payment_method_registry) { $gateways = WC()->payment_gateways()->payment_gateways(); if ($gateways) { From 2d856685301a5c3da5d6264a2c31f710e91712fc Mon Sep 17 00:00:00 2001 From: Dinwy Date: Thu, 23 May 2024 13:25:49 +0900 Subject: [PATCH 4/4] Fix lint error --- index.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/index.php b/index.php index c722f55..2cd0669 100755 --- a/index.php +++ b/index.php @@ -122,15 +122,15 @@ function register_komoju_payment_method_type() add_action( 'woocommerce_blocks_payment_method_type_registration', function ($payment_method_registry) { - $gateways = WC()->payment_gateways()->payment_gateways(); + $gateways = WC()->payment_gateways()->payment_gateways(); - if ($gateways) { - foreach ($gateways as $gateway) { - if ($gateway->enabled == 'yes' && $gateway instanceof WC_Gateway_Komoju_Single_Slug) { - $payment_method_registry->register(new WC_Gateway_Komoju_Blocks($gateway)); + if ($gateways) { + foreach ($gateways as $gateway) { + if ($gateway->enabled == 'yes' && $gateway instanceof WC_Gateway_Komoju_Single_Slug) { + $payment_method_registry->register(new WC_Gateway_Komoju_Blocks($gateway)); + } } } - } - }); + }); } -} \ No newline at end of file +}