Code Duplication    Length = 19-19 lines in 2 locations

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

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

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

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