-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwc-paymaya-payment-gateway.php
249 lines (221 loc) · 6.71 KB
/
wc-paymaya-payment-gateway.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?php
/**
* PHP version 7
* Plugin Name: Payments via Maya for WooCommerce
* Description: Take credit and debit card payments via Maya.
* Author: PayMaya
* Author URI: https://www.paymaya.com
* Version: 1.1.3
* Requires at least: 5.3.2
* Tested up to: 6.3.2
* WC requires at least: 3.9.3
* WC tested up to: 8.2.1
*
* @category Plugin
* @package CynderTech
* @author CynderTech <[email protected]>
* @license GPLv3 (https://www.gnu.org/licenses/gpl-3.0.html)
* @link n/a
*/
if (!defined('ABSPATH')) {
exit;
}
/**
* WooCommerce fallback notice.
*
* @return string
*/
function Paymaya_Woocommerce_Missing_Cynder_notice()
{
/* translators: 1. URL link. */
echo '<div class="error"><p><strong>' . sprintf(
esc_html__(
'Maya requires WooCommerce to be '
. 'installed and active. You can download %s here.',
'woocommerce-gateway-paymaya'
),
'<a href="https://woocommerce.com/" target="_blank">WooCommerce</a>'
) . '</strong></p></div>';
}
/**
* Initialize Paymaya Gateway Class
*
* @return string
*/
function Paymaya_Init_Gateway_class()
{
if (!class_exists('WooCommerce')) {
add_action('admin_notices', 'Paymaya_Woocommerce_Missing_Cynder_notice');
return;
}
define('CYNDER_PAYMAYA_MAIN_FILE', __FILE__);
define('CYNDER_PAYMAYA_VERSION', '1.1.3');
define('CYNDER_PAYMAYA_BASE_SANDBOX_URL', 'https://pg-sandbox.paymaya.com');
define('CYNDER_PAYMAYA_BASE_PRODUCTION_URL', 'https://pg.maya.ph');
define(
'CYNDER_PAYMAYA_PLUGIN_URL',
untrailingslashit(
plugins_url(
basename(plugin_dir_path(__FILE__)),
basename(__FILE__)
)
)
);
if (!class_exists('Cynder_Paymaya')) :
/**
* Paymaya Class
*
* @category Class
* @package Paymaya
* @author Cyndertech <[email protected]>
* @license n/a (http://127.0.0.0)
* @link n/a
* @phpcs:disable Standard.Cat.SniffName
*/
class Cynder_Paymaya
{
/**
* *Singleton* instance of this class
*
* @var Singleton The reference the *Singleton* instance of this class
*/
private static $_instance;
/**
* Returns the *Singleton* instance of this class.
*
* @return Singleton The *Singleton* instance.
*/
public static function getInstance()
{
if (null === self::$_instance) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Private clone method to prevent cloning of the instance of the
* *Singleton* instance.
*
* @return void
*/
private function __clone()
{
// empty
}
/**
* Private unserialize method to prevent unserializing of the *Singleton*
* instance.
*
* @return void
*/
public function __wakeup()
{
// empty
}
/**
* Protected constructor to prevent creating a new instance of the
* *Singleton* via the `new` operator from outside of this class.
*/
private function __construct()
{
add_action('admin_init', array($this, 'install'));
$this->init();
}
/**
* Initialize Paymaya plugin
*
* @return void
*
* @since 1.0.0
*/
public function init()
{
$fileDir = dirname(__FILE__);
include_once $fileDir.'/classes/cynder-paymaya.php';
include_once 'paymaya-top-level-hooks.php';
add_filter(
'woocommerce_payment_gateways',
array($this, 'addGateways')
);
if (version_compare(WC_VERSION, '3.4', '<')) {
add_filter(
'woocommerce_get_sections_checkout',
array($this, 'filterGatewayOrderAdmin')
);
}
}
/**
* Registers Payment Gateways
*
* @param $methods array of methods
*
* @return array
*
* @since 1.0.0
*/
public function addGateways($methods)
{
$methods[] = 'Cynder_Paymaya_Gateway';
return $methods;
}
/**
* Registers Payment Gateways
*
* @param array $sections array of sections
*
* @return array
*
* @since 1.0.0
*/
public function filterGatewayOrderAdmin($sections)
{
unset($sections['paymaya']);
$gatewayName = 'woocommerce-gateway-paymaya';
$sections['paymaya'] = __(
'Payments via Maya',
$gatewayName
);
$sections = [];
return $sections;
}
/**
* Install/Update function
*
* @return void
*
* @since 1.0.0
*/
public function install()
{
if (!is_plugin_active(plugin_basename(__FILE__))) {
return;
}
if (!defined('IFRAME_REQUEST')
&& (CYNDER_PAYMAYA_VERSION !== get_option(
'cynder_paymaya_version'
))
) {
do_action('woocommerce_paymaya_updated');
if (!defined('CYNDER_PAYMAYA_INSTALLING')) {
define('CYNDER_PAYMAYA_INSTALLING', true);
}
$this->updatePluginVersion();
}
}
/**
* Updates Plugin Version
*
* @return void
*
* @since 1.0.0
*/
public function updatePluginVersion()
{
delete_option('cynder_paymaya_version');
update_option('cynder_paymaya_version', CYNDER_PAYMAYA_VERSION);
}
}
Cynder_Paymaya::getInstance();
endif;
}
add_action('plugins_loaded', 'paymaya_init_gateway_class');