PHP code example of arraypress / wp-webhooks

1. Go to this page and download the library: Download arraypress/wp-webhooks library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arraypress / wp-webhooks example snippets


use ArrayPress\Webhooks\RetryPolicy;
use ArrayPress\Webhooks\Signature;

// Sending.
$payload   = wp_json_encode( [ 'event' => 'order.completed', 'id' => 1001 ] );
$signature = Signature::sign( $payload, $endpoint_secret );

wp_remote_post( $endpoint_url, [
    'headers' => [ 'Webhook-Signature' => $signature ],
    'body'    => $payload,
] );

// Receiving.
$result = Signature::verify( $raw_body, $header, $secret );

if ( ! $result->valid ) {
    status_header( 400 );
    exit;
}

// Failed delivery: worth another go?
if ( RetryPolicy::should_retry( $status, $attempt ) ) {
    $seconds = RetryPolicy::delay( $attempt );
}