PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.15.4
GiveWP – Donation Plugin and Fundraising Platform v4.15.4
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 / vendor / stripe / stripe-php / lib / Webhook.php

Webhook.php in GiveWP – Donation Plugin and Fundraising Platform 4.15.4, at vendor/stripe/stripe-php/lib/Webhook.php

43 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Stripe;
4
5 abstract class Webhook
6 {
7 const DEFAULT_TOLERANCE = 300;
8
9 /**
10 * Returns an Event instance using the provided JSON payload. Throws an
11 * Exception\UnexpectedValueException if the payload is not valid JSON, and
12 * an Exception\SignatureVerificationException if the signature
13 * verification fails for any reason.
14 *
15 * @param string $payload the payload sent by Stripe
16 * @param string $sigHeader the contents of the signature header sent by
17 * Stripe
18 * @param string $secret secret used to generate the signature
19 * @param int $tolerance maximum difference allowed between the header's
20 * timestamp and the current time
21 *
22 * @throws Exception\UnexpectedValueException if the payload is not valid JSON,
23 * @throws Exception\SignatureVerificationException if the verification fails
24 *
25 * @return Event the Event instance
26 */
27 public static function constructEvent($payload, $sigHeader, $secret, $tolerance = self::DEFAULT_TOLERANCE)
28 {
29 WebhookSignature::verifyHeader($payload, $sigHeader, $secret, $tolerance);
30
31 $data = \json_decode($payload, true);
32 $jsonError = \json_last_error();
33 if (null === $data && \JSON_ERROR_NONE !== $jsonError) {
34 $msg = "Invalid payload: {$payload} "
35 . "(json_last_error() was {$jsonError})";
36
37 throw new Exception\UnexpectedValueException($msg);
38 }
39
40 return Event::constructFrom($data);
41 }
42 }
43