'Version' ), false ); define( 'WC_CASHFREE_FILE', __FILE__ ); define( 'WC_CASHFREE_DIR_PATH', plugin_dir_path( __FILE__ ) ); define( 'WC_CASHFREE_DIR_URL', plugin_dir_url( __FILE__ ) ); define( 'WC_CASHFREE_VERSION', $plugin_data['Version'] ); $this->settings = get_option( 'woocommerce_' . self::PAYMENT_GATEWAY_ID . '_settings' ); if($this->settings) { $this->enabled = 'yes' === $this->settings['enabled']; } require_once WC_CASHFREE_DIR_PATH . 'includes/wc-cashfree-functions.php'; require_once WC_CASHFREE_DIR_PATH . 'includes/http/class-wc-cashfree-adapter.php'; add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( __CLASS__, 'plugin_action_links' ) ); add_filter( 'woocommerce_payment_gateways', array( __CLASS__, 'load_gateways' ) ); add_filter( 'woocommerce_before_add_to_cart_form' , array( $this, 'wp_cashfree_offers' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'load_scripts' ) ); add_action( 'woocommerce_blocks_loaded', array( __CLASS__, 'woocommerce_gateway_cashfree_woocommerce_block_support' ) ); } public function wp_cashfree_offers() { if ( isset($this->settings['enabledOffers']) && $this->settings['enabledOffers'] === 'yes' && isset($this->settings['sandbox']) && $this->settings['sandbox'] === 'no') { // External Scripts wp_register_script('cf-woocommerce-js', 'https://sdk.cashfree.com/js/widget/1.0.1/cashfree-widget.prod.js', null, null, true ); wp_enqueue_script('cf-woocommerce-js'); add_filter( 'cf-woocommerce_enqueue_styles', '__return_false' ); global $product; $price = $product->get_price(); echo'
'; } } /** * Add Cashfree payment gateway. * * @param array $methods List of payment methods. * * @return array */ public static function load_gateways( $methods ) { if ( ! class_exists( 'WC_Payment_Gateway' ) ) { return; } include_once WC_CASHFREE_DIR_PATH . 'includes/gateways/class-wc-cashfree-gateway.php'; include_once WC_CASHFREE_DIR_PATH . 'includes/gateways/class-wc-cashfree-payments.php'; array_push( $methods, 'WC_Cashfree_Payments' ); return $methods; } /** * Show action links on the plugin screen. * * @param mixed $links Plugin Action links. * * @return array */ public static function plugin_action_links( $links ) { $action_links = array( 'settings' => '' . __( 'Settings', 'cashfree' ) . '', ); return array_merge( $action_links, $links ); } /** * Register/queue frontend scripts. */ public function load_scripts() { if ( $this->enabled && ! is_checkout() ) { wc_cashfree_js( $this->settings ); } } /** * Logging method. * * @param string $message Log message. * @param string $level Optional. Default 'info'. */ public static function log( $message, $level = 'info' ) { if ( ! isset( self::$log ) ) { self::$log = wc_get_logger(); } self::$log->log( $level, $message, array( 'source' => self::PAYMENT_GATEWAY_ID ) ); } public static function woocommerce_gateway_cashfree_woocommerce_block_support() { if ( class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) { require_once WC_CASHFREE_DIR_PATH . 'includes/gateways/class-wc-cashfree-block-support.php'; add_action( 'woocommerce_blocks_payment_method_type_registration', function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) { $container = Automattic\WooCommerce\Blocks\Package::container(); // registers as shared instance. $container->register( WC_Cashfree_Blocks_Support::class, function() { return new WC_Cashfree_Blocks_Support(); } ); $payment_method_registry->register( $container->get( WC_Cashfree_Blocks_Support::class ) ); }, 5 ); } } } new WC_Cashfree();