PluginProbe
Cashfree for WooCommerce / 4.3.4
Cashfree for WooCommerce v4.3.4
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.3.4, at cashfree.php

135 lines 3.3 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.3.4
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 /**
26 * Cashfree main class.
27 */
28 class WC_Cashfree {
29
30 /**
31 * Payment gateway id.
32 *
33 * @var string
34 */
35 const PAYMENT_GATEWAY_ID = 'cashfree';
36
37 /**
38 * Payment gateway settings.
39 *
40 * @var array
41 */
42 private $settings;
43
44 /**
45 * A log object returned by wc_get_logger().
46 *
47 * @var WC_Logger
48 */
49 public static $log;
50
51 /**
52 * Constructor.
53 */
54 public function __construct() {
55 $plugin_data = get_file_data( __FILE__, array( 'Version' => 'Version' ), false );
56
57 define( 'WC_CASHFREE_FILE', __FILE__ );
58 define( 'WC_CASHFREE_DIR_PATH', plugin_dir_path( __FILE__ ) );
59 define( 'WC_CASHFREE_DIR_URL', plugin_dir_url( __FILE__ ) );
60 define( 'WC_CASHFREE_VERSION', $plugin_data['Version'] );
61
62 $this->settings = get_option( 'woocommerce_' . self::PAYMENT_GATEWAY_ID . '_settings' );
63 $this->enabled = 'yes' === $this->settings['enabled'] && ! empty( $this->settings['merchant_id'] );
64
65 require_once WC_CASHFREE_DIR_PATH . 'includes/wc-cashfree-functions.php';
66 require_once WC_CASHFREE_DIR_PATH . 'includes/http/class-wc-cashfree-adapter.php';
67
68 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( __CLASS__, 'plugin_action_links' ) );
69 add_filter( 'woocommerce_payment_gateways', array( __CLASS__, 'load_gateways' ) );
70
71 add_action( 'wp_enqueue_scripts', array( $this, 'load_scripts' ) );
72 }
73
74 /**
75 * Add Cashfree payment gateway.
76 *
77 * @param array $methods List of payment methods.
78 *
79 * @return array
80 */
81 public static function load_gateways( $methods ) {
82 if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
83 return;
84 }
85
86 include_once WC_CASHFREE_DIR_PATH . 'includes/gateways/class-wc-cashfree-gateway.php';
87 include_once WC_CASHFREE_DIR_PATH . 'includes/gateways/class-wc-cashfree-payments.php';
88
89 array_push( $methods, 'WC_Cashfree_Payments' );
90 return $methods;
91 }
92
93 /**
94 * Show action links on the plugin screen.
95 *
96 * @param mixed $links Plugin Action links.
97 *
98 * @return array
99 */
100 public static function plugin_action_links( $links ) {
101 $action_links = array(
102 'settings' => '<a href="' . admin_url(
103 'admin.php?page=wc-settings&tab=checkout&section=' . self::PAYMENT_GATEWAY_ID
104 ) . '">' . __( 'Settings', 'cashfree' ) . '</a>',
105 );
106
107 return array_merge( $action_links, $links );
108 }
109
110 /**
111 * Register/queue frontend scripts.
112 */
113 public function load_scripts() {
114 if ( $this->enabled && ! is_checkout() ) {
115 wc_cashfree_js( $this->settings );
116 }
117 }
118
119 /**
120 * Logging method.
121 *
122 * @param string $message Log message.
123 * @param string $level Optional. Default 'info'.
124 */
125 public static function log( $message, $level = 'info' ) {
126 if ( ! isset( self::$log ) ) {
127 self::$log = wc_get_logger();
128 }
129
130 self::$log->log( $level, $message, array( 'source' => self::PAYMENT_GATEWAY_ID ) );
131 }
132 }
133
134 new WC_Cashfree();
135