# booktics/1.0.2/core/module/fluentcrm/fluentcrm-service.php

Booktics – Appointment Booking Calendar for Service Businesses, version 1.0.2. 90 lines.

- Page: https://pluginprobe.com/plugins/booktics/1.0.2/code/core/module/fluentcrm/fluentcrm-service.php
- Raw: https://pluginprobe.com/plugins/booktics/1.0.2/raw/core/module/fluentcrm/fluentcrm-service.php
- Modified: 2025-07-10T05:36:58+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.2/code/core/module/fluentcrm/fluentcrm-service.php#L10-L20`.

```php
<?php
/**
 * FluentCRM Service
 *
 * Handles FluentCRM integration for Booktics orders
 */

namespace Booktics\Module\FluentCrm;

use Booktics\Contracts\Hookable_Service_Contract;

class FluentCRM_Service implements Hookable_Service_Contract {
	/**
	 * Register hooks
	 */
	public function register() {
		add_action( 'booktics_order_created', array( $this, 'add_contact_to_fluentcrm' ) );
	}

	/**
	 * Add contact to FluentCRM
	 *
	 * @param object $order_model The order model
	 */
	public function add_contact_to_fluentcrm( $order_model ) {
		// Check if FluentCRM is active
		if ( ! defined( 'FLUENTCRM' ) || ! function_exists( 'FluentCrmApi' ) ) {
			return;
		}

		// Get customer details
		$customer = get_user_by( 'id', $order_model->customer_id );
		if ( ! $customer ) {
			return;
		}

        $customer_data = array(
            'email' => $customer->user_email,
            'first_name' => $customer->first_name,
            'last_name' => $customer->last_name ?: '',
            'status' => 'subscribed',
        );

		try {
			// Check if FluentCRM Pro is active (has webhooks)
			$is_pro_active = is_plugin_active('fluent-crm-pro/fluentcampaign-pro.php');
            $fluentcrm_webhook_exists = !empty( booktics_get_option( 'fluentcrm_webhook_url') );
			
            if ( $is_pro_active && $fluentcrm_webhook_exists ) {
				// Use webhook if Pro is active
				$webhook_url = booktics_get_option( 'fluentcrm_webhook_url');

				if ( ! empty( $webhook_url ) ) {
                    $this->send_webhook(
						$webhook_url,
						$customer_data,
					);

                    // Returns if fluentCRM pro exists and is working properly
					return;
				}
			}

			// Fallback to direct API for free version, gets used when fluentCRM pro is not active or webhook is not set.
			$contact_api = FluentCrmApi( 'contacts' );
			$contact_api->createOrUpdate( $customer_data );
		} catch ( \Throwable $e ) {
			// Ensures silent failure in case of any error
            error_log( 'FluentCRM Error: ' . $e->getMessage() );
		}
	}

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

		if ( is_wp_error( $response ) ) {
			error_log( 'FluentCRM Webhook Error: ' . $response->get_error_message() );
		}
	}
}

```
