PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.7.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.7.1
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / inc / gateways / class-lp-gateway-abstract.php

class-lp-gateway-abstract.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.1.7.1, at inc/gateways/class-lp-gateway-abstract.php

248 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class LP_Gateway_Abstract
5 *
6 * @author ThimPress
7 * @package LearnPress/Classes
8 * @version 1.0
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 class LP_Gateway_Abstract extends LP_Abstract_Settings {
16
17 /**
18 * @var null
19 */
20 public $id = null;
21
22 /**
23 * Name of gateway will be displayed in admin settings.
24 *
25 * @var string
26 */
27 protected $method_title = '';
28
29 /**
30 * Description of gateway will be displayed in admin settings.
31 *
32 * @var string
33 */
34 protected $method_description = '';
35
36 /**
37 * @var string
38 */
39 public $order_button_text = '';
40
41 /**
42 * This payment is turn on or off?
43 *
44 * @var string
45 */
46 public $enabled = 'no';
47
48 /**
49 * @var null
50 */
51 public $title = null;
52
53 /**
54 * @var null
55 */
56 public $description = null;
57
58 /**
59 * @var string
60 */
61 protected $icon = '';
62
63 protected $stored = false;
64
65 /**
66 * Constructor
67 */
68 public function __construct() {
69 if ( ! $this->admin_name ) {
70 $this->admin_name = preg_replace( '!LP_Gateway_!', '', get_class( $this ) );
71 }
72
73 if ( ! $this->id ) {
74 $this->id = sanitize_title( $this->title );
75 }
76
77 $this->settings = LP_Settings::instance()->get_group( $this->id, '' );
78 $this->enabled = $this->settings->get( 'enable' );
79
80 add_filter( 'learn-press/admin/get-settings/admin-options-' . $this->id, array( $this, 'get_settings' ) );
81 }
82
83 /**
84 * Return unique Id of payment
85 *
86 * @return null|string
87 */
88 public function get_id() {
89 return $this->id;
90 }
91
92 /**
93 * Return method title.
94 *
95 * @return string
96 */
97 public function get_method_title() {
98 return $this->method_title;
99 }
100
101 /**
102 * Return method description.
103 *
104 * @return string
105 */
106 public function get_method_description() {
107 return $this->method_description;
108 }
109
110 /**
111 * Return method title displays in front end.
112 *
113 * @return string
114 */
115 public function get_title() {
116 return apply_filters( 'learn_press_gateway_title', $this->title, $this->id );
117 }
118
119 /**
120 * Return method description displays in front end.
121 *
122 * @return string
123 */
124 public function get_description() {
125 return apply_filters( 'learn_press_gateway_description', $this->description, $this->id );
126 }
127
128 public function is_enabled() {
129 return $this->enabled == 'yes';
130 }
131
132 public function enable( $status ) {
133 if ( is_bool( $status ) ) {
134 $this->enabled = $status;
135
136 $options = get_option( 'learn_press_' . $this->get_id() );
137
138 if ( ! $options ) {
139 $options = array();
140 }
141
142 $options['enable'] = $status ? 'yes' : 'no';
143 update_option( 'learn_press_' . $this->get_id(), $options );
144 }
145
146 return $this->enabled == 'yes';
147 }
148
149 /**
150 * Process the payment.
151 *
152 * @param $order_id
153 *
154 * @return array
155 */
156 public function process_payment( $order_id ) {
157 return array();
158 }
159
160 /**
161 * Get the icon of payment displays in front end.
162 *
163 * @return mixed
164 */
165 public function get_icon() {
166 $size = apply_filters( 'learn-press/default-payment-gateway-icon-sizes', null ); // array( 52, 32 ) is low quatity.
167
168 if ( $size ) {
169 $icon_size = sprintf( 'width: %dpx; height: %dpx', $size[0], $size[1] );
170 } else {
171 $icon_size = '';
172 }
173
174 $icon = $this->icon ? '<img class="gateway-icon" src="' . $this->icon . '" alt="' . esc_attr( $this->get_title() ) . '" style="' . $icon_size . '" />' : '';
175
176 return apply_filters( 'learn_press_gateway_icon', $icon, $this->id );
177 }
178
179 /**
180 * Return the form where user can input payment details or anything else.
181 *
182 * @return string
183 */
184 public function get_payment_form() {
185 return '';
186 }
187
188 /**
189 * Validate required field before submitting fields.
190 *
191 * @return bool
192 */
193 public function validate_fields() {
194 // TODO: validate fields if needed
195 return true;
196 }
197
198 /**
199 * @param LP_Order $order
200 *
201 * @return mixed
202 */
203 public function get_return_url( $order = null ) {
204 if ( $order ) {
205 $return_url = $order->get_checkout_order_received_url();
206 } else {
207 $return_url = learn_press_get_endpoint_url( 'lp-order-received', '', learn_press_get_page_link( 'checkout' ) );
208 }
209
210 return apply_filters( 'learn_press_get_return_url', $return_url, $order );
211 }
212
213 public function __get( $prop ) {
214 switch ( $prop ) {
215 case 'method_title':
216 case 'method_description':
217 case 'id':
218 _deprecated_argument( $prop, '3.0.0', sprintf( __( '%s has been deprecated. Please use % instead of.', 'learnpress' ), $prop, "get_{$prop}" ) );
219
220 return call_user_func( array( $this, "get_{$prop}" ) );
221 default:
222 return property_exists( $this, $prop ) ? $this->{$prop} : false;
223 }
224 }
225
226 /**
227 * @since 3.0.0
228 *
229 * return bool
230 */
231 public function is_display() {
232 $display = apply_filters( 'learn-press/payment-method/display', true, $this->id );
233 $display = apply_filters( 'learn-press/payment-method-' . $this->id . '/display', $display );
234
235 // @deprecated
236 $display = apply_filters( 'learn_press_display_payment_method', $display, $this->id );
237
238 return $display;
239 }
240
241 /**
242 * @return string
243 */
244 public function __toString() {
245 return $this->method_title;
246 }
247 }
248