PluginProbe
Cashfree for WooCommerce / 4.4.0
Cashfree for WooCommerce v4.4.0
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.0, at cashfree.php

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