PluginProbe
Cashfree for WooCommerce / 4.5.1
Cashfree for WooCommerce v4.5.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.5.1, at cashfree.php

158 lines 4.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.5.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.2
15 * WC requires at least: 3.0
16 * WC tested up to: 7.5
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 ( isset($this->settings['enabledOffers']) &&
80 $this->settings['enabledOffers'] === 'yes' &&
81 isset($this->settings['sandbox']) &&
82 $this->settings['sandbox'] === 'no') {
83 // External Scripts
84 wp_register_script('cf-woocommerce-js', 'https://sdk.cashfree.com/js/widget/1.0.1/cashfree-widget.prod.js', null, null, true );
85 wp_enqueue_script('cf-woocommerce-js');
86
87 add_filter( 'cf-woocommerce_enqueue_styles', '__return_false' );
88
89 global $product;
90 $price = $product->get_price();
91
92 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>';
93
94 }
95 }
96
97 /**
98 * Add Cashfree payment gateway.
99 *
100 * @param array $methods List of payment methods.
101 *
102 * @return array
103 */
104 public static function load_gateways( $methods ) {
105 if ( ! class_exists( 'WC_Payment_Gateway' ) ) {
106 return;
107 }
108
109 include_once WC_CASHFREE_DIR_PATH . 'includes/gateways/class-wc-cashfree-gateway.php';
110 include_once WC_CASHFREE_DIR_PATH . 'includes/gateways/class-wc-cashfree-payments.php';
111
112 array_push( $methods, 'WC_Cashfree_Payments' );
113 return $methods;
114 }
115
116 /**
117 * Show action links on the plugin screen.
118 *
119 * @param mixed $links Plugin Action links.
120 *
121 * @return array
122 */
123 public static function plugin_action_links( $links ) {
124 $action_links = array(
125 'settings' => '<a href="' . admin_url(
126 'admin.php?page=wc-settings&tab=checkout&section=' . self::PAYMENT_GATEWAY_ID
127 ) . '">' . __( 'Settings', 'cashfree' ) . '</a>',
128 );
129
130 return array_merge( $action_links, $links );
131 }
132
133 /**
134 * Register/queue frontend scripts.
135 */
136 public function load_scripts() {
137 if ( $this->enabled && ! is_checkout() ) {
138 wc_cashfree_js( $this->settings );
139 }
140 }
141
142 /**
143 * Logging method.
144 *
145 * @param string $message Log message.
146 * @param string $level Optional. Default 'info'.
147 */
148 public static function log( $message, $level = 'info' ) {
149 if ( ! isset( self::$log ) ) {
150 self::$log = wc_get_logger();
151 }
152
153 self::$log->log( $level, $message, array( 'source' => self::PAYMENT_GATEWAY_ID ) );
154 }
155 }
156
157 new WC_Cashfree();
158