# booktics/1.0.29/core/module/zoho/zoho-service.php

Booktics – Appointment Booking Calendar for Service Businesses, version 1.0.29. 80 lines.

- Page: https://pluginprobe.com/plugins/booktics/1.0.29/code/core/module/zoho/zoho-service.php
- Raw: https://pluginprobe.com/plugins/booktics/1.0.29/raw/core/module/zoho/zoho-service.php
- Modified: 2026-07-29T07:25:12+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/booktics/1.0.29/code/core/module/zoho/zoho-service.php#L10-L20`.

```php
<?php
/**
 * Zoho Service
 *
 * Handles Zoho integration for Booktics orders via webhook (Zoho Flow).
 */

namespace Booktics\Module\Zoho;

if ( ! defined( 'ABSPATH' ) ) exit;

use Booktics\Contracts\Hookable_Service_Contract;
use Booktics\Abstracts\Booktics_Database;
use Booktics\Models\Guest_Model;

class Zoho_Service implements Hookable_Service_Contract {
	/**
	 * Register hooks
	 */
	public function register() {
		add_action( 'booktics_after_order_created', array( $this, 'send_to_zoho' ), 10, 2 );
	}

	/**
	 * Send customer data to the configured Zoho (Zoho Flow) webhook.
	 *
	 * @param object $order_model   The order model.
	 * @param array  $appointments  Created appointments (unused).
	 */
	public function send_to_zoho( $order_model, $appointments = array() ) {
		$webhook_url = booktics_get_option( 'zoho_webhook_url' );
		if ( empty( $webhook_url ) ) {
			return;
		}

		// Get customer details. customer_id is a Booktics guest record id, not a WP user id.
		$customer = ( new Guest_Model( new Booktics_Database() ) )->find( array( 'id' => $order_model->customer_id ) );
		if ( ! $customer || is_wp_error( $customer ) ) {
			return;
		}

		$name_parts = preg_split( '/\s+/', trim( (string) $customer->name ), 2 );

		$customer_data = array(
			'email'      => $customer->email,
			'first_name' => $name_parts[0] ?? '',
			'last_name'  => $name_parts[1] ?? '',
			'status'     => 'subscribed',
		);

		try {
			$this->send_webhook( $webhook_url, $customer_data );
		} catch ( \Throwable $e ) {
			// Ensures silent failure in case of any error.
			if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
				error_log( 'Zoho Error: ' . $e->getMessage() ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
			}
		}
	}

	private function send_webhook( $url, $data ) {
		$response = wp_remote_post(
			$url,
			array(
				'body'    => wp_json_encode( $data ),
				'headers' => array(
					'Content-Type' => 'application/json',
				),
				'timeout' => 15,
			)
		);

		if ( is_wp_error( $response ) ) {
			if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
				error_log( 'Zoho Webhook Error: ' . $response->get_error_message() ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
			}
		}
	}
}

```
