Edit File by line
/home/zeestwma/ceyloniy.../wp-conte.../plugins/wpforms-.../src/Integrat.../Square/Api
File: WebhookEvent.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace WPForms\Integrations\Square\Api;
[2] Fix | Delete
[3] Fix | Delete
use RuntimeException;
[4] Fix | Delete
use WPForms\Integrations\Square\Helpers;
[5] Fix | Delete
use WPForms\Vendor\Square\Utils\WebhooksHelper;
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Webhook event handler.
[9] Fix | Delete
*
[10] Fix | Delete
* @since 1.9.5
[11] Fix | Delete
*/
[12] Fix | Delete
class WebhookEvent {
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* Construct and validate the Square webhook event.
[16] Fix | Delete
*
[17] Fix | Delete
* @since 1.9.5
[18] Fix | Delete
*
[19] Fix | Delete
* @param string $payload The raw JSON payload from Square.
[20] Fix | Delete
* @param string $signature The Square webhook signature from headers.
[21] Fix | Delete
* @param string $webhook_secret The webhook signing secret from Square Developer Dashboard.
[22] Fix | Delete
*
[23] Fix | Delete
* @return object The decoded event data.
[24] Fix | Delete
*
[25] Fix | Delete
* @throws RuntimeException If the webhook payload structure is invalid.
[26] Fix | Delete
*/
[27] Fix | Delete
public static function construct_event( string $payload, string $signature, string $webhook_secret ) {
[28] Fix | Delete
[29] Fix | Delete
// Validate the webhook signature.
[30] Fix | Delete
if ( ! WebhooksHelper::isValidWebhookEventSignature( $payload, $signature, $webhook_secret, Helpers::get_webhook_url() ) ) {
[31] Fix | Delete
throw new RuntimeException( 'Invalid webhook signature. Possible unauthorized request.' );
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
// Decode JSON payload.
[35] Fix | Delete
$event = json_decode( $payload, false );
[36] Fix | Delete
[37] Fix | Delete
// Check for JSON decoding errors.
[38] Fix | Delete
if ( json_last_error() !== JSON_ERROR_NONE ) {
[39] Fix | Delete
throw new RuntimeException( 'Invalid JSON payload' );
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
if ( ! $event || ! isset( $event->type, $event->data ) ) {
[43] Fix | Delete
throw new RuntimeException( 'Invalid webhook payload structure.' );
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
return $event;
[47] Fix | Delete
}
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function