diff --git a/BitPayLib/Blocks/class-bitpaypaymentsblocks.php b/BitPayLib/Blocks/class-bitpaypaymentsblocks.php new file mode 100644 index 0000000..564ea26 --- /dev/null +++ b/BitPayLib/Blocks/class-bitpaypaymentsblocks.php @@ -0,0 +1,56 @@ +settings = get_option( 'woocommerce_bitpay_checkout_gateway_settings', array() ); + $gateways = WC()->payment_gateways->payment_gateways(); + $this->gateway = $gateways[ $this->name ]; + } + public function is_active() { + return $this->gateway->is_available(); + } + + public function get_payment_method_script_handles() { + $version = BitPayPluginSetup::VERSION; + $path = plugins_url( '../../../js/bitpay_payments_blocks.js', __FILE__ ); + $handle = 'bitpay-checkout-block'; + $dependencies = array( 'wp-hooks' ); + + wp_register_script( $handle, $path, $dependencies, $version, true ); + + return array( 'bitpay-checkout-block' ); + } + + public function get_payment_method_data() { + return array( + 'title' => WcGatewayBitpay::TITLE, + 'description' => $this->get_setting( 'description' ), + 'supports' => array_filter( + $this->gateway->supports, + array( + $this->gateway, + 'supports', + ) + ), + ); + } +} diff --git a/BitPayLib/class-bitpaycancelorder.php b/BitPayLib/class-bitpaycancelorder.php index ed644ef..8bb9365 100644 --- a/BitPayLib/class-bitpaycancelorder.php +++ b/BitPayLib/class-bitpaycancelorder.php @@ -8,7 +8,7 @@ * Plugin Name: BitPay Checkout for WooCommerce * Plugin URI: https://www.bitpay.com * Description: BitPay Checkout Plugin - * Version: 5.3.2 + * Version: 5.4.0 * Author: BitPay * Author URI: mailto:integrations@bitpay.com?subject=BitPay Checkout for WooCommerce */ diff --git a/BitPayLib/class-bitpaycart.php b/BitPayLib/class-bitpaycart.php index 99fc632..3be6db2 100644 --- a/BitPayLib/class-bitpaycart.php +++ b/BitPayLib/class-bitpaycart.php @@ -8,7 +8,7 @@ * Plugin Name: BitPay Checkout for WooCommerce * Plugin URI: https://www.bitpay.com * Description: BitPay Checkout Plugin - * Version: 5.3.2 + * Version: 5.4.0 * Author: BitPay * Author URI: mailto:integrations@bitpay.com?subject=BitPay Checkout for WooCommerce */ diff --git a/BitPayLib/class-bitpaycheckouttransactions.php b/BitPayLib/class-bitpaycheckouttransactions.php index 7db315e..24d7694 100644 --- a/BitPayLib/class-bitpaycheckouttransactions.php +++ b/BitPayLib/class-bitpaycheckouttransactions.php @@ -11,7 +11,7 @@ * Plugin Name: BitPay Checkout for WooCommerce * Plugin URI: https://www.bitpay.com * Description: BitPay Checkout Plugin - * Version: 5.3.2 + * Version: 5.4.0 * Author: BitPay * Author URI: mailto:integrations@bitpay.com?subject=BitPay Checkout for WooCommerce */ diff --git a/BitPayLib/class-bitpayclientfactory.php b/BitPayLib/class-bitpayclientfactory.php index b3c1fab..28bbfbc 100644 --- a/BitPayLib/class-bitpayclientfactory.php +++ b/BitPayLib/class-bitpayclientfactory.php @@ -13,7 +13,7 @@ * Plugin Name: BitPay Checkout for WooCommerce * Plugin URI: https://www.bitpay.com * Description: BitPay Checkout Plugin - * Version: 5.3.2 + * Version: 5.4.0 * Author: BitPay * Author URI: mailto:integrations@bitpay.com?subject=BitPay Checkout for WooCommerce */ diff --git a/BitPayLib/class-bitpayinvoicecreate.php b/BitPayLib/class-bitpayinvoicecreate.php index b458e52..943a7b5 100644 --- a/BitPayLib/class-bitpayinvoicecreate.php +++ b/BitPayLib/class-bitpayinvoicecreate.php @@ -13,7 +13,7 @@ * Plugin Name: BitPay Checkout for WooCommerce * Plugin URI: https://www.bitpay.com * Description: BitPay Checkout Plugin - * Version: 5.3.2 + * Version: 5.4.0 * Author: BitPay * Author URI: mailto:integrations@bitpay.com?subject=BitPay Checkout for WooCommerce */ diff --git a/BitPayLib/class-bitpayipnprocess.php b/BitPayLib/class-bitpayipnprocess.php index a3d63a7..1b6efbb 100644 --- a/BitPayLib/class-bitpayipnprocess.php +++ b/BitPayLib/class-bitpayipnprocess.php @@ -13,7 +13,7 @@ * Plugin Name: BitPay Checkout for WooCommerce * Plugin URI: https://www.bitpay.com * Description: BitPay Checkout Plugin - * Version: 5.3.2 + * Version: 5.4.0 * Author: BitPay * Author URI: mailto:integrations@bitpay.com?subject=BitPay Checkout for WooCommerce */ diff --git a/BitPayLib/class-bitpaylogger.php b/BitPayLib/class-bitpaylogger.php index 76b017f..161be2e 100644 --- a/BitPayLib/class-bitpaylogger.php +++ b/BitPayLib/class-bitpaylogger.php @@ -8,7 +8,7 @@ * Plugin Name: BitPay Checkout for WooCommerce * Plugin URI: https://www.bitpay.com * Description: BitPay Checkout Plugin - * Version: 5.3.2 + * Version: 5.4.0 * Author: BitPay * Author URI: mailto:integrations@bitpay.com?subject=BitPay Checkout for WooCommerce */ diff --git a/BitPayLib/class-bitpaypages.php b/BitPayLib/class-bitpaypages.php index 09a9dd1..1f02728 100644 --- a/BitPayLib/class-bitpaypages.php +++ b/BitPayLib/class-bitpaypages.php @@ -7,7 +7,7 @@ /** * Plugin Name: BitPay Checkout for WooCommerce * Plugin URI: https://www.bitpay.com - * Version: 5.3.2 + * Version: 5.4.0 * Author: BitPay * Author URI: mailto:integrations@bitpay.com?subject=BitPay Checkout for WooCommerce */ diff --git a/BitPayLib/class-bitpaypaymentsettings.php b/BitPayLib/class-bitpaypaymentsettings.php index 35b4367..de7e0cf 100644 --- a/BitPayLib/class-bitpaypaymentsettings.php +++ b/BitPayLib/class-bitpaypaymentsettings.php @@ -8,7 +8,7 @@ * Plugin Name: BitPay Checkout for WooCommerce * Plugin URI: https://www.bitpay.com * Description: BitPay Checkout Plugin - * Version: 5.3.2 + * Version: 5.4.0 * Author: BitPay * Author URI: mailto:integrations@bitpay.com?subject=BitPay Checkout for WooCommerce */ diff --git a/BitPayLib/class-bitpaypluginsetup.php b/BitPayLib/class-bitpaypluginsetup.php index 9f797db..cc40a10 100644 --- a/BitPayLib/class-bitpaypluginsetup.php +++ b/BitPayLib/class-bitpaypluginsetup.php @@ -4,18 +4,21 @@ namespace BitPayLib; +use BitPayLib\Blocks\BitPayPaymentsBlocks; use WP_REST_Request; /** * Plugin Name: BitPay Checkout for WooCommerce * Plugin URI: https://www.bitpay.com * Description: BitPay Checkout Plugin - * Version: 5.3.2 + * Version: 5.4.0 * Author: BitPay * Author URI: mailto:integrations@bitpay.com?subject=BitPay Checkout for WooCommerce */ class BitPayPluginSetup { + public const VERSION = '5.4.0'; + private BitPayIpnProcess $bitpay_ipn_process; private BitPayCancelOrder $bitpay_cancel_order; private BitPayPaymentSettings $bitpay_payment_settings; @@ -51,6 +54,7 @@ public function execute(): void { add_action( 'woocommerce_thankyou', array( $this, 'bitpay_checkout_custom_message' ) ); add_filter( 'woocommerce_payment_gateways', array( $this, 'wc_bitpay_checkout_add_to_gateways' ) ); add_filter( 'woocommerce_order_button_html', array( $this, 'bitpay_checkout_replace_order_button_html' ), 10, 2 ); + add_action( 'woocommerce_blocks_loaded', array( $this, 'register_payment_block' ) ); // http:///wp-json/bitpay/ipn/status url. // http:///wp-json/bitpay/cartfix/restore url. @@ -194,4 +198,31 @@ private function validate_woo_commerce(): array { return array(); } + + public function register_payment_block(): void { + add_action( + 'woocommerce_blocks_payment_method_type_registration', + function ( \Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) { + $container = \Automattic\WooCommerce\Blocks\Package::container(); + + $container->register( + BitPayPaymentsBlocks::class, + function () { + return new BitPayPaymentsBlocks(); + } + ); + $payment_method_registry->register( + $container->get( BitPayPaymentsBlocks::class ) + ); + }, + 5 + ); + + add_action( + 'woocommerce_blocks_payment_method_type_registration', + function ( $registry ) { + $registry->register( new BitPayPaymentsBlocks() ); + } + ); + } } diff --git a/BitPayLib/class-wcgatewaybitpay.php b/BitPayLib/class-wcgatewaybitpay.php index 2e84d7a..f3f8c1f 100644 --- a/BitPayLib/class-wcgatewaybitpay.php +++ b/BitPayLib/class-wcgatewaybitpay.php @@ -8,17 +8,20 @@ * Plugin Name: BitPay Checkout for WooCommerce * Plugin URI: https://www.bitpay.com * Description: BitPay Checkout Plugin - * Version: 5.3.2 + * Version: 5.4.0 * Author: BitPay * Author URI: mailto:integrations@bitpay.com?subject=BitPay Checkout for WooCommerce */ class WcGatewayBitpay extends \WC_Payment_Gateway { public const IGNORE_STATUS_VALUE = 'bitpay-ignore'; + public const GATEWAY_NAME = 'bitpay_checkout_gateway'; + public const TITLE = 'BitPay'; + private string $instructions; public function __construct() { - $this->id = 'bitpay_checkout_gateway'; + $this->id = self::GATEWAY_NAME; $this->icon = $this->get_icon_on_payment_page(); $this->has_fields = true; @@ -33,16 +36,23 @@ public function __construct() { $this->init_form_fields(); $this->init_settings(); - $this->title = 'BitPay'; + $this->title = self::TITLE; $this->description = $this->get_option( 'description' ) . '
'; $this->instructions = $this->get_option( 'instructions', $this->description ); add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 3 ); - wp_enqueue_script( 'bitpay_wc_gateway', plugins_url( '../../js/wc_gateway_bitpay.js', __FILE__ ), null, 1, false ); + wp_enqueue_script( 'jquery' ); + wp_enqueue_script( + 'bitpay_wc_gateway', + plugins_url( '../../js/wc_gateway_bitpay.js', __FILE__ ), + null, + 1, + false + ); } public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { - if ( $this->instructions && ! $sent_to_admin && 'bitpay_checkout_gateway' === $order->get_payment_method() && $order->has_status( 'processing' ) ) { + if ( $this->instructions && ! $sent_to_admin && self::GATEWAY_NAME === $order->get_payment_method() && $order->has_status( 'processing' ) ) { echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); } } diff --git a/BitPayLib/trait-wpdbhelper.php b/BitPayLib/trait-wpdbhelper.php index 325831e..124e507 100644 --- a/BitPayLib/trait-wpdbhelper.php +++ b/BitPayLib/trait-wpdbhelper.php @@ -10,7 +10,7 @@ * Plugin Name: BitPay Checkout for WooCommerce * Plugin URI: https://www.bitpay.com * Description: BitPay Checkout Plugin - * Version: 5.3.2 + * Version: 5.4.0 * Author: BitPay * Author URI: mailto:integrations@bitpay.com?subject=BitPay Checkout for WooCommerce */ diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c1a796..c6600d2 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +# 5.4.0 +* Added compatibility with Checkout Blocks +* Tested compatibility with WordPress 6.4.2 + # 5.3.2 * Fix typo "completed" for BitPay available statuses * Checking if there is a cart before triggering empty_cart() method diff --git a/README.md b/README.md index 05e8d1c..bef10cc 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Visit the [Releases](https://github.com/bitpay/bitpay-checkout-for-woocommerce/r **BitPay Support:** -* Last Cart Version Tested: Wordpress 6.2.2 +* Last Cart Version Tested: Wordpress 6.4.2 * [GitHub Issues](https://github.com/bitpay/bitpay-checkout-for-woocommerce/issues) * [Support](https://support.bitpay.com/hc/en-us) diff --git a/index.php b/index.php index bac2b4c..b6ccf5b 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,7 @@ * Plugin Name: BitPay Checkout for WooCommerce * Plugin URI: https://www.bitpay.com * Description: BitPay Checkout Plugin - * Version: 5.3.2 + * Version: 5.4.0 * Author: BitPay * Author URI: mailto:integrations@bitpay.com?subject=BitPay Checkout for WooCommerce */ diff --git a/js/bitpay_payments_blocks.js b/js/bitpay_payments_blocks.js new file mode 100644 index 0000000..9bde04c --- /dev/null +++ b/js/bitpay_payments_blocks.js @@ -0,0 +1,22 @@ +const settings = window.wc.wcSettings.getSetting( 'bitpay_checkout_gateway_data', {} ) +const label = window.wp.htmlEntities.decodeEntities( settings.title ) || 'BitPay'; +const content = () => { + return window.wp.htmlEntities.decodeEntities( settings.description || '' ); +}; + +/** + * BitPay payment method config object. + */ +const BitPay = { + name: "bitpay_checkout_gateway", + 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( BitPay ) diff --git a/readme.txt b/readme.txt index 3423237..bf3a74d 100644 --- a/readme.txt +++ b/readme.txt @@ -2,10 +2,10 @@ Contributors: bitpay Tags: bitcoin, ether, ripple, bitcoin cash, ERC20, payments, bitpay, cryptocurrency, payment gateway Requires at least: 6.0 -Tested up to: 6.2.2 +Tested up to: 6.4.2 Requires PHP: 8.0 Recommended PHP: 8.0 -Stable tag: 5.3.2 +Stable tag: 5.4.0 License: MIT License (MIT) License URI: https://github.com/bitpay/bitpay-checkout-for-woocommerce/blob/master/LICENSE @@ -111,6 +111,10 @@ You can contact our support team via the following form https://bitpay.com/reque == Changelog == += 5.4.0 = +* Added compatibility with Checkout Blocks +* Tested compatibility with WordPress 6.4.2 + = 5.3.2 = * Fix typo "completed" for BitPay available statuses * Checking if there is a cart before triggering empty_cart() method diff --git a/scoper.inc.php b/scoper.inc.php index 47effa2..dfb153f 100644 --- a/scoper.inc.php +++ b/scoper.inc.php @@ -40,6 +40,9 @@ static function (string $filePath, string $prefix, string $contents): string { 'WC_Order', 'WP_REST_Request', 'WC_Admin_Settings', + 'Automattic\WooCommerce\Blocks\Package', + 'Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry', + 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType', 'wpdb' ], 'exclude-functions' => [],