diff --git a/.distignore b/.distignore index 4f087e8..dbb812c 100644 --- a/.distignore +++ b/.distignore @@ -14,4 +14,6 @@ package.json package-lock.json phpcs.xml README.md -todo \ No newline at end of file +todo +index.js +webpack.config.js \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a51ee35..b5a77e6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -14,6 +14,11 @@ jobs: - name: Checkout code uses: actions/checkout@v2 + - name: Build Block Assets + run: | + npm install + npm run build + - name: WordPress Plugin Deploy id: deploy uses: 10up/action-wordpress-plugin-deploy@stable diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c96f019 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vscode +node_modules/ \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index f429563..e39c8a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Changelog All notable changes to this project will be documented in this file. +## 1.2.0 +Release Date: January 6, 2024 + +* Added: Support for WooCommerce Block-based checkout. +* WordPress tested up to v6.4. +* WC Tested up to v8.6. + ## 1.1.9 Release Date: July 22, 2023 diff --git a/includes/blocks/assets/blocks.asset.php b/includes/blocks/assets/blocks.asset.php new file mode 100644 index 0000000..3eb3fed --- /dev/null +++ b/includes/blocks/assets/blocks.asset.php @@ -0,0 +1 @@ + array('react', 'wc-blocks-registry', 'wc-settings', 'wp-html-entities'), 'version' => 'cace7ebdfbbb3a43dc17'); diff --git a/includes/blocks/assets/blocks.js b/includes/blocks/assets/blocks.js new file mode 100644 index 0000000..53cfb31 --- /dev/null +++ b/includes/blocks/assets/blocks.js @@ -0,0 +1 @@ +(()=>{"use strict";const e=window.React,t=window.wc.wcBlocksRegistry,n=window.wp.htmlEntities,a=(0,window.wc.wcSettings.getSetting)("wc-razorpay_data",{}),c=(0,n.decodeEntities)(a.title)||"Razorpay Payment Gateway",o=()=>(0,n.decodeEntities)(a.description||""),r={name:"wc-razorpay",label:(0,e.createElement)((t=>{const{PaymentMethodLabel:n}=t.components;return(0,e.createElement)(n,{text:c})}),null),content:(0,e.createElement)(o,null),edit:(0,e.createElement)(o,null),placeOrderButtonLabel:a?.button_text,canMakePayment:()=>!0,ariaLabel:c,supports:{features:a.supports}};(0,t.registerPaymentMethod)(r)})(); \ No newline at end of file diff --git a/includes/blocks/class-blocks-support.php b/includes/blocks/class-blocks-support.php new file mode 100644 index 0000000..23b8856 --- /dev/null +++ b/includes/blocks/class-blocks-support.php @@ -0,0 +1,95 @@ +settings = get_option( "woocommerce_{$this->name}_settings", [] ); + } + + /** + * Returns if this payment method should be active. If false, the scripts will not be enqueued. + * + * @return boolean + */ + public function is_active() { + return ! empty( $this->settings['enabled'] ) && 'yes' === $this->settings['enabled']; + } + + /** + * Returns an array of scripts/handles to be registered for this payment method. + * + * @return array + */ + public function get_payment_method_script_handles() { + $script_path = 'includes/blocks/assets/blocks.js'; + $script_asset_path = RZPWC_PATH . 'includes/blocks/assets/blocks.asset.php'; + $script_asset = file_exists( $script_asset_path ) + ? require( $script_asset_path ) + : array( + 'dependencies' => array(), + 'version' => RZPWC_VERSION + ); + $script_url = RZPWC_URL . $script_path; + + wp_register_script( + 'rzpwc-payment-blocks', + $script_url, + $script_asset[ 'dependencies' ], + $script_asset[ 'version' ], + true + ); + + if ( function_exists( 'wp_set_script_translations' ) ) { + wp_set_script_translations( 'rzpwc-payment-blocks', 'rzp-woocommerce', RZPWC_PATH . 'languages/' ); + } + + return [ 'rzpwc-payment-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 [ + 'title' => $this->get_setting( 'title' ), + 'description' => $this->get_setting( 'description' ), + 'supports' => $this->get_supported_features(), + 'button_text' => apply_filters( 'upiwc_order_button_text', __( 'Proceed to Payment', 'rzp-woocommerce' ) ), + ]; + } + + /** + * Returns an array of supported features. + * + * @return string[] + */ + public function get_supported_features() { + $gateways = WC()->payment_gateways->get_available_payment_gateways(); + + if ( isset( $gateways[ $this->name ] ) ) { + $gateway = $gateways[ $this->name ]; + + return array_filter( $gateway->supports, [ $gateway, 'supports' ] ); + } + + return []; + } +} diff --git a/includes/blocks/index.php b/includes/blocks/index.php new file mode 100644 index 0000000..e71af0e --- /dev/null +++ b/includes/blocks/index.php @@ -0,0 +1 @@ + { + return decodeEntities( settings.description || '' ); +}; + +const Label = ( props ) => { + const { PaymentMethodLabel } = props.components; + return ; +}; + +const razorpayPaymentLinks = { + name: "wc-razorpay", + label: