diff --git a/assets/js/sslcommerz-blocks.js b/assets/js/sslcommerz-blocks.js new file mode 100644 index 0000000..70a1a64 --- /dev/null +++ b/assets/js/sslcommerz-blocks.js @@ -0,0 +1,81 @@ +/** + * SSLCommerz Payment Gateway - WooCommerce Blocks Integration + * + * @package SSLCommerz_Woocommerce + * @since 6.3.0 + */ + +(function() { + 'use strict'; + + const { registerPaymentMethod } = window.wc.wcBlocksRegistry; + const { getSetting } = window.wc.wcSettings; + const { decodeEntities } = window.wp.htmlEntities; + const { createElement } = window.wp.element; + + const settings = getSetting('sslcommerz_data', {}); + + const defaultLabel = 'SSLCommerz'; + const label = decodeEntities(settings.title) || defaultLabel; + + /** + * Content component - displays the payment method description + */ + const Content = () => { + const description = decodeEntities(settings.description || ''); + + return createElement( + 'div', + { className: 'sslcommerz-payment-description' }, + description + ); + }; + + /** + * Label component - displays the payment method title with icon + */ + const Label = (props) => { + const { PaymentMethodLabel } = props.components; + + const iconUrl = settings.icon || ''; + + return createElement( + 'span', + { className: 'sslcommerz-payment-label' }, + createElement(PaymentMethodLabel, { text: label }), + iconUrl && createElement( + 'img', + { + src: iconUrl, + alt: label, + style: { + maxWidth: '80px', + maxHeight: '24px', + marginLeft: '10px', + verticalAlign: 'middle', + display: 'inline-block' + } + } + ) + ); + }; + + /** + * SSLCommerz payment method configuration for WooCommerce Blocks + */ + const SSLCommerzPaymentMethod = { + name: 'sslcommerz', + label: createElement(Label, null), + content: createElement(Content, null), + edit: createElement(Content, null), + canMakePayment: () => true, + ariaLabel: label, + supports: { + features: settings.supports || ['products'], + }, + }; + + // Register the payment method with WooCommerce Blocks + registerPaymentMethod(SSLCommerzPaymentMethod); + +})(); diff --git a/easyCheckout.php b/easyCheckout.php index bfc68d3..8ffc8ef 100644 --- a/easyCheckout.php +++ b/easyCheckout.php @@ -3,9 +3,9 @@ * Plugin Name: SSLCommerz Payment Gateway * Plugin URI: https://sslcommerz.com/ * Description: This plugin allows you to accept payments on your WooCommerce store from customers using Visa Cards, Master cards, American Express etc. Via SSLCommerz payment gateway with new V4 API & both Hosted & Popup. -* Version: 6.2.0 -* Stable tag: 6.2.0 -* Tested up to: 6.8.1 +* Version: 6.3.0 +* Stable tag: 6.3.0 +* Tested up to: 6.9 * Author: SSLCOMMERZ * Author URI: https://github.com/sslcommerz/ * Author Email: integration@sslcommerz.com @@ -27,7 +27,7 @@ define( 'SSLCOM_PATH', plugin_dir_path( __FILE__ ) ); define( 'SSLCOM_URL', plugin_dir_url( __FILE__ ) ); - define ( 'SSLCOMMERZ_PLUGIN_VERSION', '6.2.0'); + define ( 'SSLCOMMERZ_PLUGIN_VERSION', '6.3.0'); global $plugin_slug; $plugin_slug = 'sslcommerz'; @@ -43,7 +43,10 @@ function sslcommerz_check_woocommerce_version() { if (version_compare(WC_VERSION, '8.0', '>=')) { add_action('before_woocommerce_init', function() { if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) { + // HPOS (Custom Order Tables) compatibility \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true); + // Cart and Checkout Blocks compatibility + \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('cart_checkout_blocks', __FILE__, true); } }); } @@ -51,6 +54,24 @@ function sslcommerz_check_woocommerce_version() { } add_action('plugins_loaded', 'sslcommerz_check_woocommerce_version', 5); + /** + * Register SSLCommerz payment method for WooCommerce Blocks + */ + add_action('woocommerce_blocks_loaded', function() { + if ( ! class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) { + return; + } + + require_once SSLCOM_PATH . 'lib/class-sslcommerz-blocks.php'; + + add_action( + 'woocommerce_blocks_payment_method_type_registration', + function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) { + $payment_method_registry->register( new WC_SSLCommerz_Blocks() ); + } + ); + }); + /** * Hook plugin activation */ diff --git a/lib/class-sslcommerz-blocks.php b/lib/class-sslcommerz-blocks.php new file mode 100644 index 0000000..8c0f9c1 --- /dev/null +++ b/lib/class-sslcommerz-blocks.php @@ -0,0 +1,104 @@ +settings = get_option( 'woocommerce_sslcommerz_settings', array() ); + $gateways = WC()->payment_gateways->payment_gateways(); + $this->gateway = isset( $gateways[ $this->name ] ) ? $gateways[ $this->name ] : null; + } + + /** + * Returns if this payment method should be active. + * + * @return boolean + */ + public function is_active() { + if ( ! $this->gateway ) { + return false; + } + return $this->gateway->is_available(); + } + + /** + * Returns an array of scripts/handles to be registered for this payment method. + * + * @return array + */ + public function get_payment_method_script_handles() { + $script_path = 'assets/js/sslcommerz-blocks.js'; + $script_asset_path = SSLCOM_PATH . 'assets/js/sslcommerz-blocks.asset.php'; + $script_asset = file_exists( $script_asset_path ) + ? require( $script_asset_path ) + : array( + 'dependencies' => array(), + 'version' => SSLCOMMERZ_PLUGIN_VERSION + ); + $script_url = SSLCOM_URL . $script_path; + + wp_register_script( + 'wc-sslcommerz-blocks', + $script_url, + array( 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-html-entities', 'wp-i18n' ), + $script_asset['version'], + true + ); + + if ( function_exists( 'wp_set_script_translations' ) ) { + wp_set_script_translations( 'wc-sslcommerz-blocks', 'sslcommerz', SSLCOM_PATH . 'languages/' ); + } + + return array( 'wc-sslcommerz-blocks' ); + } + + /** + * Returns an array of key=>value pairs of data made available to the payment methods script. + * + * @return array + */ + public function get_payment_method_data() { + return array( + 'title' => $this->get_setting( 'title' ), + 'description' => $this->get_setting( 'description' ), + 'supports' => array_filter( $this->gateway ? $this->gateway->supports : array(), array( $this->gateway, 'supports' ) ), + 'icon' => SSLCOM_URL . 'images/sslcz-verified.png', + 'testmode' => $this->get_setting( 'testmode' ) === 'yes', + ); + } +} diff --git a/readme.txt b/readme.txt index 1741045..3c74bc2 100644 --- a/readme.txt +++ b/readme.txt @@ -3,11 +3,13 @@ Contributors: rkbi, prabalsslw Tags: sslcommerz, Payment, gateway, easycheckout, hosted, bangladesh, official Author URI: https://www.sslcommerz.com Plugin URI: https://github.com/sslcommerz/SSLCommerz-Woocommerce -Version: 6.2.0 +Version: 6.3.0 Requires PHP: 7.4 Requires at least: 5.8 -Tested up to: 6.8.1 -Stable tag: 6.2.0 +Tested up to: 6.9 +Stable tag: 6.3.0 +WC requires at least: 8.0 +WC tested up to: 10.4.3 License: GNU General Public License v3.0 License URI: http://www.gnu.org/licenses/gpl-3.0.html