PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / Framework / PaymentGateways / Traits / HasRouteMethods.php

HasRouteMethods.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/Framework/PaymentGateways/Traits/HasRouteMethods.php

74 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Framework\PaymentGateways\Traits;
4
5 use Give\Framework\Exceptions\Primitives\Exception;
6 use Give\Framework\PaymentGateways\Exceptions\PaymentGatewayException;
7 use Give\Framework\PaymentGateways\SubscriptionModule;
8
9 /**
10 * @since 2.20.0
11 * @property SubscriptionModule $subscriptionModule
12 * @property array $routeMethods
13 * @property array $secureRouteMethods
14 */
15 trait HasRouteMethods
16 {
17 /**
18 * Route methods are used to extend the gateway api.
19 * By adding a custom routeMethod, you are effectively
20 * registering a new public route url that will resolve itself and
21 * call your method.
22 *
23 * @var string[]
24 */
25 public $routeMethods = [];
26
27 /**
28 * Secure Route methods are used to extend the gateway api with an additional wp_nonce.
29 * By adding a custom secureRouteMethod, you are effectively
30 * registering a new route url that will resolve itself and
31 * call your method after validating the nonce.
32 *
33 * @var string[]
34 */
35 public $secureRouteMethods = [];
36
37 /**
38 * @since 2.20.0
39 *
40 * @param string $method
41 *
42 * @return bool
43 */
44 public function supportsMethodRoute($method)
45 {
46 $allGatewayMethods = array_merge($this->routeMethods, $this->secureRouteMethods);
47
48 return in_array($method, $allGatewayMethods, true);
49 }
50
51 /**
52 * @since 2.20.0
53 *
54 * @param string $method
55 *
56 * @throws Exception
57 */
58 public function callRouteMethod($method, $queryParams)
59 {
60 if ($this->supportsMethodRoute($method)) {
61 return $this->$method($queryParams);
62 }
63
64 throw new PaymentGatewayException(
65 sprintf(
66 '%1$s route method is not supported by %2$s and %3$s',
67 $method,
68 get_class($this),
69 get_class($this->subscriptionModule)
70 )
71 );
72 }
73 }
74