1 | <?php |
||
17 | class EEM_Payment_Method extends EEM_Base |
||
18 | { |
||
19 | |||
20 | const scope_cart = 'CART'; |
||
21 | |||
22 | const scope_admin = 'ADMIN'; |
||
23 | |||
24 | const scope_api = 'API'; |
||
25 | |||
26 | /** |
||
27 | * @type EEM_Payment_Method |
||
28 | */ |
||
29 | protected static $_instance = null; |
||
30 | |||
31 | |||
32 | /** |
||
33 | * private constructor to prevent direct creation |
||
34 | * |
||
35 | * @param null $timezone |
||
36 | * @throws EE_Error |
||
37 | */ |
||
38 | protected function __construct($timezone = null) |
||
128 | |||
129 | |||
130 | /** |
||
131 | * Gets one by the slug provided |
||
132 | * |
||
133 | * @param string $slug |
||
134 | * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
||
135 | * @throws EE_Error |
||
136 | */ |
||
137 | public function get_one_by_slug($slug) |
||
141 | |||
142 | |||
143 | /** |
||
144 | * Gets all the acceptable scopes for payment methods. |
||
145 | * Keys are their names as store din the DB, and values are nice names for displaying them |
||
146 | * |
||
147 | * @return array |
||
148 | */ |
||
149 | public function scopes() |
||
162 | |||
163 | |||
164 | /** |
||
165 | * Determines if this is an valid scope |
||
166 | * |
||
167 | * @param string $scope like one of EEM_Payment_Method::instance()->scopes() |
||
168 | * @return boolean |
||
169 | */ |
||
170 | public function is_valid_scope($scope) |
||
178 | |||
179 | |||
180 | /** |
||
181 | * Gets all active payment methods |
||
182 | * |
||
183 | * @param string $scope one of |
||
184 | * @param array $query_params |
||
185 | * @return EE_Base_Class[]|EE_Payment_Method[] |
||
186 | * @throws EE_Error |
||
187 | */ |
||
188 | public function get_all_active($scope = null, $query_params = []) |
||
195 | |||
196 | |||
197 | /** |
||
198 | * Counts all active gateways in the specified scope |
||
199 | * |
||
200 | * @param string $scope one of EEM_Payment_Method::scope_* |
||
201 | * @param array $query_params |
||
202 | * @return int |
||
203 | * @throws EE_Error |
||
204 | */ |
||
205 | public function count_active($scope = null, $query_params = []) |
||
209 | |||
210 | |||
211 | /** |
||
212 | * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
||
213 | * argument to get all active for a given scope |
||
214 | * |
||
215 | * @param string $scope one of the constants EEM_Payment_Method::scope_* |
||
216 | * @param array $query_params |
||
217 | * @return array |
||
218 | * @throws EE_Error |
||
219 | * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
||
220 | */ |
||
221 | protected function _get_query_params_for_all_active($scope = null, $query_params = []) |
||
242 | |||
243 | |||
244 | /** |
||
245 | * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
||
246 | * argument to get all active for a given scope |
||
247 | * |
||
248 | * @param string $scope one of the constants EEM_Payment_Method::scope_* |
||
249 | * @param array $query_params |
||
250 | * @return array |
||
251 | * @throws EE_Error |
||
252 | * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
||
253 | */ |
||
254 | public function get_query_params_for_all_active($scope = null, $query_params = []) |
||
258 | |||
259 | |||
260 | /** |
||
261 | * Gets one active payment method. see @get_all_active for documentation |
||
262 | * |
||
263 | * @param string $scope |
||
264 | * @param array $query_params |
||
265 | * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
||
266 | * @throws EE_Error |
||
267 | */ |
||
268 | public function get_one_active($scope = null, $query_params = []) |
||
272 | |||
273 | |||
274 | /** |
||
275 | * Gets one payment method of that type, regardless of whether its active or not |
||
276 | * |
||
277 | * @param string $type |
||
278 | * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
||
279 | * @throws EE_Error |
||
280 | */ |
||
281 | public function get_one_of_type($type) |
||
285 | |||
286 | |||
287 | /** |
||
288 | * Overrides parent ot also check by the slug |
||
289 | * |
||
290 | * @param string|int|EE_Payment_Method $base_class_obj_or_id |
||
291 | * @param boolean $ensure_is_in_db |
||
292 | * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|int|string |
||
293 | * @throws EE_Error |
||
294 | * @see EEM_Base::ensure_is_obj() |
||
295 | */ |
||
296 | public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = false) |
||
318 | |||
319 | |||
320 | /** |
||
321 | * Gets the ID of this object, or if its a string finds the object's id |
||
322 | * associated with that slug |
||
323 | * |
||
324 | * @param mixed $base_obj_or_id_or_slug |
||
325 | * @return int |
||
326 | * @throws EE_Error |
||
327 | */ |
||
328 | public function ensure_is_ID($base_obj_or_id_or_slug) |
||
336 | |||
337 | |||
338 | /** |
||
339 | * Verifies the button urls on all the passed payment methods have a valid button url. |
||
340 | * If not, resets them to their default. |
||
341 | * |
||
342 | * @param EE_Payment_Method[] $payment_methods if NULL, defaults to all payment methods active in the cart |
||
343 | * @throws EE_Error |
||
344 | * @throws ReflectionException |
||
345 | */ |
||
346 | public function verify_button_urls($payment_methods = null) |
||
373 | |||
374 | |||
375 | /** |
||
376 | * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, |
||
377 | * but also verifies the payment method type of each is a usable object. If not, |
||
378 | * deactivate it, sets a notification, and deactivates it |
||
379 | * |
||
380 | * @param array $rows |
||
381 | * @return EE_Payment_Method[] |
||
382 | * @throws EE_Error |
||
383 | * @throws InvalidDataTypeException |
||
384 | * @throws ReflectionException |
||
385 | */ |
||
386 | protected function _create_objects($rows = []) |
||
425 | |||
426 | |||
427 | /** |
||
428 | * Gets all the payment methods which can be used for transaction |
||
429 | * (according to the relations between payment methods and events, and |
||
430 | * the currencies used for the transaction and their relation to payment methods) |
||
431 | * |
||
432 | * @param EE_Transaction $transaction |
||
433 | * @param string $scope @see EEM_Payment_Method::get_all_for_events |
||
434 | * @return EE_Payment_Method[] |
||
435 | * @throws EE_Error |
||
436 | */ |
||
437 | public function get_all_for_transaction($transaction, $scope) |
||
447 | |||
448 | |||
449 | /** |
||
450 | * Returns the payment method used for the last payment made for a registration. |
||
451 | * Note: if an offline payment method was selected on the related transaction then this will have no payment |
||
452 | * methods returned. It will ONLY return a payment method for a PAYMENT recorded against the registration. |
||
453 | * |
||
454 | * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the |
||
455 | * registration. |
||
456 | * @return EE_Payment|null |
||
457 | * @throws EE_Error |
||
458 | */ |
||
459 | public function get_last_used_for_registration($registration_or_reg_id) |
||
471 | } |
||
472 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: