PluginProbe
Cashfree for WooCommerce / 4.4.1
Cashfree for WooCommerce v4.4.1
4.8.1 4.8.0 trunk 1.0 1.2 4.2.1 4.2.2 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.8 4.3.9 4.4.0 4.4.1 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.5.0 4.5.1 All 42 releases
cashfree / cashfree.php

cashfree.php in Cashfree for WooCommerce 4.4.1, at cashfree.php

155 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Cashfree
4 * Version: 4.4.1
5 * Plugin URI: https://github.com/cashfree/cashfree-woocommerce
6 * Description: Payment gateway plugin by Cashfree Payments for Woocommerce sites.
7 * Author: devcashfree
8 * Author URI: https://cashfree.com
9 * Developer: Cashfree Dev
10 * Developer URI: techsupport@gocashfree.com
11 * Text Domain: woocommerce-extension
12 * Domain Path: /languages
13 * Requires at least: 4.4
14 * Tested up to: 6.0
15 * WC requires at least: 3.0
16 * WC tested up to: 6.3.1
17 *
18 *
19 * License: GPLv3
20 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
21 */
22
23 defined( 'ABSPATH' ) || exit;
24
25 // to read main.js file
26 define ('WPCO_URL', trailingslashit(plugins_url('/',__FILE__)));
27
28 /**
29 * Cashfree main class.
30 */
31 class WC_Cashfree {
32
33 /**
34 * Payment gateway id.
35 *
36 * @var string
37 */
38 const PAYMENT_GATEWAY_ID = 'cashfree';
39
40 /**
41 * Payment gateway settings.
42 *
43 * @var array
44 */
45 private $settings;
46
47 /**
48 * A log object returned by wc_get_logger().
49 *
50 * @var WC_Logger
51 */
52 public static $log;
53
54 /**
55 * Constructor.
56 */
57 public function __construct() {
58 $plugin_data = get_file_data( __FILE__, array( 'Version' => 'Version' ), false );
59
60 define( 'WC_CASHFREE_FILE', __FILE__ );
61 define( 'WC_CASHFREE_DIR_PATH', plugin_dir_path( __FILE__ ) );
62 define( 'WC_CASHFREE_DIR_URL', plugin_dir_url( __FILE__ ) );
63 define( 'WC_CASHFREE_VERSION', $plugin_data['Version'] );
64
65 $this->settings = get_option( 'woocommerce_' . self::PAYMENT_GATEWAY_ID . '_settings' );
66 $this->enabled = 'yes' === $this->settings['enabled'] && ! empty( $this->settings['merchant_id'] );
67
68 require_once WC_CASHFREE_DIR_PATH . 'includes/wc-cashfree-functions.php';
69 require_once WC_CASHFREE_DIR_PATH . 'includes/http/class-wc-cashfree-adapter.php';
70
71 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( __CLASS__, 'plugin_action_links' ) );
72 add_filter( 'woocommerce_payment_gateways', array( __CLASS__, 'load_gateways' ) );
73 add_filter( 'woocommerce_before_add_to_cart_form' , array( $this, 'wp_cashfree_offers' ) );
74
75 add_action( 'wp_enqueue_scripts', array( $this, 'load_scripts' ) );
76 }
77
78 public function wp_cashfree_offers() {
79 if ( $this->settings['enabledOffers'] === 'yes' && $this->settings['sandbox'] === 'no') {
80 // External Scripts
81 wp_register_script('cf-woocommerce-js', 'https://sdk.cashfree.com/js/widget/1.0.1/cashfree-widget.prod.js', null, null, true );
82 wp_enqueue_script('cf-woocommerce-js');
83
84 add_filter( 'cf-woocommerce_enqueue_styles', '__return_false' );
85
86 global $product;
87 $price = $product->get_price();
88
89 echo'<div id="cashfree-widget" data-amount='.$price.' data-appId='.$this->settings['app_id'].' data-isOffers='.$this->settings['offers'].' data-isPayLater='.$this->settings['payLater'].' data-isEmi='.$this->settings['emi'].'></div>';
90
91 }
92 }
93
94 /**
95 * Add Cashfree payment gateway.
96 *
97 * @param array $methods List of payment methods.
98 *
99 * @return array
100 */
101 public static function load_gateways( $methods ) {
102 if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
103 return;
104 }
105
106 include_once WC_CASHFREE_DIR_PATH . 'includes/gateways/class-wc-cashfree-gateway.php';
107 include_once WC_CASHFREE_DIR_PATH . 'includes/gateways/class-wc-cashfree-payments.php';
108
109 array_push( $methods, 'WC_Cashfree_Payments' );
110 return $methods;
111 }
112
113 /**
114 * Show action links on the plugin screen.
115 *
116 * @param mixed $links Plugin Action links.
117 *
118 * @return array
119 */
120 public static function plugin_action_links( $links ) {
121 $action_links = array(
122 'settings' => '<a href="' . admin_url(
123 'admin.php?page=wc-settings&tab=checkout&section=' . self::PAYMENT_GATEWAY_ID
124 ) . '">' . __( 'Settings', 'cashfree' ) . '</a>',
125 );
126
127 return array_merge( $action_links, $links );
128 }
129
130 /**
131 * Register/queue frontend scripts.
132 */
133 public function load_scripts() {
134 if ( $this->enabled && ! is_checkout() ) {
135 wc_cashfree_js( $this->settings );
136 }
137 }
138
139 /**
140 * Logging method.
141 *
142 * @param string $message Log message.
143 * @param string $level Optional. Default 'info'.
144 */
145 public static function log( $message, $level = 'info' ) {
146 if ( ! isset( self::$log ) ) {
147 self::$log = wc_get_logger();
148 }
149
150 self::$log->log( $level, $message, array( 'source' => self::PAYMENT_GATEWAY_ID ) );
151 }
152 }
153
154 new WC_Cashfree();
155