Back | Home
الـ Path الحالي: /home/picotech/domains/instantly.picotech.app/public_html/public/./../app/.././../../finland.picotech.app/public_html/storage/../vendor/./nikic/../dompdf/../alexandr-mironov/../monolog/../unicodeveloper/../dragonmantank/../telnyx/../filp/../phpstan/../nikic/../psy/.././messagebird/.././doctrine/.././telnyx/../ralouphie/../telnyx/telnyx-php/lib
الملفات الموجودة في هذا الـ Path:
.
..
Address.php
AlphanumericSenderID.php
ApiOperations
ApiRequestor.php
ApiResource.php
ApiResponse.php
AvailablePhoneNumber.php
Balance.php
BillingGroup.php
Brand.php
Call.php
CallControlApplication.php
Campaign.php
Collection.php
Conference.php
Connection.php
CredentialConnection.php
ErrorObject.php
Event.php
Exception
FQDN.php
FQDNConnection.php
Fax.php
FaxApplication.php
HttpClient
IP.php
IPConnection.php
InboundChannel.php
Message.php
MessagingHostedNumberOrder.php
MessagingPhoneNumber.php
MessagingProfile.php
MobileOperatorNetwork.php
NumberLookup.php
NumberOrder.php
NumberOrderDocument.php
NumberReservation.php
OtaUpdate.php
OutboundVoiceProfile.php
PhoneNumber
PhoneNumber.php
PhoneNumberAssignmentByProfile.php
PhoneNumberCampaign.php
PortingOrder.php
PortingPhoneNumber.php
Portout.php
RegulatoryRequirement.php
RequestTelemetry.php
ShortCode.php
SimCard.php
TelephonyCredential.php
Telnyx.php
TelnyxObject.php
Util
Verification.php
VerifyProfile.php
VerifyVerification.php
Webhook.php
WebhookSignature.php

مشاهدة ملف: Webhook.php

<?php

namespace Telnyx;

abstract class Webhook
{
    const DEFAULT_TOLERANCE = 300;

    /**
     * Alias for constructEvent().
     * Returns an Event instance using the current HTTPS request. Throws an
     * Exception\UnexpectedValueException if the payload is not valid JSON, and
     * an Exception\SignatureVerificationException if the signature
     * verification fails for any reason.
     *
     * @param string $public_key secret used to generate the signature
     * @param int $tolerance maximum difference allowed between the header's
     *  timestamp and the current time
     *
     * @throws Exception\UnexpectedValueException if the payload is not valid JSON,
     * @throws Exception\SignatureVerificationException if the verification fails
     *
     * @return Event the Event instance
     */
    public static function constructFromRequest($public_key = '', $tolerance = self::DEFAULT_TOLERANCE)
    {
        if (!isset($_SERVER['HTTP_TELNYX_SIGNATURE_ED25519']) || !isset($_SERVER['HTTP_TELNYX_TIMESTAMP'])) {
            throw Exception\SignatureVerificationException::factory(
                'Unable to extract timestamp and signatures from header'
            );
        }

        $payload = @file_get_contents('php://input');
        $sig_header = $_SERVER['HTTP_TELNYX_SIGNATURE_ED25519'];
        $timestamp_header = $_SERVER['HTTP_TELNYX_TIMESTAMP'];

        return \Telnyx\Webhook::constructEvent(
            $payload, $sig_header, $timestamp_header, $public_key, $tolerance
        );
    }

    /**
     * Returns an Event instance using the provided JSON payload. Throws an
     * Exception\UnexpectedValueException if the payload is not valid JSON, and
     * an Exception\SignatureVerificationException if the signature
     * verification fails for any reason.
     *
     * @param string $payload the payload sent by Telnyx
     * @param string $signature_header the contents of the signature header sent by Telnyx
     * @param string $timestamp the timestamp from the header sent by Telnyx
     * @param string $public_key secret used to generate the signature
     * @param int $tolerance maximum difference allowed between the header's
     *  timestamp and the current time
     *
     * @throws Exception\UnexpectedValueException if the payload is not valid JSON,
     * @throws Exception\SignatureVerificationException if the verification fails
     *
     * @return Event the Event instance
     */
    public static function constructEvent($payload, $signature_header, $timestamp, $public_key = '', $tolerance = self::DEFAULT_TOLERANCE)
    {
        WebhookSignature::verifyHeader($payload, $signature_header, $timestamp, $public_key, $tolerance);

        $data = \json_decode($payload, true);
        $jsonError = \json_last_error();
        if (null === $data && \JSON_ERROR_NONE !== $jsonError) {
            $msg = "Invalid payload: {$payload} "
              . "(json_last_error() was {$jsonError})";

            throw new Exception\UnexpectedValueException($msg);
        }

        return Event::constructFrom($data);
    }
}