Skip to content

Commit

Permalink
Merge branch 'T3MjfsEy' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanPetakNeuralab committed Oct 22, 2024
2 parents 66e21a2 + 68e168a commit 3d908b8
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 11 deletions.
20 changes: 20 additions & 0 deletions assets/src/js/kekspay-blocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const settings = window.wc.wcSettings.getSetting( kekspayBlocksData.kekspayID + '_data', {} );
const label = window.wp.htmlEntities.decodeEntities( settings.title );

const Content = () => {
return window.wp.htmlEntities.decodeEntities( settings.description );
};

const Kekspay_Gateway = {
name: kekspayBlocksData.kekspayID,
label: label,
content: Object( window.wp.element.createElement )( Content, null ),
edit: Object( window.wp.element.createElement )( Content, null ),
canMakePayment: () => true,
ariaLabel: label,
supports: {
features: settings.supports,
},
};

window.wc.wcBlocksRegistry.registerPaymentMethod( Kekspay_Gateway );
1 change: 1 addition & 0 deletions assets/src/scss/kekspay.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
}

.kekspay-logo {
display: block;
width: 300px;
height: 129px;
margin: 0 auto;
Expand Down
50 changes: 50 additions & 0 deletions includes/core/class-kekspay-block-checkout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;

final class Kekspay_Block_Checkout extends AbstractPaymentMethodType {
private $gateway;

protected $name = KEKSPAY_PLUGIN_ID;

public function initialize() {
$this->settings = Kekspay_Data::get_settings();
$this->gateway = Kekspay_Payment_Gateway::get_instance();
}

public function is_active() {
return $this->gateway->is_available();
}

public function get_payment_method_script_handles() {
wp_register_script(
'kekspay-blocks-script',
KEKSPAY_DIR_URL . 'assets/dist/js/kekspay-blocks.js',
[
'wc-blocks-registry',
'wc-settings',
'wp-element',
'wp-html-entities',
'wp-i18n',
],
KEKSPAY_PLUGIN_VERSION,
true
);

wp_localize_script(
'kekspay-blocks-script',
'kekspayBlocksData',
[
'kekspayID' => KEKSPAY_PLUGIN_ID,
]
);

return [ 'kekspay-blocks-script' ];
}

public function get_payment_method_data() {
return [
'title' => $this->gateway->method_title,
'description' => $this->gateway->method_description,
];
}
}
25 changes: 24 additions & 1 deletion includes/core/class-kekspay-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
* Kekspay_Payment_Gateway class
*/
class Kekspay_Payment_Gateway extends WC_Payment_Gateway {
/**
* Instance of the current class, null before first usage.
*
* @var WC_Kekspay
*/
protected static $instance = null;

/**
* App data handler.
Expand Down Expand Up @@ -42,14 +48,19 @@ public function __construct() {
$this->title = esc_attr( Kekspay_Data::get_settings( 'title' ) );

$this->add_hooks();

self::$instance = $this;
}

/**
* Register different hooks.
*/
private function add_hooks() {
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, [ $this, 'process_admin_options' ] );
add_action( 'woocommerce_receipt_' . $this->id, [ $this, 'do_receipt_page' ] );

if ( ! self::$instance ) {
add_action( 'woocommerce_receipt_' . $this->id, [ $this, 'do_receipt_page' ] );
}
}

/**
Expand Down Expand Up @@ -217,5 +228,17 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) {
return Kekspay_Connector::refund( $order, $amount );
}

/**
* Return class instance.
*
* @static
* @return Kekspay_Payment_Gateway
*/
public static function get_instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
}
}
2 changes: 1 addition & 1 deletion includes/utilities/class-kekspay-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static function test_mode() {
self::load_settings();
}

return 'yes' === self::$settings['in-test-mode'];
return isset( self::$settings['in-test-mode'] ) && 'yes' === self::$settings['in-test-mode'];
}

/**
Expand Down
7 changes: 5 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Contributors: erstebank
Tags: kekspay, woocommerce, gateway, payment
Requires at least: 6.3
Tested up to: 6.5
Tested up to: 6.6
Requires PHP: 7.4
Stable tag: 2.0.0
Stable tag: 2.1.0
License: GPL v3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -49,6 +49,9 @@ For more installation options check the [official WordPress documentation](https

== Changelog ==

= 2.1.0 =
* Add WooCommerce checkout blocks support.

= 2.0.0 =
* Drop PHP 7.2 support.

Expand Down
1 change: 1 addition & 0 deletions webpack.mix.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ if (!mix.inProduction()) {
}

mix.setPublicPath("./"); // set because of this issue: https://github.com/JeffreyWay/laravel-mix/issues/1126
mix.js("assets/src/js/kekspay-blocks.js", "assets/dist/js/kekspay-blocks.js");
mix.js("assets/src/js/kekspay-admin.js", "assets/dist/js/kekspay-admin.js");
mix.js("assets/src/js/kekspay.js", "assets/dist/js/kekspay.js");

Expand Down
35 changes: 28 additions & 7 deletions woocommerce-gateway-kekspay.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: KEKS Pay for WooCommerce
* Plugin URI: https://www.kekspay.hr/
* Description: Incredibly fast and user friendly payment method created by Erste Bank Croatia.
* Version: 2.0.0
* Version: 2.1.0
* Requires at least: 6.3
* Requires PHP: 7.4
* Author: Erste bank Croatia
Expand All @@ -14,7 +14,7 @@
* Domain Path: /languages
*
* WC requires at least: 8.2
* WC tested up to: 8.8
* WC tested up to: 9.3
*/

if ( ! defined( 'ABSPATH' ) ) {
Expand Down Expand Up @@ -51,17 +51,19 @@ function kekspay_admin_notice_missing_woocommerce() {
}

/**
* Declare Kekspay plugin compatible with HPOS.
* Declare Kekspay plugin compatibility for certain WooCommerce features:
* - HPOS
* - Checkout Blocks
*
* @return void
*/
function kekspay_hpos_compatible() {
function kekspay_wc_features_compatibility() {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', __FILE__, true );
}
}
add_action( 'before_woocommerce_init', 'kekspay_hpos_compatible' );

add_action( 'before_woocommerce_init', 'kekspay_wc_features_compatibility' );

if ( ! class_exists( 'WC_Kekspay' ) ) {
/**
Expand Down Expand Up @@ -106,6 +108,7 @@ protected function __construct() {
add_action( 'admin_init', [ $this, 'check_for_other_kekspay_gateways' ], 1 );
add_action( 'activated_plugin', [ $this, 'set_kekspay_plugins_check_required' ] );
add_action( 'woocommerce_admin_field_payment_gateways', [ $this, 'set_kekspay_plugins_check_required' ] );
add_action( 'woocommerce_blocks_loaded', [ $this, 'register_checkout_block_gateway' ] );
}

/**
Expand All @@ -116,7 +119,7 @@ public static function register_constants() {
define( 'KEKSPAY_PLUGIN_ID', 'erste-kekspay-woocommerce' );
}
if ( ! defined( 'KEKSPAY_PLUGIN_VERSION' ) ) {
define( 'KEKSPAY_PLUGIN_VERSION', '2.0.0' );
define( 'KEKSPAY_PLUGIN_VERSION', '2.1.0' );
}
if ( ! defined( 'KEKSPAY_DIR_PATH' ) ) {
define( 'KEKSPAY_DIR_PATH', plugin_dir_path( __FILE__ ) );
Expand Down Expand Up @@ -243,6 +246,24 @@ public static function set_kekspay_plugins_check_required() {
update_option( 'kekspay_plugins_check_required', 'yes' );
}

/**
* Register Kekspay method for block checkout.
*/
public function register_checkout_block_gateway() {
if ( ! class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
return;
}

require_once KEKSPAY_DIR_PATH . 'includes/core/class-kekspay-block-checkout.php';

add_action(
'woocommerce_blocks_payment_method_type_registration',
function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) {
$payment_method_registry->register( new Kekspay_Block_Checkout() );
}
);
}

/**
* Deactivate plugin.
*/
Expand Down

0 comments on commit 3d908b8

Please sign in to comment.