self::TIMEOUT, 'redirection' => 0, 'headers' => array_merge( array( 'Content-Type' => 'application/json' ), $headers ), 'body' => $body, ) ); return is_wp_error( $response ) ? 0 : (int) wp_remote_retrieve_response_code( $response ); } public static function webhook( array $payload ): int { $body = (string) wp_json_encode( $payload ); $timestamp = (string) time(); return self::post_json( Connection::endpoint( 'api_base' ) . '/webhooks/woocommerce', $body, array( 'X-Flowfy-Store' => Connection::site_id(), 'X-Flowfy-Timestamp' => $timestamp, 'X-Flowfy-Signature' => self::signature( $timestamp, $body, Connection::signing_secret_bytes() ), ) ); } public static function signature( string $timestamp, string $body, string $secret_bytes ): string { return base64_encode( hash_hmac( 'sha256', $timestamp . '.' . $body, $secret_bytes, true ) ); } public static function track( array $event ): int { return self::post_json( self::track_url(), (string) wp_json_encode( $event ) ); } public static function track_url(): string { return Connection::endpoint( 'edge_base' ) . '/v1/track?writeKey=' . rawurlencode( base64_encode( Connection::write_key() ) ); } public static function is_success( int $code ): bool { return $code >= 200 && $code < 300; } }