Code Duplication    Length = 19-19 lines in 2 locations

includes/compat/class-wc-stripe-sepa-subs-compat.php 1 location

@@ 391-409 (lines=19) @@
388
	 * @param array $payment_meta associative array of meta data required for automatic payments
389
	 * @return array
390
	 */
391
	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
392
		if ( $this->id === $payment_method_id ) {
393
394
			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
395
				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
396
			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
397
				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
398
			}
399
400
			if (
401
				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
402
				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
403
				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
404
				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
405
406
				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
407
			}
408
		}
409
	}
410
411
	/**
412
	 * Render the payment method used for a subscription in the "My Subscriptions" table

includes/compat/class-wc-stripe-subs-compat.php 1 location

@@ 403-421 (lines=19) @@
400
	 * @param array $payment_meta associative array of meta data required for automatic payments
401
	 * @return array
402
	 */
403
	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
404
		if ( $this->id === $payment_method_id ) {
405
406
			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
407
				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
408
			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
409
				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
410
			}
411
412
			if (
413
				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
414
				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
415
				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
416
				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
417
418
				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
419
			}
420
		}
421
	}
422
423
	/**
424
	 * Render the payment method used for a subscription in the "My Subscriptions" table