-
Notifications
You must be signed in to change notification settings - Fork 0
/
lifterlms-gateway-nextpay.php
168 lines (132 loc) · 3.82 KB
/
lifterlms-gateway-nextpay.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
<?php
/**
* Plugin Name: LifterLMS Nextpay Gateway
* Plugin URI: https://lifterlms.com/
* Description: Sell LifterLMS courses and memberships using Nextpay Gateway
* Version: 1.0.0
* Author: Nextpay
* Author URI: https://nextpay.ir
* Text Domain: lifterlms-nextpay
* Domain Path: /languages
* License: GPLv2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Requires at least: 4.2
* Tested up to: 4.5.3
*
* @package LifterLMS Nextpay
* @category Core
* @author LifterLMS
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Restrict direct access
if ( ! class_exists( 'LifterLMS_Nextpay') ) :
final class LifterLMS_Nextpay {
/**
* Plugin Version
*/
public $version = '1.0.0';
/**
* Singleton class instance
* @var obj
* @since 1.0.0
* @version 1.0.0
*/
protected static $_instance = null;
/**
* Main Instance of LifterLMS_Nextpay
* Ensures only one instance of LifterLMS_Nextpay is loaded or can be loaded.
* @see LLMS_Gateway_Nextpay()
* @return LifterLMS_Nextpay - Main instance
* @since 1.0.0
* @version 1.0.0
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Constructor
* @since 1.0.0
* @version 1.0.0
* @return void
*/
private function __construct() {
$this->define_constants();
add_action( 'plugins_loaded', array( $this, 'init' ), 10 );
}
/**
* Define plugin constants
* @return void
* @since 3.0.0
* @version 3.0.0
*/
private function define_constants() {
// LLMS Nextpay Plugin File
if ( ! defined( 'LLMS_Nextpay_PLUGIN_FILE' ) ) {
define( 'LLMS_Nextpay_PLUGIN_FILE', __FILE__ );
}
// LLMS Convert Kit Plugin Directory
if ( ! defined( 'LLMS_Nextpay_PLUGIN_DIR' ) ) {
define( 'LLMS_Nextpay_PLUGIN_DIR', WP_PLUGIN_DIR . "/" . plugin_basename( dirname(__FILE__) ) . '/');
}
}
/**
* Initialize, require, add hooks & filters
* @return void
* @since 1.0.0
* @version 1.0.0
*/
public function init() {
// can only function with LifterLMS 3.0.0 or later
if ( function_exists( 'LLMS' ) && version_compare( '3.0.0-alpha', LLMS()->version, '<=' ) ) {
add_action( 'lifterlms_settings_save_checkout', array( $this, 'maybe_check_reference_transactions' ) );
add_filter( 'lifterlms_payment_gateways', array( $this, 'register_gateway' ), 10, 1 );
require_once 'includes/class.llms.payment.gateway.nextpay.php';
}
}
/**
* When saving the Checkout tab, check reference transactions if the check button was clicked
* @return void
* @since 1.0.0
* @version 1.0.0
*/
public function maybe_check_reference_transactions() {
$gateways = LLMS()->payment_gateways();
$g = $gateways->get_gateway_by_id( 'Nextpay' );
$check = false;
// if live creds have changed we should check ref transactions on the new creds
if ( isset( $_POST[ $g->get_option_name( 'api_key' ) ] ) && $g->get_api_key() !== $_POST[ $g->get_option_name( 'api_key' ) ] ) {
$check = true;
} elseif ( isset( $_POST['llms_gateway_Nextpay_check_ref_trans'] ) ) {
$check = true;
}
// checkem
if ( $check ) {
// wait until after settings are saved so that the check will always be run with the credentials that we're just submitted
add_action( 'lifterlms_settings_saved', array( $g, 'check_reference_transactions' ) );
}
}
/**
* Register the gateway with LifterLMS
* @param array $gateways array of currently registered gateways
* @return array
* @since 1.0.0
* @version 1.0.0
*/
public function register_gateway( $gateways ) {
$gateways[] = 'LLMS_Payment_Gateway_Nextpay';
return $gateways;
}
}
endif;
/**
* Returns the main instance of LifterLMS_Nextpay
* @return LifterLMS
* @since 1.0.0
* @version 1.0.0
*/
function LLMS_Gateway_Nextpay() {
return LifterLMS_Nextpay::instance();
}
return LLMS_Gateway_Nextpay();