Skip to content

Commit

Permalink
Merge pull request #119 from degica/update/declareCompatibility
Browse files Browse the repository at this point in the history
Update KOMOJU Plugin for WooCommerce Cart Checkout Block & HPOS
  • Loading branch information
Dinwy authored Jul 21, 2024
2 parents 28b8e3c + d504007 commit 9b04920
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 149 deletions.
4 changes: 0 additions & 4 deletions includes/class-wc-gateway-komoju-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
12 changes: 7 additions & 5 deletions includes/class-wc-gateway-komoju-ipn-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -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();
}
}
4 changes: 4 additions & 0 deletions includes/class-wc-gateway-komoju-single-slug.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ public function create_session_for_fields()
],
];

if ($this->get_order_total() == 0) {
return null;
}

return $komoju_api->createSession($session_params);
}

Expand Down
23 changes: 16 additions & 7 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<?php
/*
Plugin Name: KOMOJU Payments
Plugin URI: https://github.com/komoju/komoju-woocommerce
Description: Extends WooCommerce with KOMOJU gateway.
Version: 3.1.3
Author: KOMOJU
Author URI: https://komoju.com
*/
* Plugin Name: KOMOJU Payments
* Plugin URI: https://github.com/komoju/komoju-woocommerce
* Description: Extends WooCommerce with KOMOJU gateway.
* Author: KOMOJU
* Author URI: https://komoju.com
* Version: 3.1.3
* WC requires at least: 6.0
* WC tested up to: 8.8.3
*/

add_action('before_woocommerce_init', function () {
if (class_exists('\Automattic\WooCommerce\Utilities\FeaturesUtil')) {
Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('cart_checkout_blocks', __FILE__, true);
Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
}
});

add_action('plugins_loaded', 'woocommerce_komoju_init', 0);

Expand Down
19 changes: 10 additions & 9 deletions tests/cypress/e2e/admin.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
describe('KOMOJU for WooCommerce: Admin', () => {
beforeEach(() => {
cy.installWordpress();
cy.signinToWordpress();
cy.installWooCommerce();
cy.installKomoju();

cy.visit('/wp-admin/admin.php?page=wc-settings&tab=komoju_settings&section=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&section=api_settings');
cy.get('.komoju-endpoint-field').contains('Reset').click();
cy.contains('Save changes').click();
});
})

it('lets me add and remove specialized payment gateways', () => {
Expand Down Expand Up @@ -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&section=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();
Expand Down
8 changes: 5 additions & 3 deletions tests/cypress/e2e/checkout.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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');
})

Expand Down
7 changes: 4 additions & 3 deletions tests/cypress/e2e/refunded-webhook.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
46 changes: 20 additions & 26 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,27 @@ 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('[email protected]');
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('[email protected]');
cy.get('#submit').click();
});
});

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', () => {
Expand Down Expand Up @@ -112,13 +108,13 @@ Cypress.Commands.add('setupKomoju', (
) => {
cy.visit('/wp-admin/admin.php?page=wc-settings&tab=komoju_settings&section=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();
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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', () => {
Expand Down
2 changes: 2 additions & 0 deletions tests/cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
Loading

0 comments on commit 9b04920

Please sign in to comment.