Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions assets/js/sslcommerz-blocks.js
Original file line number Diff line number Diff line change
@@ -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);

})();
29 changes: 25 additions & 4 deletions easyCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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';
Expand All @@ -43,14 +43,35 @@ 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);
}
});
}
}
}
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
*/
Expand Down
104 changes: 104 additions & 0 deletions lib/class-sslcommerz-blocks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
/**
* SSLCommerz Blocks Support
*
* Adds WooCommerce Checkout Blocks compatibility for SSLCommerz payment gateway.
*
* @package SSLCommerz_Woocommerce
* @since 6.3.0
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;

/**
* SSLCommerz Blocks integration
*
* @since 6.3.0
*/
final class WC_SSLCommerz_Blocks extends AbstractPaymentMethodType {

/**
* The gateway instance.
*
* @var WC_sslcommerz
*/
private $gateway;

/**
* Payment method name/id/slug.
*
* @var string
*/
protected $name = 'sslcommerz';

/**
* Initializes the payment method type.
*/
public function initialize() {
$this->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',
);
}
}
8 changes: 5 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down