HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux vmi1674223.contaboserver.net 5.4.0-182-generic #202-Ubuntu SMP Fri Apr 26 12:29:36 UTC 2024 x86_64
User: root (0)
PHP: 7.4.3-4ubuntu2.22
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/onlineshop/wp-content/plugins/pinterest-for-woocommerce/src/AdCreditsCoupons.php
<?php
/**
 * Pinterest for WooCommerce Ads Credits Coupons
 *
 * @package     Pinterest_For_WooCommerce/Classes/
 * @version     1.2.5
 */

namespace Automattic\WooCommerce\Pinterest;

use DateTime;
use DateTimeZone;

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

/**
 * Class Handling ad credits.
 */
class AdCreditsCoupons {

	/**
	 * List of Ads Credits allowed currencies.
	 *
	 * @since 1.3.17
	 *
	 * @var array
	 */
	public static $allowed_currencies = array(
		'USD',
		'GBP',
		'EUR',
		'BRL',
		'AUD',
		'CAD',
		'MXN',
		'PLN',
		'CHF',
		'DKK',
		'RON',
		'SEK',
		'NZD',
		'HUF',
		'NOK',
		'JPY',
		'CZK',
		'ARS',
	);

	/**
	 * 2023 copon code.
	 *
	 * @var string
	 */
	public static $coupon_for_2023 = 'Q09JTl9DTElFTlRfSURfMTQ2ODQxNF9DUkVESVRT';

	/**
	 * 2024 copon code.
	 *
	 * @var string
	 */
	public static $coupon_for_2024 = 'V09PQ09NTUVSQ0VfMTQ2ODQxNF9DUkVESVRfMjAyNA==';

	/**
	 * Get a valid coupon for the merchant.
	 *
	 * @since 1.2.5
	 * @since 1.3.17 update logic for new data format.
	 *
	 * @return string|false Coupon string or false if no coupon was found.
	 */
	public static function get_coupon_for_merchant() {
		$switch_date       = new DateTime( '2023-12-31 23:59:59', new DateTimeZone( 'GMT' ) );
		$switch_timestamp  = $switch_date->getTimestamp();
		$current_timestamp = time();
		$currency          = get_woocommerce_currency();

		if ( ! in_array( $currency, self::$allowed_currencies, true ) ) {
			return false;
		}

		return ( $current_timestamp >= $switch_timestamp ) ? self::$coupon_for_2024 : self::$coupon_for_2023;
	}

	/**
	 * Check if there is a valid coupon for the user currency.
	 *
	 * @return bool Wether there is a valid coupon for the merchant.
	 */
	public static function has_valid_coupon_for_merchant() {
		return self::get_coupon_for_merchant() !== false;
	}

}