-
Notifications
You must be signed in to change notification settings - Fork 93
/
osen-wc-mpesa.php
executable file
·128 lines (106 loc) · 4.13 KB
/
osen-wc-mpesa.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
121
122
123
124
125
126
127
128
<?php
/**
* @package Mpesa for WooCommerce
* @author Osen Concepts < [email protected] >
* @version 3.0.0
*
* Plugin Name: Osen WC Mpesa
* Plugin URI: https://wcmpesa.co.ke/
* Description: This plugin extends WordPress and WooCommerce functionality to integrate <cite>Mpesa</cite> for making and receiving online payments.
* Author: Osen Concepts Kenya < [email protected] >
* Version: 3.0.0
* Author URI: https://osen.co.ke/
*
* Requires at least: 4.6
* Tested up to: 5.8.1
*
* WC requires at least: 3.5.0
* WC tested up to: 5.1
*
* License: GPLv3
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
* Copyright 2021 Osen Concepts
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 3, as
* published by the Free Software Foundation.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USAv
*/
// Exit if accessed directly.
if (!defined('ABSPATH')) {
exit;
}
define('WCM_VER', '2.3.6');
if (!defined('WCM_PLUGIN_FILE')) {
define('WCM_PLUGIN_FILE', __FILE__);
}
require_once plugin_dir_path(__FILE__) . 'vendor/autoload.php';
register_activation_hook(__FILE__, function () {
set_transient('wc-mpesa-activation-notice', true, 5);
if (!is_plugin_active('woocommerce/woocommerce.php')) {
deactivate_plugins('osen-wc-mpesa/osen-wc-mpesa.php');
add_action('admin_notices', function () {
$class = 'notice notice-error is-dismissible';
$message = __('Please Install/Activate WooCommerce for this extension to work..', 'woocommerce');
printf('<div class="%1$s"><p>%2$s</p></div>', esc_attr($class), esc_html($message));
});
}
flush_rewrite_rules();
exit(wp_redirect(admin_url('admin.php?page=wc-settings&tab=checkout§ion=mpesa')));
});
/**
* Check transient and show notice only once - delete transient immediately after
*/
add_action('admin_notices', function () {
if (get_transient('wc-mpesa-activation-notice')) {
$class = 'updated notice is-dismissible';
$message = 'Thank you for installing the M-Pesa for WooCommerce plugin! <strong>You are awesome</strong>!';
$about_message = 'About M-Pesa for WooCommerce';
$about_url = admin_url('admin.php?page=wc_mpesa_about');
$live_message = 'How to Go Live';
$live_url = admin_url('admin.php?page=wc_mpesa_go_live');
$btn_class = 'button button-primary';
printf(
'<div class="%1$s"><p>%2$s</p><p><a class="button" href="%3$s">%4$s</a><a class="%5$s" href="%6$s">%7$s</a></p></div>',
esc_attr($class),
esc_html($message),
esc_attr($about_url),
esc_html($about_message),
esc_attr($btn_class),
esc_attr($live_url),
esc_html($live_message)
);
delete_transient('wc-mpesa-activation-notice');
}
});
add_action('wp_enqueue_scripts', function () {
if (is_checkout()) {
wp_enqueue_style("wc-mpesa-3-0", plugins_url("assets/styles.css", __FILE__));
wp_enqueue_script('jquery');
wp_enqueue_script("wc-mpesa-3-0", plugins_url("assets/scripts.js", __FILE__), array("jquery"), false, true);
wp_add_inline_script("wc-mpesa-3-0", 'var MPESA_RECEIPT_URL = "' . home_url('wc-api/lipwa_receipt') . '"', 'before');
}
});
add_action('admin_enqueue_scripts', function () {
wp_enqueue_style("c3", plugins_url("assets/c3/c3.min.css", __FILE__));
wp_enqueue_script("c3", plugins_url("assets/c3/c3.bundle.js", __FILE__), array("jquery"));
wp_enqueue_script("wc-mpesa-settings", plugins_url("assets/admin_scripts.js", __FILE__), array("jquery"), false, true);
});
/**
* Initialize all plugin features and utilities
*/
new Osen\Woocommerce\Initialize;
new Osen\Woocommerce\Utilities;
/**
* Initialize metaboxes for C2B API
*/
new Osen\Woocommerce\Post\Metaboxes\C2B;
/**
* Initialize our admin menus (submenus under WooCommerce)
*/
new Osen\Woocommerce\Admin\Menu;