diff --git a/includes/class-wc-gateway-komoju-block.php b/includes/class-wc-gateway-komoju-block.php index 7b9ada6..572755e 100644 --- a/includes/class-wc-gateway-komoju-block.php +++ b/includes/class-wc-gateway-komoju-block.php @@ -45,10 +45,6 @@ public function get_payment_method_script_handles() public function get_payment_method_data() { - if (!is_checkout()) { - return; - } - // We lazily fetch one session to be shared by all payment methods with dynamic fields. static $checkout_session; if (is_null($checkout_session)) { diff --git a/includes/class-wc-gateway-komoju-ipn-handler.php b/includes/class-wc-gateway-komoju-ipn-handler.php index 5b11074..1fa256f 100644 --- a/includes/class-wc-gateway-komoju-ipn-handler.php +++ b/includes/class-wc-gateway-komoju-ipn-handler.php @@ -221,7 +221,8 @@ protected function payment_status_captured($order, $webhookEvent) if (!empty($webhookEvent->payment_method_fee())) { // log komoju transaction fee - update_post_meta($order->get_id(), 'Payment Gateway Transaction Fee', wc_clean($webhookEvent->payment_method_fee())); + $order->update_meta_data('Payment Gateway Transaction Fee', wc_clean($webhookEvent->payment_method_fee())); + $order->save(); } } else { $this->payment_on_hold($order, sprintf(__('Payment pending: %s', 'komoju-woocommerce'), $webhookEvent->additional_information())); @@ -343,16 +344,17 @@ private function get_session($session_id) protected function save_komoju_meta_data($order, $webhookEvent) { if (!empty($webhookEvent->tax())) { - update_post_meta($order->get_id(), 'Tax', wc_clean($webhookEvent->tax())); + $order->update_meta_data('Tax', wc_clean($webhookEvent->tax())); } if (!empty($webhookEvent->amount())) { - update_post_meta($order->get_id(), 'Amount', wc_clean($webhookEvent->amount())); + $order->update_meta_data('Amount', wc_clean($webhookEvent->amount())); } if (!empty($webhookEvent->additional_information())) { - update_post_meta($order->get_id(), 'Additional info', wc_clean(print_r($webhookEvent->additional_information(), true))); + $order->update_meta_data('Additional info', wc_clean(print_r($webhookEvent->additional_information(), true))); } if (!empty($webhookEvent->uuid())) { - $order->add_meta_data('komoju_payment_id', $webhookEvent->uuid(), true); + $order->update_meta_data('komoju_payment_id', $webhookEvent->uuid(), true); } + $order->save(); } } diff --git a/includes/class-wc-gateway-komoju-single-slug.php b/includes/class-wc-gateway-komoju-single-slug.php index 4ac375e..c5c45ae 100644 --- a/includes/class-wc-gateway-komoju-single-slug.php +++ b/includes/class-wc-gateway-komoju-single-slug.php @@ -140,6 +140,10 @@ public function create_session_for_fields() ], ]; + if ($this->get_order_total() == 0) { + return null; + } + return $komoju_api->createSession($session_params); } diff --git a/index.php b/index.php index eb31b07..8e93431 100755 --- a/index.php +++ b/index.php @@ -1,12 +1,21 @@ { beforeEach(() => { cy.installWordpress(); - cy.signinToWordpress(); - cy.installWooCommerce(); - cy.installKomoju(); - - cy.visit('/wp-admin/admin.php?page=wc-settings&tab=komoju_settings§ion=api_settings'); - cy.get('.komoju-endpoint-field').contains('Reset').click(); - cy.contains('Save changes').click(); + cy.signinToWordpress().then(() => { + cy.installWooCommerce(); + cy.installKomoju(); + + cy.visit('/wp-admin/admin.php?page=wc-settings&tab=komoju_settings§ion=api_settings'); + cy.get('.komoju-endpoint-field').contains('Reset').click(); + cy.contains('Save changes').click(); + }); }) it('lets me add and remove specialized payment gateways', () => { @@ -49,8 +50,8 @@ describe('KOMOJU for WooCommerce: Admin', () => { it('updates secret key with one-click setup', () => { cy.visit('/wp-admin/admin.php?page=wc-settings&tab=komoju_settings§ion=api_settings'); - cy.get('#komoju_woocommerce_secret_key').type('{selectAll}{backspace}'); - cy.get('#komoju_woocommerce_webhook_secret').type('{selectAll}{backspace}'); + cy.get('#komoju_woocommerce_secret_key').clear(); + cy.get('#komoju_woocommerce_webhook_secret').clear(); cy.contains('Save changes').click(); cy.contains('Payment methods').click(); diff --git a/tests/cypress/e2e/checkout.cy.js b/tests/cypress/e2e/checkout.cy.js index 61306d8..221a1e2 100644 --- a/tests/cypress/e2e/checkout.cy.js +++ b/tests/cypress/e2e/checkout.cy.js @@ -3,9 +3,10 @@ describe('KOMOJU for WooCommerce: Checkout', () => { beforeEach(() => { cy.installWordpress(); - cy.signinToWordpress(); - cy.installWooCommerce(); - cy.installKomoju(); + cy.signinToWordpress().then(() => { + cy.installWooCommerce(); + cy.installKomoju(); + }); }) it('lets me make a payment using the specialized konbini gateway', () => { @@ -33,6 +34,7 @@ describe('KOMOJU for WooCommerce: Checkout', () => { cy.contains('How to make a payment at Family Mart', { matchCase: false, timeout: 20000 }).should('be.visible'); cy.location('pathname').should('include', '/sessions/'); cy.contains('Return to').click(); + cy.wait(1000); cy.contains('Thank you. Your order has been received.').should('be.visible'); }) diff --git a/tests/cypress/e2e/refunded-webhook.cy.js b/tests/cypress/e2e/refunded-webhook.cy.js index b73d54a..0953d26 100644 --- a/tests/cypress/e2e/refunded-webhook.cy.js +++ b/tests/cypress/e2e/refunded-webhook.cy.js @@ -3,9 +3,10 @@ describe("KOMOJU for WooCommerce: Refunded webhook", () => { beforeEach(() => { cy.installWordpress(); - cy.signinToWordpress(); - cy.installWooCommerce(); - cy.installKomoju(); + cy.signinToWordpress().then(() => { + cy.installWooCommerce(); + cy.installKomoju(); + }); }); it("sets an order as a refunded based on incoming refunded webhook", () => { diff --git a/tests/cypress/support/commands.js b/tests/cypress/support/commands.js index 71599ac..b826252 100644 --- a/tests/cypress/support/commands.js +++ b/tests/cypress/support/commands.js @@ -39,10 +39,10 @@ Cypress.Commands.add('installWordpress', () => { cy.contains('English (United States)').click(); cy.get('#language-continue').click(); - cy.get('#weblog_title').type('Degica Mart').type('{selectAll}Degica Mart'); - cy.get('#user_login').type('degica'); - cy.get('#pass1').type('{selectAll}deg1kaX7reme!'); - cy.get('#admin_email').type('dev@degica.com'); + cy.get('#weblog_title').clear().type('Degica Mart'); + cy.get('#user_login').clear().type('degica'); + cy.get('#pass1').clear().type('deg1kaX7reme!'); + cy.get('#admin_email').clear().type('dev@degica.com'); cy.get('#submit').click(); }); }); @@ -50,20 +50,16 @@ Cypress.Commands.add('installWordpress', () => { Cypress.Commands.add('signinToWordpress', () => { cy.visit('/wp-admin'); - cy.window().then(win => { - if (!win.document.querySelector('#loginform')) { + cy.get('body').then(($body) => { + if (!$body.find('#loginform').length) { cy.log('Already logged in'); return; } cy.log('Logging in'); - - cy.get('#user_login').type('degica').type('{selectAll}degica'); - cy.wait(100); - cy.get('#user_pass').type('deg1kaX7reme!'); - cy.wait(100); - cy.get('#wp-submit').click(); + cy.get('#user_login').should('be.visible').clear().type('degica'); + cy.get('#user_pass').should('be.visible').clear().type('deg1kaX7reme!'); + cy.get('#wp-submit').should('be.visible').click(); }); - cy.wait(1000); }); Cypress.Commands.add('installWooCommerce', () => { @@ -112,13 +108,13 @@ Cypress.Commands.add('setupKomoju', ( ) => { cy.visit('/wp-admin/admin.php?page=wc-settings&tab=komoju_settings§ion=api_settings'); - cy.get('#komoju_woocommerce_secret_key').type('{selectAll}').type(secretKey); - cy.get('#komoju_woocommerce_publishable_key').type('{selectAll}').type(publishableKey); + cy.get('#komoju_woocommerce_secret_key').clear().type(secretKey); + cy.get('#komoju_woocommerce_publishable_key').clear().type(publishableKey); cy.get('.komoju-endpoint-komoju_woocommerce_fields_url').then($element => { const $edit = $element.find('.komoju-endpoint-edit'); if ($edit.length > 0) { return cy.wrap($edit).click(); } }); - cy.get('#komoju_woocommerce_fields_url').type('{selectAll}').type('https://multipay-staging.test.komoju.com/fields.js'); + cy.get('#komoju_woocommerce_fields_url').clear().type('https://multipay-staging.test.komoju.com/fields.js'); cy.contains('Save changes').click(); cy.contains('Payment methods').click(); @@ -150,14 +146,14 @@ Cypress.Commands.add('goToStore', () => { }); Cypress.Commands.add('fillInAddress', () => { - cy.get('#billing-last_name').type('{selectAll}Johnson'); - cy.get('#billing-first_name').type('{selectAll}Test'); + cy.get('#billing-last_name').clear().type('Johnson'); + cy.get('#billing-first_name').clear().type('Test'); cy.get('#billing-country').find('#components-form-token-input-0').type('Japan').first().click(); cy.get('#billing-state').find('input').type('Tokyo').first().click(); - cy.get('#billing-postcode').type('{selectAll}180-0004'); - cy.get('#billing-city').type('Musashino'); - cy.get('#billing-address_1').type('address'); - cy.get('#billing-phone').type('{selectAll}123123213213213'); + cy.get('#billing-postcode').clear().type('180-0004'); + cy.get('#billing-city').clear().type('Musashino'); + cy.get('#billing-address_1').clear().type('address'); + cy.get('#billing-phone').clear().type('123123213213213'); }); Cypress.Commands.add('iframe', { prevSubject: 'element' }, ($iframe) => { @@ -200,10 +196,8 @@ Cypress.Commands.add('addItemAndProceedToCheckout', () => { } }); - cy.get('.wc-block-mini-cart__button').click(); - cy.wait(100); - cy.contains('Go to checkout').click(); - cy.wait(100); + cy.get('.wc-block-mini-cart__button').should('be.visible').click(); + cy.contains('Go to checkout').should('be.visible').click(); }); Cypress.Commands.add('clickPaymentTab', () => { diff --git a/tests/cypress/support/e2e.js b/tests/cypress/support/e2e.js index c635e79..35bc334 100644 --- a/tests/cypress/support/e2e.js +++ b/tests/cypress/support/e2e.js @@ -22,5 +22,7 @@ import './commands' Cypress.on('uncaught:exception', (err, runnable) => { // Ignore the error if it's from a specific source if (err.message.includes('@wordpress/interactivity')) return false; + // Ignore postMessage errors + if (err.message.includes('postMessage')) return false; return true; }) \ No newline at end of file diff --git a/tests/package-lock.json b/tests/package-lock.json index 1021267..00c593d 100644 --- a/tests/package-lock.json +++ b/tests/package-lock.json @@ -5,7 +5,7 @@ "packages": { "": { "dependencies": { - "cypress": "*" + "cypress": "^13.13.1" } }, "node_modules/@colors/colors": { @@ -201,10 +201,6 @@ "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.12.0.tgz", "integrity": "sha512-NmWvPnx0F1SfrQbYwOi7OeaNGokp9XhzNioJ/CSBs8Qa4vxug81mhJEAVZwxXuBmYB5KDRfMq/F3RR0BIU7sWg==" }, - "node_modules/balanced-match": { - "version": "1.0.2", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" - }, "node_modules/base64-js": { "version": "1.5.1", "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", @@ -239,14 +235,6 @@ "version": "3.7.2", "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==" }, - "node_modules/brace-expansion": { - "version": "1.1.11", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, "node_modules/buffer": { "version": "5.7.1", "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", @@ -429,10 +417,6 @@ "node": ">=4.0.0" } }, - "node_modules/concat-map": { - "version": "0.0.1", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" - }, "node_modules/core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", @@ -451,9 +435,9 @@ } }, "node_modules/cypress": { - "version": "13.9.0", - "resolved": "https://registry.npmjs.org/cypress/-/cypress-13.9.0.tgz", - "integrity": "sha512-atNjmYfHsvTuCaxTxLZr9xGoHz53LLui3266WWxXJHY7+N6OdwJdg/feEa3T+buez9dmUXHT1izCOklqG82uCQ==", + "version": "13.13.1", + "resolved": "https://registry.npmjs.org/cypress/-/cypress-13.13.1.tgz", + "integrity": "sha512-8F9UjL5MDUdgC/S5hr8CGLHbS5gGht5UOV184qc2pFny43fnkoaKxlzH/U6//zmGu/xRTaKimNfjknLT8+UDFg==", "hasInstallScript": true, "dependencies": { "@cypress/request": "^3.0.0", @@ -495,7 +479,7 @@ "request-progress": "^3.0.0", "semver": "^7.5.3", "supports-color": "^8.1.1", - "tmp": "~0.2.1", + "tmp": "~0.2.3", "untildify": "^4.0.0", "yauzl": "^2.10.0" }, @@ -741,10 +725,6 @@ "node": ">=10" } }, - "node_modules/fs.realpath": { - "version": "1.0.0", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" - }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", @@ -799,24 +779,6 @@ "assert-plus": "^1.0.0" } }, - "node_modules/glob": { - "version": "7.2.3", - "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.1.1", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/global-dirs": { "version": "3.0.0", "integrity": "sha512-v8ho2DS5RiCjftj1nD9NmnfaOzTdud7RRnVd9kFNOjqZbISlx5DQ+OrTkywgd0dIt7oFCvKetZSHoHcP3sDdiA==", @@ -941,18 +903,6 @@ "node": ">=8" } }, - "node_modules/inflight": { - "version": "1.0.6", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dependencies": { - "once": "^1.3.0", - "wrappy": "1" - } - }, - "node_modules/inherits": { - "version": "2.0.4", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" - }, "node_modules/ini": { "version": "2.0.0", "integrity": "sha512-7PnF4oN3CvZF23ADhA5wRaYEQpJ8qygSkbtTXWBeXWXmEVRXK+1ITciHWwHhsjv1TmW0MgacIv6hEi5pX5NQdA==", @@ -1198,16 +1148,6 @@ "node": ">=6" } }, - "node_modules/minimatch": { - "version": "3.1.2", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, "node_modules/minimist": { "version": "1.2.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", @@ -1275,13 +1215,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/path-is-absolute": { - "version": "1.0.1", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/path-key": { "version": "3.1.1", "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", @@ -1394,19 +1327,6 @@ "version": "1.3.0", "integrity": "sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA==" }, - "node_modules/rimraf": { - "version": "3.0.2", - "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "dependencies": { - "glob": "^7.1.3" - }, - "bin": { - "rimraf": "bin.js" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/rxjs": { "version": "7.5.5", "integrity": "sha512-sy+H0pQofO95VDmFLzyaw9xNJU4KTRSwQIGM6+iG3SypAtCiLDzpeG8sJrNCWn2Up9km+KhkvTdbkrdy+yzZdw==", @@ -1590,13 +1510,11 @@ "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=" }, "node_modules/tmp": { - "version": "0.2.1", - "integrity": "sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==", - "dependencies": { - "rimraf": "^3.0.0" - }, + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.3.tgz", + "integrity": "sha512-nZD7m9iCPC5g0pYmcaxogYKggSfLsdxl8of3Q/oIbqCqLLIO9IAF0GWjX1z9NZRHPiXv8Wex4yDCaZsgEw0Y8w==", "engines": { - "node": ">=8.17.0" + "node": ">=14.14" } }, "node_modules/tough-cookie": { diff --git a/tests/package.json b/tests/package.json index ba74165..ec8ed6e 100644 --- a/tests/package.json +++ b/tests/package.json @@ -1,5 +1,5 @@ { "dependencies": { - "cypress": "*" + "cypress": "^13.13.1" } }