1 | <?php |
||
26 | class AuthnetWebhook |
||
27 | { |
||
28 | /** |
||
29 | * @var object SimpleXML object representing the Webhook notification |
||
30 | */ |
||
31 | private $webhook; |
||
32 | |||
33 | /** |
||
34 | * @var string JSON string that is the Webhook notification sent by Authorize.Net |
||
35 | */ |
||
36 | private $webhookJson; |
||
37 | |||
38 | /** |
||
39 | * @var array HTTP headers sent with the notification |
||
40 | */ |
||
41 | private $headers; |
||
42 | |||
43 | /** |
||
44 | * @var string Authorize.Net Signature Key |
||
45 | */ |
||
46 | private $signature; |
||
47 | |||
48 | /** |
||
49 | * Creates the response object with the response json returned from the API call |
||
50 | * |
||
51 | * @param string $signature Authorize.Net Signature Key |
||
52 | * @param string $payload Webhook Notification sent by Authorize.Net |
||
53 | * @param array $headers HTTP headers sent with Webhook. Optional if PHP is run as an Apache module |
||
54 | * @throws AuthnetInvalidCredentialsException |
||
55 | * @throws AuthnetInvalidJsonException |
||
56 | */ |
||
57 | 3 | public function __construct(string $signature, string $payload, array $headers = []) |
|
73 | |||
74 | /** |
||
75 | * Outputs the response JSON in a human readable format |
||
76 | * |
||
77 | * @return string HTML table containing debugging information |
||
78 | */ |
||
79 | 1 | public function __toString() |
|
95 | |||
96 | /** |
||
97 | * Gets a response variable from the Webhook notification |
||
98 | * |
||
99 | * @param string $var |
||
100 | * @return string requested variable from the API call response |
||
101 | */ |
||
102 | 1 | public function __get($var) |
|
106 | |||
107 | /** |
||
108 | * Validates a webhook signature to determine if the webhook is valid |
||
109 | * |
||
110 | * @return bool |
||
111 | */ |
||
112 | 3 | public function isValid() : bool |
|
118 | |||
119 | /** |
||
120 | * Validates a webhook signature to determine if the webhook is valid |
||
121 | * |
||
122 | * @return string|null |
||
123 | */ |
||
124 | 1 | public function getRequestId() : ?string |
|
128 | |||
129 | /** |
||
130 | * Retrieves all HTTP headers of a given request |
||
131 | * |
||
132 | * @return array |
||
133 | */ |
||
134 | 1 | protected function getAllHeaders() : array |
|
148 | } |
||
149 |