-
Notifications
You must be signed in to change notification settings - Fork 0
/
jazzcash-woocommerce.php
120 lines (111 loc) · 4.43 KB
/
jazzcash-woocommerce.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* Plugin Name: JazzCash - WC Payment GateWay
* Plugin URI: https://github.com/meetsohail/jazzcash-wc-payment-gateway
* Description: JazzCash WordPress Payment Gateway plugin.
* Version: 1.0
* Requires at least: 5.2
* Requires PHP: 7.0
* Author: Sohail Ahmed
* Author URI: https://github.com/meetsohail
* License: MIT
* License URI: https://choosealicense.com/licenses/mit/
* Text Domain: jazzcash-wc-payment-gateway
* Domain Path: /languages
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class JazzCash_Woocommerce_Payment_Gateway
{
public function __construct()
{
define('JAZZCASH_VERSION', '1.0');
define('JAZZCASH_ID', 'jazzcash-wc-payment-gateway');
define("JAZZCASH_DIR_PATH", plugin_dir_path(__FILE__));
define("JAZZCASH_DIR_PATH_INC", plugin_dir_path(__FILE__)."inc/");
define("JAZZCASH_DIR_PATH_IMAGES", plugin_dir_url( __FILE__ )."images/");
define("JAZZCASH_DIR_PATH_CSS", plugin_dir_url( __FILE__ )."css/");
define("JAZZCASH_DIR_PATH_JS", plugin_dir_url( __FILE__ )."js/");
define("JAZZCASH_URL", plugins_url('', __FILE__));
/**
* Check if WooCommerce is active
**/
if ( !in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) )
{
add_action('admin_notices', array($this, 'jazzcash_wc_woocommerce_check'));
}
/**
* Check if Currency is PKR
**/
else if(apply_filters( 'woocommerce_currency', get_option( 'woocommerce_currency' ) ) != 'PKR')
{
add_action('admin_notices', array($this, 'jazzcash_wc_currency_check'));
}
/**
* Activate Plugin Successfully
**/
else
{
add_action( 'plugins_loaded', array($this,'jazzcash_wc_gateway_class') );
add_filter( 'woocommerce_payment_gateways', array($this, 'jazzcash_wc_payment_gateway') );
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array($this, 'jazzcash_wc_action_links') );
add_action('admin_notices', array($this, 'jazzcash_wc_ssl_check'));
add_action( 'woocommerce_before_thankyou', array($this,'jazzcash_wc_success_message_after_payment') );
}
}
function jazzcash_wc_woocommerce_check()
{
echo "<div class=\"error\"><p>" . __("Make Sure WooCommerce is installed to use JazzCash WooCommerce Payment GateWay Plugin")."</p></div>";
}
function jazzcash_wc_currency_check()
{
echo "<div class=\"error\"><p>" . __("JazzCash only Proccessess Pakistani PKR currency.")."</p></div>";
}
function jazzcash_wc_gateway_class()
{
require_once(JAZZCASH_DIR_PATH_INC."init.class.php");
}
function jazzcash_wc_payment_gateway($methods)
{
$methods[] = 'JazzCash_WC_Payment_Gateway';
return $methods;
}
/**
* Add Setting Link on plugins page.
**/
function jazzcash_wc_action_links( $links )
{
$plugin_links = array(
'<a href="' . admin_url( 'admin.php?page=wc-settings&tab=checkout' ) . '">' . __( 'Settings', 'jazzcash' ) . '</a>',
);
return array_merge( $plugin_links, $links );
}
/**
* Check SSL.
**/
public function jazzcash_wc_ssl_check()
{
if ($this->enabled == "yes")
{
if (get_option('woocommerce_force_ssl_checkout') == "no")
{
echo "<div class=\"error\"><p>" . sprintf(__("<strong>%s</strong> is enabled and WooCommerce is not forcing the SSL certificate on your checkout page. Please ensure that you have a valid SSL certificate and that you are <a href=\"%s\">forcing the checkout pages to be secured.</a>"),
$this->method_title, admin_url('admin.php?page=wc-settings&tab=checkout')) .
"</p></div>";
}
}
}
/**
* Shows success message on thank you page.
**/
function jazzcash_wc_success_message_after_payment( $order_id )
{
// Get the WC_Order Object
$order = wc_get_order( $order_id );
if ( $order->has_status('processing') ){
wc_print_notice( __("Your payment has been successful!", "woocommerce"), "success" );
}
}
}
new JazzCash_Woocommerce_Payment_Gateway();