Your IP : 52.15.66.233


Current Path : /home/ephorei/www/wp-includes/images/media/q2m9hb/
Upload File :
Current File : /home/ephorei/www/wp-includes/images/media/q2m9hb/edd.tar

triggers/edd-licensekey-status-changed-to-expired.php000064400000004601150062040220016746 0ustar00<?php
/**
 * LicenseKeyStatusChangedToExpired.
 * php version 5.6
 *
 * @category LicenseKeyStatusChangedToExpired
 * @package  SureTriggers
 * @author   BSF <username@example.com>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
 * @link     https://www.brainstormforce.com/
 * @since    1.0.0
 */

namespace SureTriggers\Integrations\EDD\Triggers;

use EDD_Payment;
use SureTriggers\Controllers\AutomationController;
use SureTriggers\Integrations\EDD\EDD;
use SureTriggers\Traits\SingletonLoader;

if ( ! class_exists( 'LicenseKeyStatusChangedToExpired' ) ) :

	/**
	 * NewLicenseKey
	 *
	 * @category NewLicenseKey
	 * @package  SureTriggers
	 * @author   BSF <username@example.com>
	 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
	 * @link     https://www.brainstormforce.com/
	 * @since    1.0.0
	 *
	 * @psalm-suppress UndefinedTrait
	 */
	class LicenseKeyStatusChangedToExpired {

		/**
		 * Integration type.
		 *
		 * @var string
		 */
		public $integration = 'EDD';

		/**
		 * Trigger name.
		 *
		 * @var string
		 */
		public $trigger = 'edd_license_key_status_changed_to_expired';

		use SingletonLoader;

		/**
		 * Constructor
		 *
		 * @since  1.0.0
		 */
		public function __construct() {
			add_filter( 'sure_trigger_register_trigger', [ $this, 'register' ] );
		}

		/**
		 * Register action.
		 *
		 * @param array $triggers trigger data.
		 * @return array
		 */
		public function register( $triggers ) {

			$triggers[ $this->integration ][ $this->trigger ] = [
				'label'         => __( 'License Key Status Changed To Expired', 'suretriggers' ),
				'action'        => $this->trigger,
				'common_action' => 'edd_sl_post_set_status',
				'function'      => [ $this, 'trigger_listener' ],
				'priority'      => 10,
				'accepted_args' => 2,
			];

			return $triggers;

		}

		/**
		 * Trigger listener
		 *
		 * @param int    $license_id License ID.
		 * @param string $status Status.
		 * @since 1.0.0
		 *
		 * @return void
		 */
		public function trigger_listener( $license_id, $status ) {
			if ( 'expired' !== $status ) {
				return;
			}
			$context = EDD::edd_get_license_data( $license_id );
			
			AutomationController::sure_trigger_handle_trigger(
				[
					'trigger' => $this->trigger,
					'context' => $context,
				]
			);
		}
	}

	/**
	 * Ignore false positive
	 *
	 * @psalm-suppress UndefinedMethod
	 */
	LicenseKeyStatusChangedToExpired::get_instance();

endif;
triggers/edd-licensekey-deactivated.php000064400000004414150062040220014235 0ustar00<?php
/**
 * LicenseKeyDeActivated.
 * php version 5.6
 *
 * @category LicenseKeyDeActivated
 * @package  SureTriggers
 * @author   BSF <username@example.com>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
 * @link     https://www.brainstormforce.com/
 * @since    1.0.0
 */

namespace SureTriggers\Integrations\EDD\Triggers;

use EDD_Payment;
use SureTriggers\Controllers\AutomationController;
use SureTriggers\Integrations\EDD\EDD;
use SureTriggers\Traits\SingletonLoader;

if ( ! class_exists( 'LicenseKeyDeActivated' ) ) :

	/**
	 * NewLicenseKey
	 *
	 * @category NewLicenseKey
	 * @package  SureTriggers
	 * @author   BSF <username@example.com>
	 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
	 * @link     https://www.brainstormforce.com/
	 * @since    1.0.0
	 *
	 * @psalm-suppress UndefinedTrait
	 */
	class LicenseKeyDeActivated {

		/**
		 * Integration type.
		 *
		 * @var string
		 */
		public $integration = 'EDD';

		/**
		 * Trigger name.
		 *
		 * @var string
		 */
		public $trigger = 'edd_license_key_deactivated';

		use SingletonLoader;

		/**
		 * Constructor
		 *
		 * @since  1.0.0
		 */
		public function __construct() {
			add_filter( 'sure_trigger_register_trigger', [ $this, 'register' ] );
		}

		/**
		 * Register action.
		 *
		 * @param array $triggers trigger data.
		 * @return array
		 */
		public function register( $triggers ) {

			$triggers[ $this->integration ][ $this->trigger ] = [
				'label'         => __( 'New License Key', 'suretriggers' ),
				'action'        => $this->trigger,
				'common_action' => 'edd_sl_deactivate_license',
				'function'      => [ $this, 'trigger_listener' ],
				'priority'      => 10,
				'accepted_args' => 2,
			];

			return $triggers;

		}

		/**
		 * Trigger listener
		 *
		 * @param int $license_id License ID.
		 * @param int $download_id Download ID.
		 * @since 1.0.0
		 *
		 * @return void
		 */
		public function trigger_listener( $license_id, $download_id ) {
		
			$context = EDD::edd_get_license_data( $license_id, $download_id );
			AutomationController::sure_trigger_handle_trigger(
				[
					'trigger' => $this->trigger,
					'context' => $context,
				]
			);
		}
	}

	/**
	 * Ignore false positive
	 *
	 * @psalm-suppress UndefinedMethod
	 */
	LicenseKeyDeActivated::get_instance();

endif;
triggers/edd-licensekey-status-changed-to-active.php000064400000004565150062040220016572 0ustar00<?php
/**
 * LicenseKeyStatusChangedToActive.
 * php version 5.6
 *
 * @category LicenseKeyStatusChangedToActive
 * @package  SureTriggers
 * @author   BSF <username@example.com>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
 * @link     https://www.brainstormforce.com/
 * @since    1.0.0
 */

namespace SureTriggers\Integrations\EDD\Triggers;

use EDD_Payment;
use SureTriggers\Controllers\AutomationController;
use SureTriggers\Integrations\EDD\EDD;
use SureTriggers\Traits\SingletonLoader;

if ( ! class_exists( 'LicenseKeyStatusChangedToActive' ) ) :

	/**
	 * NewLicenseKey
	 *
	 * @category NewLicenseKey
	 * @package  SureTriggers
	 * @author   BSF <username@example.com>
	 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
	 * @link     https://www.brainstormforce.com/
	 * @since    1.0.0
	 *
	 * @psalm-suppress UndefinedTrait
	 */
	class LicenseKeyStatusChangedToActive {

		/**
		 * Integration type.
		 *
		 * @var string
		 */
		public $integration = 'EDD';

		/**
		 * Trigger name.
		 *
		 * @var string
		 */
		public $trigger = 'edd_license_key_status_changed_to_active';

		use SingletonLoader;

		/**
		 * Constructor
		 *
		 * @since  1.0.0
		 */
		public function __construct() {
			add_filter( 'sure_trigger_register_trigger', [ $this, 'register' ] );
		}

		/**
		 * Register action.
		 *
		 * @param array $triggers trigger data.
		 * @return array
		 */
		public function register( $triggers ) {

			$triggers[ $this->integration ][ $this->trigger ] = [
				'label'         => __( 'License Key Status Changed To Active', 'suretriggers' ),
				'action'        => $this->trigger,
				'common_action' => 'edd_sl_post_set_status',
				'function'      => [ $this, 'trigger_listener' ],
				'priority'      => 10,
				'accepted_args' => 2,
			];

			return $triggers;

		}

		/**
		 * Trigger listener
		 *
		 * @param int    $license_id License ID.
		 * @param string $status Status.
		 * @since 1.0.0
		 *
		 * @return void
		 */
		public function trigger_listener( $license_id, $status ) {
			if ( 'active' !== $status ) {
				return;
			}
			$context = EDD::edd_get_license_data( $license_id );
			AutomationController::sure_trigger_handle_trigger(
				[
					'trigger' => $this->trigger,
					'context' => $context,
				]
			);
		}
	}

	/**
	 * Ignore false positive
	 *
	 * @psalm-suppress UndefinedMethod
	 */
	LicenseKeyStatusChangedToActive::get_instance();

endif;
triggers/edd-purchase-refund.php000064400000004447150062040220012730 0ustar00<?php
/**
 * EDDPurchaseRefund.
 * php version 5.6
 *
 * @category EDDPurchaseRefund
 * @package  SureTriggers
 * @author   BSF <username@example.com>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
 * @link     https://www.brainstormforce.com/
 * @since    1.0.0
 */

namespace SureTriggers\Integrations\EDD\Triggers;

use SureTriggers\Controllers\AutomationController;
use SureTriggers\Integrations\EDD\EDD;
use SureTriggers\Traits\SingletonLoader;

if ( ! class_exists( 'EDDPurchaseRefund' ) ) :

	/**
	 * EDDPurchaseRefund
	 *
	 * @category EDDPurchaseRefund
	 * @package  SureTriggers
	 * @author   BSF <username@example.com>
	 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
	 * @link     https://www.brainstormforce.com/
	 * @since    1.0.0
	 *
	 * @psalm-suppress UndefinedTrait
	 */
	class EDDPurchaseRefund {

		/**
		 * Integration type.
		 *
		 * @var string
		 */
		public $integration = 'EDD';

		/**
		 * Trigger name.
		 *
		 * @var string
		 */
		public $trigger = 'edd_user_purchase_refund';

		use SingletonLoader;

		/**
		 * Constructor
		 *
		 * @since  1.0.0
		 */
		public function __construct() {
			add_filter( 'sure_trigger_register_trigger', [ $this, 'register' ] );
		}

		/**
		 * Register action.
		 *
		 * @param array $triggers trigger data.
		 * @return array
		 */
		public function register( $triggers ) {
			$triggers[ $this->integration ][ $this->trigger ] = [
				'label'         => __( 'Stripe Payment Refunded', 'suretriggers' ),
				'action'        => $this->trigger,
				'common_action' => 'edds_payment_refunded',
				'function'      => [ $this, 'trigger_listener' ],
				'priority'      => 10,
				'accepted_args' => 1,
			];

			return $triggers;
		}

		/**
		 * Trigger listener
		 *
		 * @param int $order_id The entry that was just created.
		 * @since 1.0.0
		 *
		 * @return void
		 */
		public function trigger_listener( $order_id ) {
			$order_detail = edd_get_payment( $order_id );

			if ( empty( $order_detail ) ) {
				return;
			}

			$context = EDD::get_purchase_refund_context( $order_detail );

			AutomationController::sure_trigger_handle_trigger(
				[
					'trigger' => $this->trigger,
					'context' => $context,
				]
			);
		}
	}

	/**
	 * Ignore false positive
	 *
	 * @psalm-suppress UndefinedMethod
	 */
	EDDPurchaseRefund::get_instance();

endif;
triggers/edd-purchase-one-product.php000064400000004562150062040220013702 0ustar00<?php
/**
 * EDDPurchaseOneProduct.
 * php version 5.6
 *
 * @category EDDPurchaseOneProduct
 * @package  SureTriggers
 * @author   BSF <username@example.com>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
 * @link     https://www.brainstormforce.com/
 * @since    1.0.0
 */

namespace SureTriggers\Integrations\EDD\Triggers;

use EDD_Payment;
use SureTriggers\Controllers\AutomationController;
use SureTriggers\Integrations\EDD\EDD;
use SureTriggers\Traits\SingletonLoader;

if ( ! class_exists( 'EDDPurchaseOneProduct' ) ) :

	/**
	 * EDDPurchaseProduct
	 *
	 * @category EDDPurchaseProduct
	 * @package  SureTriggers
	 * @author   BSF <username@example.com>
	 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
	 * @link     https://www.brainstormforce.com/
	 * @since    1.0.0
	 *
	 * @psalm-suppress UndefinedTrait
	 */
	class EDDPurchaseOneProduct {

		/**
		 * Integration type.
		 *
		 * @var string
		 */
		public $integration = 'EDD';

		/**
		 * Trigger name.
		 *
		 * @var string
		 */
		public $trigger = 'edd_user_purchase_specific_product';

		use SingletonLoader;

		/**
		 * Constructor
		 *
		 * @since  1.0.0
		 */
		public function __construct() {
			add_filter( 'sure_trigger_register_trigger', [ $this, 'register' ] );
		}

		/**
		 * Register action.
		 *
		 * @param array $triggers trigger data.
		 * @return array
		 */
		public function register( $triggers ) {

			$triggers[ $this->integration ][ $this->trigger ] = [
				'label'         => __( 'Product Purchased', 'suretriggers' ),
				'action'        => $this->trigger,
				'common_action' => 'edd_complete_purchase',
				'function'      => [ $this, 'trigger_listener' ],
				'priority'      => 10,
				'accepted_args' => 1,
			];

			return $triggers;

		}

		/**
		 * Trigger listener
		 *
		 * @param int $payment_id The entry that was just created.
		 * @since 1.0.0
		 *
		 * @return void
		 */
		public function trigger_listener( $payment_id ) {
			
			$payment = new EDD_Payment( $payment_id );

			if ( empty( $payment->cart_details ) ) {
				return;
			}
			$context = EDD::get_product_purchase_context( $payment, 'order_one_product' );

			AutomationController::sure_trigger_handle_trigger(
				[
					'trigger' => $this->trigger,
					'context' => $context,
				]
			);
		}
	}

	/**
	 * Ignore false positive
	 *
	 * @psalm-suppress UndefinedMethod
	 */
	EDDPurchaseOneProduct::get_instance();

endif;
triggers/edd-licensekey-activated.php000064400000004376150062040220013733 0ustar00<?php
/**
 * LicenseKeyActivated.
 * php version 5.6
 *
 * @category LicenseKeyActivated
 * @package  SureTriggers
 * @author   BSF <username@example.com>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
 * @link     https://www.brainstormforce.com/
 * @since    1.0.0
 */

namespace SureTriggers\Integrations\EDD\Triggers;

use EDD_Payment;
use SureTriggers\Controllers\AutomationController;
use SureTriggers\Integrations\EDD\EDD;
use SureTriggers\Traits\SingletonLoader;

if ( ! class_exists( 'LicenseKeyActivated' ) ) :

	/**
	 * NewLicenseKey
	 *
	 * @category NewLicenseKey
	 * @package  SureTriggers
	 * @author   BSF <username@example.com>
	 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
	 * @link     https://www.brainstormforce.com/
	 * @since    1.0.0
	 *
	 * @psalm-suppress UndefinedTrait
	 */
	class LicenseKeyActivated {

		/**
		 * Integration type.
		 *
		 * @var string
		 */
		public $integration = 'EDD';

		/**
		 * Trigger name.
		 *
		 * @var string
		 */
		public $trigger = 'edd_license_key_activated';

		use SingletonLoader;

		/**
		 * Constructor
		 *
		 * @since  1.0.0
		 */
		public function __construct() {
			add_filter( 'sure_trigger_register_trigger', [ $this, 'register' ] );
		}

		/**
		 * Register action.
		 *
		 * @param array $triggers trigger data.
		 * @return array
		 */
		public function register( $triggers ) {

			$triggers[ $this->integration ][ $this->trigger ] = [
				'label'         => __( 'New License Key', 'suretriggers' ),
				'action'        => $this->trigger,
				'common_action' => 'edd_sl_activate_license',
				'function'      => [ $this, 'trigger_listener' ],
				'priority'      => 10,
				'accepted_args' => 2,
			];

			return $triggers;

		}

		/**
		 * Trigger listener
		 *
		 * @param int $license_id License ID.
		 * @param int $download_id Download ID.
		 * @since 1.0.0
		 *
		 * @return void
		 */
		public function trigger_listener( $license_id, $download_id ) {
		
			$context = EDD::edd_get_license_data( $license_id, $download_id );
			AutomationController::sure_trigger_handle_trigger(
				[
					'trigger' => $this->trigger,
					'context' => $context,
				]
			);
		}
	}

	/**
	 * Ignore false positive
	 *
	 * @psalm-suppress UndefinedMethod
	 */
	LicenseKeyActivated::get_instance();

endif;
triggers/edd-new-licensekey-created.php000064400000004510150062040220014153 0ustar00<?php
/**
 * NewLicenseKey.
 * php version 5.6
 *
 * @category NewLicenseKey
 * @package  SureTriggers
 * @author   BSF <username@example.com>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
 * @link     https://www.brainstormforce.com/
 * @since    1.0.0
 */

namespace SureTriggers\Integrations\EDD\Triggers;

use EDD_Payment;
use SureTriggers\Controllers\AutomationController;
use SureTriggers\Integrations\EDD\EDD;
use SureTriggers\Traits\SingletonLoader;

if ( ! class_exists( 'NewLicenseKey' ) ) :

	/**
	 * NewLicenseKey
	 *
	 * @category NewLicenseKey
	 * @package  SureTriggers
	 * @author   BSF <username@example.com>
	 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
	 * @link     https://www.brainstormforce.com/
	 * @since    1.0.0
	 *
	 * @psalm-suppress UndefinedTrait
	 */
	class NewLicenseKey {

		/**
		 * Integration type.
		 *
		 * @var string
		 */
		public $integration = 'EDD';

		/**
		 * Trigger name.
		 *
		 * @var string
		 */
		public $trigger = 'edd_new_license_key';

		use SingletonLoader;

		/**
		 * Constructor
		 *
		 * @since  1.0.0
		 */
		public function __construct() {
			add_filter( 'sure_trigger_register_trigger', [ $this, 'register' ] );
		}

		/**
		 * Register action.
		 *
		 * @param array $triggers trigger data.
		 * @return array
		 */
		public function register( $triggers ) {

			$triggers[ $this->integration ][ $this->trigger ] = [
				'label'         => __( 'New License Key', 'suretriggers' ),
				'action'        => $this->trigger,
				'common_action' => 'edd_sl_store_license',
				'function'      => [ $this, 'trigger_listener' ],
				'priority'      => 10,
				'accepted_args' => 4,
			];

			return $triggers;

		}

		/**
		 * Trigger listener
		 *
		 * @param int    $license_id License ID.
		 * @param int    $download_id Download ID.
		 * @param int    $payment_id Payment ID.
		 * @param string $type Type.
		 * @since 1.0.0
		 *
		 * @return void
		 */
		public function trigger_listener( $license_id, $download_id, $payment_id, $type ) {
		
			$context = EDD::edd_get_license_data( $license_id, $download_id, $payment_id );
			AutomationController::sure_trigger_handle_trigger(
				[
					'trigger' => $this->trigger,
					'context' => $context,
				]
			);
		}
	}

	/**
	 * Ignore false positive
	 *
	 * @psalm-suppress UndefinedMethod
	 */
	NewLicenseKey::get_instance();

endif;
triggers/edd-subscription-renewal.php000064400000005126150062040220014007 0ustar00<?php
/**
 * EDDSubscriptionRenewal.
 * php version 5.6
 *
 * @category EDDSubscriptionRenewal
 * @package  SureTriggers
 * @author   BSF <username@example.com>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
 * @link     https://www.brainstormforce.com/
 * @since    1.0.0
 */

namespace SureTriggers\Integrations\EDD\Triggers;

use EDD_Payment;
use SureTriggers\Controllers\AutomationController;
use SureTriggers\Integrations\EDD\EDD;
use SureTriggers\Traits\SingletonLoader;

if ( ! class_exists( 'EDDSubscriptionRenewal' ) ) :

	/**
	 * EDDSubscriptionRenewal
	 *
	 * @category EDDSubscriptionRenewal
	 * @package  SureTriggers
	 * @author   BSF <username@example.com>
	 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
	 * @link     https://www.brainstormforce.com/
	 * @since    1.0.0
	 *
	 * @psalm-suppress UndefinedTrait
	 */
	class EDDSubscriptionRenewal {

		/**
		 * Integration type.
		 *
		 * @var string
		 */
		public $integration = 'EDD';

		/**
		 * Trigger name.
		 *
		 * @var string
		 */
		public $trigger = 'edd_subscription_renewal';

		use SingletonLoader;

		/**
		 * Constructor
		 *
		 * @since  1.0.0
		 */
		public function __construct() {
			add_filter( 'sure_trigger_register_trigger', [ $this, 'register' ] );
		}

		/**
		 * Register action.
		 *
		 * @param array $triggers trigger data.
		 * @return array
		 */
		public function register( $triggers ) {
			$triggers[ $this->integration ][ $this->trigger ] = [
				'label'         => __( 'Subscription Renewal', 'suretriggers' ),
				'action'        => $this->trigger,
				'common_action' => 'edd_subscription_post_renew',
				'function'      => [ $this, 'trigger_listener' ],
				'priority'      => 10,
				'accepted_args' => 4,
			];

			return $triggers;
		}

		/**
		 * Trigger listener
		 *
		 * @param int    $subscription_id Subscription id.
		 * @param string $expiration expiration time.
		 * @param array  $subscription subscription time.
		 * @param int    $payment_id payment id.
		 * @since 1.0.0
		 *
		 * @return void
		 */
		public function trigger_listener( $subscription_id, $expiration, $subscription, $payment_id ) {
			if ( ! class_exists( '\EDD_Payment' ) ) {
				return;
			}
			$payment = new EDD_Payment( $payment_id );

			if ( empty( $payment->cart_details ) ) {
				return;
			}
			$context = EDD::get_product_purchase_context( $payment );

			AutomationController::sure_trigger_handle_trigger(
				[
					'trigger' => $this->trigger,
					'context' => $context,
				]
			);
		}
	}

	/**
	 * Ignore false positive
	 *
	 * @psalm-suppress UndefinedMethod
	 */
	EDDSubscriptionRenewal::get_instance();

endif;
triggers/edd-licensekey-status-changed-to-inactive.php000064400000004607150062040220017116 0ustar00<?php
/**
 * LicenseKeyStatusChangedToInactive.
 * php version 5.6
 *
 * @category LicenseKeyStatusChangedToInactive
 * @package  SureTriggers
 * @author   BSF <username@example.com>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
 * @link     https://www.brainstormforce.com/
 * @since    1.0.0
 */

namespace SureTriggers\Integrations\EDD\Triggers;

use EDD_Payment;
use SureTriggers\Controllers\AutomationController;
use SureTriggers\Integrations\EDD\EDD;
use SureTriggers\Traits\SingletonLoader;

if ( ! class_exists( 'LicenseKeyStatusChangedToInactive' ) ) :

	/**
	 * NewLicenseKey
	 *
	 * @category NewLicenseKey
	 * @package  SureTriggers
	 * @author   BSF <username@example.com>
	 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
	 * @link     https://www.brainstormforce.com/
	 * @since    1.0.0
	 *
	 * @psalm-suppress UndefinedTrait
	 */
	class LicenseKeyStatusChangedToInactive {

		/**
		 * Integration type.
		 *
		 * @var string
		 */
		public $integration = 'EDD';

		/**
		 * Trigger name.
		 *
		 * @var string
		 */
		public $trigger = 'edd_license_key_status_changed_to_inactive';

		use SingletonLoader;

		/**
		 * Constructor
		 *
		 * @since  1.0.0
		 */
		public function __construct() {
			add_filter( 'sure_trigger_register_trigger', [ $this, 'register' ] );
		}

		/**
		 * Register action.
		 *
		 * @param array $triggers trigger data.
		 * @return array
		 */
		public function register( $triggers ) {

			$triggers[ $this->integration ][ $this->trigger ] = [
				'label'         => __( 'License Key Status Changed To Active', 'suretriggers' ),
				'action'        => $this->trigger,
				'common_action' => 'edd_sl_post_set_status',
				'function'      => [ $this, 'trigger_listener' ],
				'priority'      => 10,
				'accepted_args' => 2,
			];

			return $triggers;

		}

		/**
		 * Trigger listener
		 *
		 * @param int    $license_id License ID.
		 * @param string $status Status.
		 * @since 1.0.0
		 *
		 * @return void
		 */
		public function trigger_listener( $license_id, $status ) {
			if ( 'inactive' !== $status ) {
				return;
			}
			$context = EDD::edd_get_license_data( $license_id );    
			AutomationController::sure_trigger_handle_trigger(
				[
					'trigger' => $this->trigger,
					'context' => $context,
				]
			);
		}
	}

	/**
	 * Ignore false positive
	 *
	 * @psalm-suppress UndefinedMethod
	 */
	LicenseKeyStatusChangedToInactive::get_instance();

endif;
triggers/edd-licensekey-status-changed-to-disabled.php000064400000004621150062040220017057 0ustar00<?php
/**
 * LicenseKeyStatusChangedToDisabled.
 * php version 5.6
 *
 * @category LicenseKeyStatusChangedToDisabled
 * @package  SureTriggers
 * @author   BSF <username@example.com>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
 * @link     https://www.brainstormforce.com/
 * @since    1.0.0
 */

namespace SureTriggers\Integrations\EDD\Triggers;

use EDD_Payment;
use SureTriggers\Controllers\AutomationController;
use SureTriggers\Integrations\EDD\EDD;
use SureTriggers\Traits\SingletonLoader;

if ( ! class_exists( 'LicenseKeyStatusChangedToDisabled' ) ) :

	/**
	 * NewLicenseKey
	 *
	 * @category NewLicenseKey
	 * @package  SureTriggers
	 * @author   BSF <username@example.com>
	 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
	 * @link     https://www.brainstormforce.com/
	 * @since    1.0.0
	 *
	 * @psalm-suppress UndefinedTrait
	 */
	class LicenseKeyStatusChangedToDisabled {

		/**
		 * Integration type.
		 *
		 * @var string
		 */
		public $integration = 'EDD';

		/**
		 * Trigger name.
		 *
		 * @var string
		 */
		public $trigger = 'edd_license_key_status_changed_to_disabled';

		use SingletonLoader;

		/**
		 * Constructor
		 *
		 * @since  1.0.0
		 */
		public function __construct() {
			add_filter( 'sure_trigger_register_trigger', [ $this, 'register' ] );
		}

		/**
		 * Register action.
		 *
		 * @param array $triggers trigger data.
		 * @return array
		 */
		public function register( $triggers ) {

			$triggers[ $this->integration ][ $this->trigger ] = [
				'label'         => __( 'License Key Status Changed To Disabled', 'suretriggers' ),
				'action'        => $this->trigger,
				'common_action' => 'edd_sl_post_set_status',
				'function'      => [ $this, 'trigger_listener' ],
				'priority'      => 10,
				'accepted_args' => 2,
			];

			return $triggers;

		}

		/**
		 * Trigger listener
		 *
		 * @param int    $license_id License ID.
		 * @param string $status Status.
		 * @since 1.0.0
		 *
		 * @return void
		 */
		public function trigger_listener( $license_id, $status ) {
			if ( 'disabled' !== $status ) {
				return;
			}
			$context = EDD::edd_get_license_data( $license_id );        
			
			AutomationController::sure_trigger_handle_trigger(
				[
					'trigger' => $this->trigger,
					'context' => $context,
				]
			);
		}
	}

	/**
	 * Ignore false positive
	 *
	 * @psalm-suppress UndefinedMethod
	 */
	LicenseKeyStatusChangedToDisabled::get_instance();

endif;
triggers/edd-purchase-product.php000064400000004501150062040220013114 0ustar00<?php
/**
 * EDDPurchaseProduct.
 * php version 5.6
 *
 * @category EDDPurchaseProduct
 * @package  SureTriggers
 * @author   BSF <username@example.com>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
 * @link     https://www.brainstormforce.com/
 * @since    1.0.0
 */

namespace SureTriggers\Integrations\EDD\Triggers;

use EDD_Payment;
use SureTriggers\Controllers\AutomationController;
use SureTriggers\Integrations\EDD\EDD;
use SureTriggers\Traits\SingletonLoader;

if ( ! class_exists( 'EDDPurchaseProduct' ) ) :

	/**
	 * EDDPurchaseProduct
	 *
	 * @category EDDPurchaseProduct
	 * @package  SureTriggers
	 * @author   BSF <username@example.com>
	 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
	 * @link     https://www.brainstormforce.com/
	 * @since    1.0.0
	 *
	 * @psalm-suppress UndefinedTrait
	 */
	class EDDPurchaseProduct {

		/**
		 * Integration type.
		 *
		 * @var string
		 */
		public $integration = 'EDD';

		/**
		 * Trigger name.
		 *
		 * @var string
		 */
		public $trigger = 'edd_user_purchase_product';

		use SingletonLoader;

		/**
		 * Constructor
		 *
		 * @since  1.0.0
		 */
		public function __construct() {
			add_filter( 'sure_trigger_register_trigger', [ $this, 'register' ] );
		}

		/**
		 * Register action.
		 *
		 * @param array $triggers trigger data.
		 * @return array
		 */
		public function register( $triggers ) {

			$triggers[ $this->integration ][ $this->trigger ] = [
				'label'         => __( 'Order Created', 'suretriggers' ),
				'action'        => $this->trigger,
				'common_action' => 'edd_complete_purchase',
				'function'      => [ $this, 'trigger_listener' ],
				'priority'      => 10,
				'accepted_args' => 1,
			];

			return $triggers;

		}

		/**
		 * Trigger listener
		 *
		 * @param int $payment_id The entry that was just created.
		 * @since 1.0.0
		 *
		 * @return void
		 */
		public function trigger_listener( $payment_id ) {
			
			$payment = new EDD_Payment( $payment_id );

			if ( empty( $payment->cart_details ) ) {
				return;
			}
			$context = EDD::get_product_purchase_context( $payment );

			AutomationController::sure_trigger_handle_trigger(
				[
					'trigger' => $this->trigger,
					'context' => $context,
				]
			);
		}
	}

	/**
	 * Ignore false positive
	 *
	 * @psalm-suppress UndefinedMethod
	 */
	EDDPurchaseProduct::get_instance();

endif;
edd.php000064400000023335150062040220006006 0ustar00<?php
/**
 * EDD core integrations file
 *
 * @since 1.0.0
 * @package SureTrigger
 */

namespace SureTriggers\Integrations\EDD;

use Easy_Digital_Downloads;
use EDD_Payment;
use EDD_Customer;
use EDD_SL_Download;
use SureTriggers\Controllers\IntegrationsController;
use SureTriggers\Integrations\Integrations;
use SureTriggers\Traits\SingletonLoader;

/**
 * Class SureTrigger
 *
 * @package SureTriggers\Integrations\EDD
 */
class EDD extends Integrations {

	use SingletonLoader;

	/**
	 * ID
	 *
	 * @var string
	 */
	protected $id = 'EDD';

	/**
	 * SureTrigger constructor.
	 */
	public function __construct() {
		$this->name        = __( 'EDD', 'suretriggers' );
		$this->description = __( 'Easy Digital Downloads is a complete eCommerce solution for selling digital products on WordPress.', 'suretriggers' );
		$this->icon_url    = SURE_TRIGGERS_URL . 'assets/icons/edd.svg';

		parent::__construct();
	}

	/**
	 * Get context for Order Created trigger.
	 *
	 * @param  EDD_Payment|object|null $payment payment.
	 * @param  string|null             $term trigger type.
	 * @param  integer|null            $download_id download id.
	 * @return array
	 */
	public static function get_product_purchase_context( EDD_Payment $payment, $term = null, $download_id = null ) {
		global $wpdb;
	
		$purchased_products     = implode(
			', ',
			array_map(
				function ( $entry ) {
					return $entry['name'];
				},
				$payment->cart_details
			)
		);
		$purchased_products_ids = implode(
			', ',
			array_map(
				function ( $entry ) {
					return $entry['id'];
				},
				$payment->cart_details
			)
		);

		$price_id        = static::get_item_price_id( $payment->cart_details[0] );
		$licenses_table  = $wpdb->prefix . 'edd_licenses';
		$licenses_result = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $licenses_table ) );
		if ( $licenses_result == $licenses_table ) {
			$licesnses = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}edd_licenses WHERE payment_id= %s", $payment->ID ) );
		}
		$context                        = [];
		$context['order_id']            = $payment->ID;
		$context['customer_email']      = $payment->email;
		$context['customer_id']         = $payment->customer_id;
		$context['user_id']             = $payment->user_info['id'];
		$context['customer_first_name'] = $payment->first_name;
		$context['customer_last_name']  = $payment->last_name;
		$context['ordered_items']       = $purchased_products;
		$context['currency']            = $payment->currency;
		$context['status']              = $payment->status;
		$context['discount_codes']      = ( property_exists( $payment, 'discounts' ) ) ? $payment->discounts : 'NA';
		$context['order_discounts']     = number_format( $payment->order->discount, 2 );
		$context['order_subtotal']      = number_format( $payment->subtotal, 2 );
		$context['order_tax']           = number_format( $payment->tax, 2 );
		$context['order_total']         = number_format( $payment->total, 2 );
		$context['payment_method']      = $payment->gateway;
		$context['purchase_key']        = $payment->key;
		$context['ordered_items_ids']   = $purchased_products_ids;
		$context['customer_address']    = $payment->user_info['address'];
		if ( 'order_one_product' === $term ) {
			if ( $download_id > 0 ) {
				$context['download_id'] = $download_id;
			} else {
				$download_id            = $payment->cart_details[0]['id'];
				$context['download_id'] = $download_id;
			}
		}
		if ( ! empty( $price_id ) ) {
			$context['price_id'] = $price_id;
		}
		if ( ! empty( $licesnses ) ) {
			$context['license_key']             = $licesnses->license_key;
			$context['license_key_expire_date'] = $licesnses->expiration;
			$context['license_key_status']      = $licesnses->status;
		}

		// Fetch custom checkout fields.
		$post_id_option = get_option( 'cfm-checkout-form' );
		if ( is_numeric( $post_id_option ) ) {
			$post_id = (int) $post_id_option;
			$fields  = get_post_meta( $post_id, 'cfm-form', true );
			if ( is_array( $fields ) && ! empty( $fields ) && function_exists( 'edd_get_order_meta' ) ) {
				foreach ( $fields as $field ) {
					$context[ $field['name'] ] = edd_get_order_meta( $payment->ID, $field['name'], true );
				}
			}
		}
		return $context;
	}

	/**
	 * Get context for Stripe Payment Refunded trigger.
	 *
	 * @param EDD_Payment|object|null $order_detail order details.
	 * @return array
	 */
	public static function get_purchase_refund_context( EDD_Payment $order_detail ) {
		$total_discount      = 0;
		$item_names          = [];
		$download_product    = [];
		$download_product_id = [];

		$order_items = edd_get_payment_meta_cart_details( $order_detail->ID );

		foreach ( $order_items as $item ) {
			$item_names[]          = $item['name'];
			$download_product[]    = get_the_title( $item['id'] );
			$download_product_id[] = $item['id'];
			// Sum the discount.
			if ( is_numeric( $item['discount'] ) ) {
				$total_discount += $item['discount'];
			}
		}

		$context                          = [];
		$context['order_id']              = $order_detail->ID;
		$context['customer_id']           = $order_detail->customer_id;
		$context['user_id']               = $order_detail->user_id;
		$context['customer_email']        = $order_detail->email;
		$context['customer_first_name']   = $order_detail->first_name;
		$context['customer_last_name']    = $order_detail->last_name;
		$context['ordered_items']         = implode( ',', $item_names );
		$context['download_product_name'] = implode( ',', $download_product );
		$context['download_product_id']   = implode( ',', $download_product_id );
		$context['currency']              = $order_detail->currency;
		$context['status']                = $order_detail->status;
		$context['discount_codes']        = ( property_exists( $order_detail, 'discounts' ) ) ? $order_detail->discounts : 'NA';
		$context['order_discounts']       = number_format( $total_discount, 2 );
		$context['order_subtotal']        = number_format( $order_detail->subtotal, 2 );
		$context['order_tax']             = number_format( $order_detail->tax, 2 );
		$context['order_total']           = number_format( $order_detail->total, 2 );
		$context['payment_method']        = $order_detail->gateway;

		return $context;
	}

	/**
	 * Get relevant data for a given license ID.
	 *
	 * @since  1.1
	 *
	 * @param  integer $license_id License ID.
	 * @param  integer $download_id Downoad ID.
	 * @param  integer $payment_id Payment ID.
	 * @return array|void               License data.
	 */
	public static function edd_get_license_data( $license_id = 0, $download_id = 0, $payment_id = 0 ) {
		
		if ( ! function_exists( 'edd_software_licensing' ) ) {
			return;
		}
		$license = edd_software_licensing()->get_license( $license_id );
		// The license ID supplied didn't give us a valid license, no data to return.
		if ( false === $license ) {
			return [];
		}

		if ( empty( $download_id ) ) {

			$download_id = $license->download_id;

		}

		if ( empty( $payment_id ) ) {

			$payment_id = $license->payment_id;

		}
		if ( ! function_exists( 'edd_get_payment_customer_id' ) ) {
			return;
		}
		if ( ! class_exists( 'EDD_Customer' ) ) {
			return;
		}
		$customer_id = edd_get_payment_customer_id( $payment_id );
		$price_id    = $license->price_id;
		if ( empty( $customer_id ) ) {
			if ( ! function_exists( 'edd_get_payment_meta_user_info' ) || ! function_exists( 'edd_get_payment_user_email' ) ) {
				return;
			}
			$user_info       = edd_get_payment_meta_user_info( $payment_id );
			$customer        = new EDD_Customer();
			$customer->email = edd_get_payment_user_email( $payment_id );
			$customer->name  = $user_info['first_name'];

		} else {
		
			$customer = new EDD_Customer( $customer_id );

		}
		$expiration = null;
		if ( $license->is_lifetime ) {
			$expiration = 'never';
		} elseif ( $license->expiration && is_numeric( $license->expiration ) ) {
			$expiration = $license->expiration;
		}
		if ( ! class_exists( 'EDD_SL_Download' ) ) {
			return;
		}
		$download     = new EDD_SL_Download( $download_id );
		$license_data = [
			'ID'               => $license->ID,
			'key'              => $license->key,
			'customer_email'   => $customer->email,
			'customer_name'    => $customer->name,
			'customer_id'      => $customer->id,
			'user_id'          => $customer->user_id,
			'download_id'      => $download_id,
			'price_id'         => $price_id,
			'product_name'     => $download->get_name(),
			'activation_limit' => $license->activation_limit,
			'activation_count' => $license->activation_count,
			'activated_urls'   => implode( ',', $license->sites ),
			'expiration'       => $expiration,
			'is_lifetime'      => $license->is_lifetime ? '1' : '0',
			'status'           => $license->status,
		];

		return $license_data;
	}

	/**
	 * Get price id.
	 *
	 * @param  array $item cart item.
	 * @return array
	 */
	public static function get_item_price_id( $item = [] ) {
		if ( isset( $item['item_number'] ) ) {
			$price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null;
		} else {
			$price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null;
		}
	
		return $price_id;
	}

	/**
	 * Is Plugin dependent plugin is installed or not.
	 *
	 * @return bool
	 */
	public function is_plugin_installed() {
		return class_exists( Easy_Digital_Downloads::class );
	}

	/**
	 * Get context for products actions.
	 *
	 * @param  array        $payments payments.
	 * @param  string|null  $term trigger type.
	 * @param  integer|null $download_id download id.
	 * @return array
	 */
	public static function get_all_product_purchase_context( $payments, $term = null, $download_id = null ) {
		$data = [];
		foreach ( $payments as $payment ) {
			$data[] = static::get_product_purchase_context( $payment, 'edd_action', $download_id );
		}
		return $data;
	}

}

IntegrationsController::register( EDD::class );
actions/edd-create-discount.php000064400000013506150062040220012534 0ustar00<?php
/**
 * EDDCreateDiscount.
 * php version 5.6
 *
 * @category EDDCreateDiscount
 * @package  SureTriggers
 * @author   BSF <username@example.com>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
 * @link     https://www.brainstormforce.com/
 * @since    1.0.0
 */

namespace SureTriggers\Integrations\EDD\Actions;

use SureTriggers\Integrations\AutomateAction;
use SureTriggers\Traits\SingletonLoader;
use SureTriggers\Integrations\WordPress\WordPress;
use Exception;

/**
 * EDDCreateDiscount
 *
 * @category EDDCreateDiscount
 * @package  SureTriggers
 * @author   BSF <username@example.com>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
 * @link     https://www.brainstormforce.com/
 * @since    1.0.0
 */
class EDDCreateDiscount extends AutomateAction {

	/**
	 * Integration type.
	 *
	 * @var string
	 */
	public $integration = 'EDD';

	/**
	 * Action name.
	 *
	 * @var string
	 */
	public $action = 'edd_create_discount';

	use SingletonLoader;

	/**
	 * Register action.
	 *
	 * @param array $actions action data.
	 * @return array
	 */
	public function register( $actions ) {
		$actions[ $this->integration ][ $this->action ] = [
			'label'    => __( 'Create Discount', 'suretriggers' ),
			'action'   => $this->action,
			'function' => [ $this, 'action_listener' ],
		];

		return $actions;
	}

	/**
	 * Action listener.
	 *
	 * @param int   $user_id user_id.
	 * @param int   $automation_id automation_id.
	 * @param array $fields fields.
	 * @param array $selected_options selected_options.
	 * @return array|bool
	 * @throws Exception Exception.
	 */
	public function _action_listener( $user_id, $automation_id, $fields, $selected_options ) {

		// Add conditional check as this action only works with EDD Discounts Pro extension.
		if ( ! class_exists( 'edd_dp' ) ) {
			throw new Exception( 'EDD Discounts Pro plugin is not active.' );
		}

		$title = ! empty( $selected_options['discount_title'] ) ? $selected_options['discount_title'] : false;

		$type = ! empty( $selected_options['discount_type'] ) ? sanitize_key( wp_strip_all_tags( stripslashes( trim( $selected_options['discount_type'] ) ) ) ) : false;
		
		$quantity = ! empty( $selected_options['discount_quantity'] ) ? absint( trim( $selected_options['discount_quantity'] ) ) : false;
		
		$value = ! empty( $selected_options['discount_value'] ) ? wp_strip_all_tags( stripslashes( trim( $selected_options['discount_value'] ) ) ) : false;
		
		if ( ! empty( $selected_options['products'] ) ) {
			$products_ids = array_column( $selected_options['products'], 'value' );
			$products     = $products_ids;
		} else {
			$products = [];
		}
		
		if ( ! empty( $selected_options['categories'] ) ) {
			$categories_ids = array_column( $selected_options['categories'], 'value' );
			$categories     = $categories_ids;
		} else {
			$categories = [];
		}
		
		if ( ! empty( $selected_options['tags'] ) ) {
			$tags_ids = array_column( $selected_options['tags'], 'value' );
			$tags     = $tags_ids;
		} else {
			$tags = [];
		}

		$user_emails = explode( ',', $selected_options['user_email'] );
		if ( ! empty( $user_emails ) ) {
			$users = [];
			foreach ( $user_emails as $email ) {
				$user = get_user_by( 'email', $email );
				if ( $user ) {
					$users[] = $user->ID;
				}
			}
		} else {
			$users = [];
		}

		$start           = ! empty( $selected_options['start_date'] ) ? sanitize_text_field( trim( $selected_options['start_date'] ) ) : '';
		$start_hour_time = explode( ':', $selected_options['start_hour'] );
		$start_hour      = ! empty( $start_hour_time[0] ) ? absint( trim( $start_hour_time[0] ) ) : '00';
		$start_minute    = ! empty( $start_hour_time[1] ) ? absint( trim( $start_hour_time[1] ) ) : '00';
		$full_start_date = '';
		if ( ! empty( $start ) ) {
			$full_start_date = gmdate( 'Y-m-d H:i:s', (int) strtotime( sprintf( '%s %d:%d', $start, $start_hour, $start_minute ) ) );
		}

		$end           = ! empty( $selected_options['expiration_date'] ) ? sanitize_text_field( trim( $selected_options['expiration_date'] ) ) : '';
		$end_hour_time = explode( ':', $selected_options['expiration_hour'] );
		$end_hour      = ! empty( $end_hour_time[0] ) ? absint( trim( $end_hour_time[0] ) ) : '23';
		$end_minute    = ! empty( $end_hour_time[1] ) ? absint( trim( $end_hour_time[1] ) ) : '59';
		$full_end_date = '';
		if ( ! empty( $end ) ) {
			$full_end_date = gmdate( 'Y-m-d H:i:s', (int) strtotime( sprintf( '%s %d:%d', $end, $end_hour, $end_minute ) ) );
		}

		$cust = ! empty( $selected_options['cust'] ) ? true : false;

		if ( ! empty( $selected_options['groups'] ) ) {
			$group_ids = array_column( $selected_options['groups'], 'value' );
			$groups    = $group_ids;
		} else {
			$groups = [];
		}

		if ( isset( $selected_options['include_or_exclude'] ) ) {
			$include_or_exclude = sanitize_text_field( $selected_options['include_or_exclude'] );
		} else {
			$include_or_exclude = 'include';
		}

		$meta = [
			'type'               => $type,
			'quantity'           => $quantity,
			'value'              => $value,
			'products'           => $products,
			'include_or_exclude' => $include_or_exclude,
			'categories'         => $categories,
			'tags'               => $tags,
			'users'              => $users,
			'groups'             => $groups,
			'start'              => $full_start_date,
			'end'                => $full_end_date,
			'cust'               => $cust,
		];

		$result_arr = [
			'post_title'  => $title,
			'post_type'   => 'customer_discount',
			'post_status' => 'publish',
		];

		$post_id = wp_insert_post( $result_arr );

		foreach ( array_filter( $meta ) as $key => $value ) {
			update_post_meta( $post_id, $key, $value );
		}
		update_post_meta( $post_id, 'frontend', $meta );

		$donation           = WordPress::get_post_context( $post_id );
		$discount_meta_data = get_post_meta( $post_id );

		return array_merge( $donation, (array) $discount_meta_data );
	}
}

EDDCreateDiscount::get_instance();
actions/find-user-have-active-inactive-license-for-specific-download.php000064400000006112150062040220022366 0ustar00<?php
/**
 * FindIfUserHasActiveInactiveLicenseDownload.
 * php version 5.6
 *
 * @category FindIfUserHasActiveInactiveLicenseDownload
 * @package  SureTriggers
 * @author   BSF <username@example.com>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
 * @link     https://www.brainstormforce.com/
 * @since    1.0.0
 */

namespace SureTriggers\Integrations\EDD\Actions;

use SureTriggers\Integrations\AutomateAction;
use SureTriggers\Traits\SingletonLoader;
use SureTriggers\Integrations\EDD\EDD;
use Exception;

/**
 * FindIfUserHasActiveInactiveLicenseDownload
 *
 * @category FindIfUserHasActiveInactiveLicenseDownload
 * @package  SureTriggers
 * @author   BSF <username@example.com>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
 * @link     https://www.brainstormforce.com/
 * @since    1.0.0
 */
class FindIfUserHasActiveInactiveLicenseDownload extends AutomateAction {

	/**
	 * Integration type.
	 *
	 * @var string
	 */
	public $integration = 'EDD';

	/**
	 * Action name.
	 *
	 * @var string
	 */
	public $action = 'find_user_have_active_or_inactive_license_for_specific_download';

	use SingletonLoader;

	/**
	 * Register action.
	 *
	 * @param array $actions action data.
	 * @return array
	 */
	public function register( $actions ) {
		$actions[ $this->integration ][ $this->action ] = [
			'label'    => __( 'User have subscription for download', 'suretriggers' ),
			'action'   => $this->action,
			'function' => [ $this, 'action_listener' ],
		];

		return $actions;
	}

	/**
	 * Action listener.
	 *
	 * @param int   $user_id user_id.
	 * @param int   $automation_id automation_id.
	 * @param array $fields fields.
	 * @param array $selected_options selected_options.
	 * @return array|bool
	 * @throws Exception Exception.
	 */
	public function _action_listener( $user_id, $automation_id, $fields, $selected_options ) {
		global $wpdb;
		if ( empty( $user_id ) ) {
			$email = $selected_options['wp_user_email'];
			$user  = get_user_by( 'email', $email );
			if ( $user ) {
				$user_id = $user->ID;
			}
		}
	
		if ( ! empty( $selected_options['download_id'] ) ) {
			$download_id = $selected_options['download_id'];
		} else {
			$download_id = 0;
		}
		if ( ! empty( $selected_options['price_id'] ) ) {
			$price_id = $selected_options['price_id'];
		} else {
			$price_id = 0;
		}
		if ( -1 === $price_id ) {
			$result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}edd_licenses WHERE download_id=%d AND user_id=%d AND (status='active' OR status='inactive') order by id DESC", $download_id, $user_id ) );
		} else {
			$result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}edd_licenses WHERE download_id=%d AND user_id=%d AND price_id=%d AND (status='active' OR status='inactive') order by id DESC", $download_id, $user_id, $price_id ) );

		}
		if ( ! empty( $result ) ) {
			$dynamic_response['data']  = $result;
			$dynamic_response['count'] = count( $result );
			
		} else {
			$dynamic_response['count'] = '0';
			$dynamic_response['data']  = [];
		}
		return $dynamic_response;
	}
}

FindIfUserHasActiveInactiveLicenseDownload::get_instance();
actions/find-user-purchased-download.php000064400000007011150062040220014360 0ustar00<?php
/**
 * FindIfUserPurchasedDownload.
 * php version 5.6
 *
 * @category FindIfUserPurchasedDownload
 * @package  SureTriggers
 * @author   BSF <username@example.com>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
 * @link     https://www.brainstormforce.com/
 * @since    1.0.0
 */

namespace SureTriggers\Integrations\EDD\Actions;

use SureTriggers\Integrations\AutomateAction;
use SureTriggers\Traits\SingletonLoader;
use SureTriggers\Integrations\EDD\EDD;
use Exception;

/**
 * FindIfUserPurchasedDownload
 *
 * @category FindIfUserPurchasedDownload
 * @package  SureTriggers
 * @author   BSF <username@example.com>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
 * @link     https://www.brainstormforce.com/
 * @since    1.0.0
 */
class FindIfUserPurchasedDownload extends AutomateAction {

	/**
	 * Integration type.
	 *
	 * @var string
	 */
	public $integration = 'EDD';

	/**
	 * Action name.
	 *
	 * @var string
	 */
	public $action = 'find_user_purchased_download';

	use SingletonLoader;

	/**
	 * Register action.
	 *
	 * @param array $actions action data.
	 * @return array
	 */
	public function register( $actions ) {
		$actions[ $this->integration ][ $this->action ] = [
			'label'    => __( 'User has purchased a download', 'suretriggers' ),
			'action'   => $this->action,
			'function' => [ $this, 'action_listener' ],
		];

		return $actions;
	}

	/**
	 * Action listener.
	 *
	 * @param int   $user_id user_id.
	 * @param int   $automation_id automation_id.
	 * @param array $fields fields.
	 * @param array $selected_options selected_options.
	 * @return array|bool
	 * @throws Exception Exception.
	 */
	public function _action_listener( $user_id, $automation_id, $fields, $selected_options ) {
		global $wpdb;
		if ( empty( $user_id ) ) {
			$email = $selected_options['wp_user_email'];
			$user  = get_user_by( 'email', $email );
			if ( $user ) {
				$user_id = $user->ID;
			}
		}
		if ( ! empty( $selected_options['download_id'] ) ) {
			$download_id = $selected_options['download_id'];
		} else {
			$download_id = 0;
		}
		if ( ! empty( $selected_options['price_id'] ) ) {
			$price_id = $selected_options['price_id'];
		} else {
			$price_id = 0;
		}
		if ( $download_id > 0 ) {
			$args = [
				'download' => $download_id,
				'user'     => $user_id,
				'output'   => 'payments',
				
			];
		} else {
			$args = [
				'user' => $user_id,
			];
		}
		
		
		if ( ! function_exists( 'edd_get_payments' ) ) {
			return false;
		}
		$payments         = edd_get_payments( $args );
		$dynamic_response = [];
		if ( ! $payments ) {
			$dynamic_response['count']   = '0';
			$dynamic_response['message'] = 'User has not purchased any downloads.';
			$dynamic_response['data']    = [];
			
		} else {
			$data      = (array) EDD::get_all_product_purchase_context( $payments, 'edd_action', $download_id );
			$price_ids = array_column( $data, 'price_id' );
		
			if ( $price_id > 0 ) {
				if ( in_array( $price_id, $price_ids ) ) {
					$dynamic_response['data']    = $data;
					$dynamic_response['count']   = count( $data );
					$dynamic_response['message'] = 'User has purchased downloads.';
				} else {
					$dynamic_response['count']   = '0';
					$dynamic_response['message'] = 'User has not purchased any downloads.';
					$dynamic_response['data']    = [];
				}
			} else {
				$dynamic_response['data']    = $data;
				$dynamic_response['count']   = count( $data );
				$dynamic_response['message'] = 'User has purchased downloads.';
			}
		}
		
		return $dynamic_response;
	}
}

FindIfUserPurchasedDownload::get_instance();
actions/find-user-have-subscription-for-specific-download.php000064400000007061150062040220020423 0ustar00<?php
/**
 * FindIfUserHasActiveSubscriptionDownload.
 * php version 5.6
 *
 * @category FindIfUserHasActiveSubscriptionDownload
 * @package  SureTriggers
 * @author   BSF <username@example.com>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
 * @link     https://www.brainstormforce.com/
 * @since    1.0.0
 */

namespace SureTriggers\Integrations\EDD\Actions;

use EDD_Customer;
use SureTriggers\Integrations\AutomateAction;
use SureTriggers\Traits\SingletonLoader;
use SureTriggers\Integrations\EDD\EDD;
use Exception;

/**
 * FindIfUserHasActiveSubscriptionDownload
 *
 * @category FindIfUserHasActiveSubscriptionDownload
 * @package  SureTriggers
 * @author   BSF <username@example.com>
 * @license  https://www.gnu.org/licenses/gpl-3.0.html GPLv3
 * @link     https://www.brainstormforce.com/
 * @since    1.0.0
 */
class FindIfUserHasActiveSubscriptionDownload extends AutomateAction {

	/**
	 * Integration type.
	 *
	 * @var string
	 */
	public $integration = 'EDD';

	/**
	 * Action name.
	 *
	 * @var string
	 */
	public $action = 'find_user_have_subscription_for_specific_download';

	use SingletonLoader;

	/**
	 * Register action.
	 *
	 * @param array $actions action data.
	 * @return array
	 */
	public function register( $actions ) {
		$actions[ $this->integration ][ $this->action ] = [
			'label'    => __( 'User have subscription for download', 'suretriggers' ),
			'action'   => $this->action,
			'function' => [ $this, 'action_listener' ],
		];

		return $actions;
	}

	/**
	 * Action listener.
	 *
	 * @param int   $user_id user_id.
	 * @param int   $automation_id automation_id.
	 * @param array $fields fields.
	 * @param array $selected_options selected_options.
	 * @return array|bool
	 * @throws Exception Exception.
	 */
	public function _action_listener( $user_id, $automation_id, $fields, $selected_options ) {
		global $wpdb;
		if ( empty( $user_id ) ) {
			$email = $selected_options['wp_user_email'];
			$user  = get_user_by( 'email', $email );
			if ( $user ) {
				$user_id = $user->ID;
			}
		}
	
		if ( ! empty( $selected_options['download_id'] ) ) {
			$download_id = $selected_options['download_id'];
		} else {
			$download_id = 0;
		}
		if ( ! empty( $selected_options['price_id'] ) ) {
			$price_id = $selected_options['price_id'];
		} else {
			$price_id = 0;
		}
		
		if ( -1 === $price_id ) {
			$result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}edd_subscriptions WHERE product_id=%d AND status='active' order by id DESC", $download_id ) );
		} else {
			$result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}edd_subscriptions WHERE product_id=%d AND price_id=%d AND status='active' order by id DESC", $download_id, $price_id ) );

		}
		if ( ! class_exists( 'EDD_Customer' ) ) {
			return false;
		}
		$dynamic_response = [];
		if ( ! $result ) {
			$dynamic_response['count'] = '0';
			$dynamic_response['data']  = [];
			
		} else {
			$customer_ids = array_column( $result, 'customer_id' );
			$user_ids     = [];
			foreach ( $customer_ids as $customer_id ) {
				$customer   = new EDD_Customer( $customer_id );
				$user_ids[] = $customer->user_id;
			}
			if ( $user_id > 0 ) {
				if ( in_array( $user_id, $user_ids ) ) {
					$dynamic_response['data']  = $result;
					$dynamic_response['count'] = count( $result );
				} else {
					$dynamic_response['count'] = '0';
					$dynamic_response['data']  = [];
				}
			} else {
				$dynamic_response['data']  = $result;
				$dynamic_response['count'] = count( $result );
			}
		}
		return $dynamic_response;
	}
}

FindIfUserHasActiveSubscriptionDownload::get_instance();