HEX
Server: Apache
System: Linux ecngx285.inmotionhosting.com 4.18.0-553.79.1.lve.el8.x86_64 #1 SMP Wed Oct 15 17:59:35 UTC 2025 x86_64
User: zeusxp5 (3862)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: /home/zeusxp5/tour.kamille.us/wp-content/plugins/surecart/app/src/Models/IncomingWebhook.php
<?php
namespace SureCart\Models;

use SureCart\Models\DatabaseModel;
use SureCart\Support\TimeDate;

/**
 * The integration model.
 */
class IncomingWebhook extends DatabaseModel {
	/**
	 * The integrations table name.
	 *
	 * @var string
	 */
	protected $table_name = 'surecart_incoming_webhooks';

	/**
	 * The object name
	 *
	 * @var string
	 */
	protected $object_name = 'incoming_webhook';

	/**
	 * Fillable items.
	 *
	 * @var array
	 */
	protected $fillable = array( 'id', 'webhook_id', 'processed_at', 'data', 'source', 'created_at', 'updated_at', 'deleted_at' );

	/**
	 * Force `data` to be an object.
	 *
	 * @param array|object $value The value to set.
	 *
	 * @return void
	 */
	public function setDataAttribute( $value ) {
		$this->attributes['data'] = json_decode( wp_json_encode( $value ) );
	}

	/**
	 * Has this been processed?
	 *
	 * @return boolean
	 */
	protected function getProcessedAttribute() {
		return ! empty( $this->attributes['processed_at'] );
	}

	/**
	 * Serialize the data when setting it.
	 *
	 * @param mixed $value The value to set.
	 */
	protected function setProcessedAttribute( $value ) {
		$this->attributes['processed_at'] = ! empty( $value ) ? current_time( 'mysql' ) : null;
		$this->attributes['processed']    = ! empty( $value );
	}

	/**
	 * Delete expired incoming webhooks.
	 *
	 * @param integer $time_ago The number of days ago to delete.
	 *
	 * @return integer The number of rows deleted.
	 */
	protected function deleteExpired( $time_ago = '30 days' ) {
		global $wpdb;
		$date           = new \DateTime();
		$table_name     = $wpdb->prefix . 'surecart_incoming_webhooks';
		$formatted_date = $date->modify( '-' . $time_ago )->format( 'Y-m-d H:i:s' );
		return $wpdb->query( $wpdb->prepare( "DELETE FROM $table_name WHERE created_at < %s", $formatted_date ) );
	}

	/**
	 * Get the created at date.
	 *
	 * @return string
	 */
	public function getCreatedAtDateAttribute() {
		return TimeDate::formatDate( strtotime( $this->created_at ?? '' ) );
	}

	/**
	 * Get the created at date time.
	 *
	 * @return string
	 */
	public function getCreatedAtDateTimeAttribute() {
		return TimeDate::formatDateAndTime( strtotime( $this->created_at ?? '' ) );
	}

	/**
	 * Get the updated at date.
	 *
	 * @return string
	 */
	public function getUpdatedAtDateAttribute() {
		return TimeDate::formatDate( strtotime( $this->updated_at ?? '' ) );
	}

	/**
	 * Get the updated at date time.
	 *
	 * @return string
	 */
	public function getUpdatedAtDateTimeAttribute() {
		return TimeDate::formatDateAndTime( strtotime( $this->updated_at ?? '' ) );
	}
}