Code Duplication    Length = 11-15 lines in 4 locations

includes/class-wc-stripe-helper.php 4 locations

@@ 378-388 (lines=11) @@
375
	 * @version 4.0.0
376
	 * @param string $source_id
377
	 */
378
	public static function get_order_by_source_id( $source_id ) {
379
		global $wpdb;
380
381
		$order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $source_id, '_stripe_source_id' ) );
382
383
		if ( ! empty( $order_id ) ) {
384
			return wc_get_order( $order_id );
385
		}
386
387
		return false;
388
	}
389
390
	/**
391
	 * Gets the order by Stripe charge ID.
@@ 397-411 (lines=15) @@
394
	 * @since 4.1.16 Return false if charge_id is empty.
395
	 * @param string $charge_id
396
	 */
397
	public static function get_order_by_charge_id( $charge_id ) {
398
		global $wpdb;
399
400
		if ( empty( $charge_id ) ) {
401
			return false;
402
		}
403
404
		$order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $charge_id, '_transaction_id' ) );
405
406
		if ( ! empty( $order_id ) ) {
407
			return wc_get_order( $order_id );
408
		}
409
410
		return false;
411
	}
412
413
	/**
414
	 * Gets the order by Stripe PaymentIntent ID.
@@ 420-430 (lines=11) @@
417
	 * @param string $intent_id The ID of the intent.
418
	 * @return WC_Order|bool Either an order or false when not found.
419
	 */
420
	public static function get_order_by_intent_id( $intent_id ) {
421
		global $wpdb;
422
423
		$order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $intent_id, '_stripe_intent_id' ) );
424
425
		if ( ! empty( $order_id ) ) {
426
			return wc_get_order( $order_id );
427
		}
428
429
		return false;
430
	}
431
432
	/**
433
	 * Gets the order by Stripe SetupIntent ID.
@@ 439-449 (lines=11) @@
436
	 * @param string $intent_id The ID of the intent.
437
	 * @return WC_Order|bool Either an order or false when not found.
438
	 */
439
	public static function get_order_by_setup_intent_id( $intent_id ) {
440
		global $wpdb;
441
442
		$order_id = $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT ID FROM $wpdb->posts as posts LEFT JOIN $wpdb->postmeta as meta ON posts.ID = meta.post_id WHERE meta.meta_value = %s AND meta.meta_key = %s", $intent_id, '_stripe_setup_intent' ) );
443
444
		if ( ! empty( $order_id ) ) {
445
			return wc_get_order( $order_id );
446
		}
447
448
		return false;
449
	}
450
451
	/**
452
	 * Sanitize statement descriptor text.