LearnDash_Stripe_Connect_Checkout_Integration.php 9.19 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
<?php
/**
 * Deprecated. Use LearnDash_Stripe_Gateway instead.
 * This class handled Stripe Connect integration.
 *
 * @since 4.0.0
 * @deprecated 4.5.0
 *
 * @package LearnDash\Deprecated
 */

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

_deprecated_file(
	__FILE__,
	'4.5.0',
	esc_html( LEARNDASH_LMS_PLUGIN_DIR . '/includes/payments/gateways/class-learndash-stripe-gateway.php' )
);

if ( ! class_exists( 'LearnDash_Stripe_Connect_Checkout_Integration' ) && class_exists( 'LearnDash_Payment_Gateway_Integration' ) ) {
	/**
	 * Stripe Connect checkout integration class.
	 *
	 * @since 4.0.0
	 * @deprecated 4.5.0
	 */
	class LearnDash_Stripe_Connect_Checkout_Integration extends LearnDash_Payment_Gateway_Integration {
		/**
		 * Deprecated.
		 *
		 * @deprecated 4.5.0
		 */
		const PAYMENT_PROCESSOR = 'stripe';

		/**
		 * Plugin options.
		 *
		 * @deprecated 4.5.0
		 *
		 * @var array
		 */
		protected $options = array();

		/**
		 * Stripe secret key.
		 *
		 * @deprecated 4.5.0
		 *
		 * @var string
		 */
		protected $secret_key = '';

		/**
		 * Stripe publishable key.
		 *
		 * @deprecated 4.5.0
		 *
		 * @var string
		 */
		protected $publishable_key = '';

		/**
		 * Stripe connected account id.
		 *
		 * @deprecated 4.5.0
		 *
		 * @var string
		 */
		protected $account_id = '';

		/**
		 * Stripe API client.
		 *
		 * @deprecated 4.5.0
		 *
		 * @var null
		 */
		protected $stripe = null;

		/**
		 * Variable to hold the Course object we are working with.
		 *
		 * @deprecated 4.5.0
		 *
		 * @var null
		 */
		protected $course = null;

		/**
		 * Stripe checkout session id.
		 *
		 * @deprecated 4.5.0
		 *
		 * @var string
		 */
		protected $session_id = '';

		/**
		 * Stripe customer id meta key name.
		 *
		 * @deprecated 4.5.0
		 *
		 * @var string
		 */
		protected $stripe_customer_id_meta_key = '';

		/**
		 * Construction.
		 *
		 * @deprecated 4.5.0
		 */
		public function __construct() {
			_deprecated_constructor( __CLASS__, '4.5.0' );
		}

		/**
		 * Sets Stripe customer id meta key.
		 *
		 * @deprecated 4.5.0
		 */
		protected function set_stripe_customer_id_meta_key(): void {
			_deprecated_function( __METHOD__, '4.5.0' );
		}

		/**
		 * Configs Stripe API key.
		 *
		 * @deprecated 4.5.0
		 */
		protected function configure() {
			_deprecated_function( __METHOD__, '4.5.0' );
		}

		/**
		 * Checks if it's a test mode.
		 *
		 * @deprecated 4.5.0
		 *
		 * @return bool
		 */
		public function is_test_mode(): bool {
			_deprecated_function( __METHOD__, '4.5.0' );

			return true;
		}

		/**
		 * Get course button args
		 *
		 * @deprecated 4.5.0
		 *
		 * @param int|null $course_id Course ID.
		 *
		 * @return array Course args
		 */
		public function get_course_args( ?int $course_id = null ): array {
			_deprecated_function( __METHOD__, '4.5.0' );

			return array();
		}

		/**
		 * Enqueues scripts.
		 *
		 * @deprecated 4.5.0
		 *
		 * @return void
		 */
		public function enqueue_scripts(): void {
			_deprecated_function( __METHOD__, '4.5.0' );

			$gateway = Learndash_Payment_Gateway::get_active_payment_gateway_by_name( Learndash_Stripe_Gateway::get_name() );
			$gateway->enqueue_scripts();
		}

		/**
		 * Output modified payment button
		 *
		 * @deprecated 4.5.0
		 *
		 * @param string     $default_button Learndash default payment button.
		 * @param array|null $params Button parameters.
		 *
		 * @return string Modified button.
		 */
		public function payment_button( string $default_button, ?array $params = null ): string {
			_deprecated_function( __METHOD__, '4.5.0' );

			return $default_button;
		}

		/**
		 * Stripe payment button
		 *
		 * @deprecated 4.5.0
		 *
		 * @param string $default_button Default button.
		 *
		 * @return string Payment button.
		 */
		public function stripe_button( $default_button ) {
			_deprecated_function( __METHOD__, '4.5.0' );

			return '';
		}

		/**
		 * Integration button scripts
		 *
		 * @deprecated 4.5.0
		 *
		 * @return void
		 */
		public function button_scripts() {
			_deprecated_function( __METHOD__, '4.5.0' );
		}

		/**
		 * Process Stripe new checkout
		 *
		 * @deprecated 4.5.0
		 *
		 * @return void
		 */
		public function process_webhook(): void {
			_deprecated_function( __METHOD__, '4.5.0' );

			$gateway = Learndash_Payment_Gateway::get_active_payment_gateway_by_name( Learndash_Stripe_Gateway::get_name() );
			$gateway->process_webhook();
		}

		/**
		 * Get LearnDash course ID by Stripe plan ID.
		 *
		 * @deprecated 4.5.0
		 *
		 * @param string $plan_id Stripe plan ID.
		 *
		 * @return string|null LearnDash course ID or null.
		 */
		public function get_course_id_by_plan_id( string $plan_id ): ?string {
			_deprecated_function( __METHOD__, '4.5.0' );

			global $wpdb;

			return $wpdb->get_var( // phpcs:ignore
				$wpdb->prepare( "SELECT post_id FROM {$wpdb->prefix}postmeta WHERE meta_key = 'stripe_plan_id' AND meta_value = %s", $plan_id )
			);
		}

		/**
		 * Outputs transaction message.
		 *
		 * @deprecated 4.5.0
		 *
		 * @return void
		 */
		public function output_transaction_message(): void {
			_deprecated_function( __METHOD__, '4.5.0' );
		}

		/**
		 * Get user ID of the customer
		 *
		 * @deprecated 4.5.0
		 *
		 * @param null|string $email User email address.
		 * @param string      $customer_id Stripe customer ID.
		 * @param null|int    $user_id WP user ID.
		 *
		 * @return int WP_User ID
		 */
		public function get_user_id( ?string $email, string $customer_id, ?int $user_id = null ): int {
			_deprecated_function( __METHOD__, '4.5.0' );

			$user = ! empty( $user_id ) && is_numeric( $user_id )
				? get_user_by( 'ID', $user_id )
				: ( ! empty( $email ) ? get_user_by( 'email', $email ) : null );

			if ( $user ) {
				return $user->ID;
			}

			return $this->create_user( $email, wp_generate_password( 18 ), $email );
		}

		/**
		 * Creates a user if does not exist.
		 *
		 * @deprecated 4.5.0
		 *
		 * @param string $email Email.
		 * @param string $password Password.
		 * @param string $username Username.
		 *
		 * @return int Newly created user ID
		 */
		public function create_user( string $email, string $password, string $username ): int {
			_deprecated_function( __METHOD__, '4.5.0' );

			if ( username_exists( $username ) ) {
				$random_chars = str_shuffle( substr( md5( (string) time() ), 0, 5 ) );
				$username     = $username . '-' . $random_chars;
			}

			return wp_create_user( $username, $password, $email );
		}

		/**
		 * Records a payment transaction.
		 *
		 * @deprecated 4.5.0
		 *
		 * @param object $session    Transaction data passed through $_POST.
		 * @param int    $post_id    Post ID.
		 * @param int    $user_id    User ID.
		 * @param string $user_email Email of the user.
		 */
		public function record_transaction( $session, int $post_id, int $user_id, string $user_email ) {
			_deprecated_function( __METHOD__, '4.5.0' );
		}

		/**
		 * Maps the secret key.
		 *
		 * @deprecated 4.5.0
		 *
		 * @return string
		 */
		protected function map_secret_key(): string {
			_deprecated_function( __METHOD__, '4.5.0' );

			return '';
		}

		/**
		 * Maps the publishable key.
		 *
		 * @deprecated 4.5.0
		 *
		 * @return string
		 */
		protected function map_publishable_key(): string {
			_deprecated_function( __METHOD__, '4.5.0' );

			return '';
		}

		/**
		 * Returns enabled payment methods.
		 *
		 * @deprecated 4.5.0
		 *
		 * @return array
		 */
		protected function get_payment_methods(): array {
			_deprecated_function( __METHOD__, '4.5.0' );

			return array();
		}

		/**
		 * Check if Stripe currency ISO code is zero decimal currency
		 *
		 * @deprecated 4.5.0
		 *
		 * @param string $currency Stripe currency ISO code.
		 *
		 * @return bool
		 */
		protected function is_zero_decimal_currency( string $currency = '' ): bool {
			_deprecated_function( __METHOD__, '4.5.0' );

			$zero_decimal_currencies = array(
				'BIF',
				'CLP',
				'DJF',
				'GNF',
				'JPY',
				'KMF',
				'KRW',
				'MGA',
				'PYG',
				'RWF',
				'VND',
				'VUV',
				'XAF',
				'XOF',
				'XPF',
			);

			return in_array( strtoupper( $currency ), $zero_decimal_currencies, true );
		}

		/**
		 * Generates random string.
		 *
		 * @deprecated 4.5.0
		 *
		 * @param integer $length Length.
		 *
		 * @return string
		 */
		protected function generate_random_string( $length = 5 ): string {
			_deprecated_function( __METHOD__, '4.5.0' );

			return substr( md5( microtime() ), 0, $length );
		}

		/**
		 * Checks if learndash Stripe Connect webhook is running.
		 *
		 * @deprecated 4.5.0
		 *
		 * @return bool
		 */
		protected function check_webhook_process(): bool {
			_deprecated_function( __METHOD__, '4.5.0' );

			return false;
		}

		/**
		 * Sets Stripe checkout session on a course page.
		 *
		 * @deprecated 4.5.0
		 *
		 * @param int|null $course_id Course ID.
		 *
		 * @return array
		 */
		protected function set_session( ?int $course_id = null ) {
			_deprecated_function( __METHOD__, '4.5.0' );

			return array(
				'error' => __( 'Deprecated', 'learndash' ),
			);
		}

		/**
		 * AJAX function handler for init checkout.
		 *
		 * @deprecated 4.5.0
		 *
		 * @return void
		 */
		public function ajax_init_checkout(): void {
			_deprecated_function( __METHOD__, '4.5.0' );

			$gateway = Learndash_Payment_Gateway::get_active_payment_gateway_by_name( Learndash_Stripe_Gateway::get_name() );
			$gateway->setup_payment();
		}
	}
}