Skip to content

Commit

Permalink
Merge pull request #5 from iamsayan/develop
Browse files Browse the repository at this point in the history
added v1.2.0
  • Loading branch information
iamsayan authored Feb 6, 2024
2 parents e5753ce + 8066838 commit 1162b18
Show file tree
Hide file tree
Showing 14 changed files with 19,124 additions and 26 deletions.
4 changes: 3 additions & 1 deletion .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ package.json
package-lock.json
phpcs.xml
README.md
todo
todo
index.js
webpack.config.js
5 changes: 5 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vscode
node_modules/
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 1 addition & 0 deletions includes/blocks/assets/blocks.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-html-entities'), 'version' => 'cace7ebdfbbb3a43dc17');
1 change: 1 addition & 0 deletions includes/blocks/assets/blocks.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 95 additions & 0 deletions includes/blocks/class-blocks-support.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;

/**
* Razorpay Payment Links Blocks integration
*
* @since 1.2.0
*/
final class RZP_WC_Payment_Gateway_Blocks_Support extends AbstractPaymentMethodType {

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

/**
* Initializes the payment method type.
*/
public function initialize() {
$this->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 [];
}
}
1 change: 1 addition & 0 deletions includes/blocks/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php // Silence is golden
30 changes: 30 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { registerPaymentMethod } from '@woocommerce/blocks-registry';
import { decodeEntities } from '@wordpress/html-entities';
import { getSetting } from '@woocommerce/settings';

const settings = getSetting( 'wc-razorpay_data', {} );
const label = decodeEntities( settings.title ) || 'Razorpay Payment Gateway';

const Content = () => {
return decodeEntities( settings.description || '' );
};

const Label = ( props ) => {
const { PaymentMethodLabel } = props.components;
return <PaymentMethodLabel text={ label } />;
};

const razorpayPaymentLinks = {
name: "wc-razorpay",
label: <Label />,
content: <Content />,
edit: <Content />,
placeOrderButtonLabel: settings?.button_text,
canMakePayment: () => true,
ariaLabel: label,
supports: {
features: settings.supports,
},
};

registerPaymentMethod( razorpayPaymentLinks );
Loading

0 comments on commit 1162b18

Please sign in to comment.