From d55b49117a030daff77efa54d83c56ae95704970 Mon Sep 17 00:00:00 2001 From: Makoto Mizukami Date: Fri, 31 May 2024 17:36:04 +0900 Subject: [PATCH 1/3] Prevent hosted fields being rendered only for descriptions in shortcodes --- includes/class-wc-gateway-komoju-single-slug.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/includes/class-wc-gateway-komoju-single-slug.php b/includes/class-wc-gateway-komoju-single-slug.php index 4072163..4ac375e 100644 --- a/includes/class-wc-gateway-komoju-single-slug.php +++ b/includes/class-wc-gateway-komoju-single-slug.php @@ -63,6 +63,14 @@ public function __construct($payment_method) parent::__construct(); + // Gimmick - + // If fields should not be rendered honour user-defined descriptions only + // This prevents fields to be rendered if 1) the description of the corresponding payment method is empty, and either 2a) publishable key is unavailable or 2b) inline fields are opted out in payment method settings + // This counters a non-intuitive behaviour in WC (https://github.com/woocommerce/woocommerce/blob/5dd7713346786c5874615b34a1d56f81a29b673f/plugins/woocommerce/templates/checkout/payment-method.php#L28) + if (!$this->has_fields) { + $this->description = $this->get_option('description'); + } + $this->method_description = sprintf( __('%s payments powered by KOMOJU', 'komoju-woocommerce'), $this->default_title() From f41ecb216f041e32a7c709d673529304d9e42257 Mon Sep 17 00:00:00 2001 From: Makoto Mizukami Date: Fri, 31 May 2024 17:36:36 +0900 Subject: [PATCH 2/3] Honour has_fields also in blocks --- includes/class-wc-gateway-komoju-block.php | 1 + includes/js/komoju-checkout-blocks.js | 25 ++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/includes/class-wc-gateway-komoju-block.php b/includes/class-wc-gateway-komoju-block.php index 2559d1f..7b9ada6 100644 --- a/includes/class-wc-gateway-komoju-block.php +++ b/includes/class-wc-gateway-komoju-block.php @@ -68,6 +68,7 @@ public function get_payment_method_data() 'session' => json_encode($checkout_session), 'paymentType' => $this->gateway->payment_method['type_slug'], 'locale' => $this->gateway->locale, + 'inlineFields' => $this->gateway->has_fields, ]; } } diff --git a/includes/js/komoju-checkout-blocks.js b/includes/js/komoju-checkout-blocks.js index 119b0ee..a29e4cf 100644 --- a/includes/js/komoju-checkout-blocks.js +++ b/includes/js/komoju-checkout-blocks.js @@ -5,16 +5,19 @@ const KomojuPaymentModule = (() => { 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 = + settings.inlineFields + ? 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' }, + }) + : null; const label = createElement('div', { style: { display: 'block', alignItems: 'center', justifyContent: 'center', width: '100%' } @@ -110,4 +113,4 @@ const KomojuPaymentModule = (() => { }; })(); -KomojuPaymentModule.init(); \ No newline at end of file +KomojuPaymentModule.init(); From 8e276f725f1d6b34efc3f044d86342b7ec2719c3 Mon Sep 17 00:00:00 2001 From: Makoto Mizukami Date: Tue, 11 Jun 2024 11:35:36 +0900 Subject: [PATCH 3/3] Fix tests; navigate through admin pages based on URLs --- tests/cypress/e2e/admin.cy.js | 4 ++-- tests/cypress/e2e/checkout.cy.js | 8 ++++---- tests/cypress/support/commands.js | 6 +++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/cypress/e2e/admin.cy.js b/tests/cypress/e2e/admin.cy.js index a74c895..cd5d515 100644 --- a/tests/cypress/e2e/admin.cy.js +++ b/tests/cypress/e2e/admin.cy.js @@ -14,13 +14,13 @@ describe('KOMOJU for WooCommerce: Admin', () => { it('lets me add and remove specialized payment gateways', () => { cy.setupKomoju(['konbini', 'credit_card']); - cy.contains('Payments').click(); + cy.clickPaymentTab(); cy.get('.form-table').should('include.text', 'Komoju - Konbini'); cy.get('.form-table').should('include.text', 'Komoju - Credit Card'); cy.setupKomoju(['paypay', 'linepay']); - cy.contains('Payments').click(); + cy.clickPaymentTab(); cy.get('.form-table').should('not.include.text', 'Komoju - Konbini'); cy.get('.form-table').should('not.include.text', 'Komoju - Credit Card'); diff --git a/tests/cypress/e2e/checkout.cy.js b/tests/cypress/e2e/checkout.cy.js index 5a60bc4..6da7f9b 100644 --- a/tests/cypress/e2e/checkout.cy.js +++ b/tests/cypress/e2e/checkout.cy.js @@ -10,7 +10,7 @@ describe('KOMOJU for WooCommerce: Checkout', () => { it('lets me make a payment using the specialized konbini gateway', () => { cy.setupKomoju(['konbini', 'credit_card']); - cy.contains('Payments').click(); + cy.clickPaymentTab(); cy.enablePaymentGateway('komoju_konbini'); cy.goToStore(); cy.addItemAndProceedToCheckout(); @@ -38,7 +38,7 @@ describe('KOMOJU for WooCommerce: Checkout', () => { it('lets me make a payment using the specialized credit card gateway', () => { cy.setupKomoju(['credit_card']); - cy.contains('Payments').click(); + cy.clickPaymentTab(); cy.enablePaymentGateway('komoju_credit_card'); cy.contains('Save changes').click(); cy.goToStore(); @@ -62,7 +62,7 @@ describe('KOMOJU for WooCommerce: Checkout', () => { it('lets me use the specialized WebMoney gateway, despite it being unsupported by Fields', () => { cy.setupKomoju(['credit_card', 'konbini', 'web_money']); - cy.contains('Payments').click(); + cy.clickPaymentTab(); cy.enablePaymentGateway('komoju_web_money'); cy.contains('Save changes').click(); cy.goToStore(); @@ -83,7 +83,7 @@ describe('KOMOJU for WooCommerce: Checkout', () => { it('lets me turn checkout icons on and off', () => { cy.setupKomoju(['konbini', 'credit_card']); - cy.contains('Payments').click(); + cy.clickPaymentTab(); cy.enablePaymentGateway('komoju_credit_card'); cy.get('[data-gateway_id="komoju_credit_card"] a.button') diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index d932b5c..71599ac 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -204,4 +204,8 @@ Cypress.Commands.add('addItemAndProceedToCheckout', () => { cy.wait(100); cy.contains('Go to checkout').click(); cy.wait(100); -}); \ No newline at end of file +}); + +Cypress.Commands.add('clickPaymentTab', () => { + cy.visit('/wp-admin/admin.php?page=wc-settings&tab=checkout'); +});