Code Duplication    Length = 19-19 lines in 2 locations

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

@@ 317-335 (lines=19) @@
314
	 * @param array $payment_meta associative array of meta data required for automatic payments
315
	 * @return array
316
	 */
317
	public function validate_subscription_payment_meta( $payment_method_id, $payment_meta ) {
318
		if ( $this->id === $payment_method_id ) {
319
320
			if ( ! isset( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) || empty( $payment_meta['post_meta']['_stripe_customer_id']['value'] ) ) {
321
				throw new Exception( __( 'A "Stripe Customer ID" value is required.', 'woocommerce-gateway-stripe' ) );
322
			} elseif ( 0 !== strpos( $payment_meta['post_meta']['_stripe_customer_id']['value'], 'cus_' ) ) {
323
				throw new Exception( __( 'Invalid customer ID. A valid "Stripe Customer ID" must begin with "cus_".', 'woocommerce-gateway-stripe' ) );
324
			}
325
326
			if (
327
				( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
328
				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'card_' ) )
329
				&& ( ! empty( $payment_meta['post_meta']['_stripe_source_id']['value'] )
330
				&& 0 !== strpos( $payment_meta['post_meta']['_stripe_source_id']['value'], 'src_' ) ) ) {
331
332
				throw new Exception( __( 'Invalid source ID. A valid source "Stripe Source ID" must begin with "src_" or "card_".', 'woocommerce-gateway-stripe' ) );
333
			}
334
		}
335
	}
336
337
	/**
338
	 * Render the payment method used for a subscription in the "My Subscriptions" table

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

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