Code Duplication    Length = 34-34 lines in 2 locations

includes/class-wc-form-handler.php 2 locations

@@ 392-425 (lines=34) @@
389
	/**
390
	 * Process the delete payment method form.
391
	 */
392
	public static function delete_payment_method_action() {
393
		global $wp;
394
395
		if ( isset( $wp->query_vars['delete-payment-method'] ) ) {
396
397
			$token_id = absint( $wp->query_vars['delete-payment-method'] );
398
			$token = WC_Payment_Tokens::get( $token_id );
399
			$delete = true;
400
401
			if ( is_null( $token ) ) {
402
				wc_add_notice( __( 'Invalid payment method', 'woocommerce' ), 'error' );
403
				$delete = false;
404
			}
405
406
			if ( get_current_user_id() !== $token->get_user_id() ) {
407
				wc_add_notice( __( 'Invalid payment method', 'woocommerce' ), 'error' );
408
				$delete = false;
409
			}
410
411
			if ( false === wp_verify_nonce( $_REQUEST['_wpnonce'], 'delete-payment-method-' . $token_id ) ) {
412
				wc_add_notice( __( 'Invalid payment method', 'woocommerce' ), 'error' );
413
				$delete = false;
414
			}
415
416
			if ( $delete ) {
417
				WC_Payment_Tokens::delete( $token_id );
418
				wc_add_notice( __( 'Payment method deleted.', 'woocommerce' ) );
419
			}
420
421
			wp_redirect( wc_get_account_endpoint_url( 'payment-methods' ) );
422
			exit();
423
		}
424
425
	}
426
427
	/**
428
	 * Process the delete payment method form.
@@ 430-463 (lines=34) @@
427
	/**
428
	 * Process the delete payment method form.
429
	 */
430
	public static function set_default_payment_method_action() {
431
		global $wp;
432
433
		if ( isset( $wp->query_vars['set-default-payment-method'] ) ) {
434
435
			$token_id = absint( $wp->query_vars['set-default-payment-method'] );
436
			$token = WC_Payment_Tokens::get( $token_id );
437
			$delete = true;
438
439
			if ( is_null( $token ) ) {
440
				wc_add_notice( __( 'Invalid payment method', 'woocommerce' ), 'error' );
441
				$delete = false;
442
			}
443
444
			if ( get_current_user_id() !== $token->get_user_id() ) {
445
				wc_add_notice( __( 'Invalid payment method', 'woocommerce' ), 'error' );
446
				$delete = false;
447
			}
448
449
			if ( false === wp_verify_nonce( $_REQUEST['_wpnonce'], 'set-default-payment-method-' . $token_id ) ) {
450
				wc_add_notice( __( 'Invalid payment method', 'woocommerce' ), 'error' );
451
				$delete = false;
452
			}
453
454
			if ( $delete ) {
455
				WC_Payment_Tokens::set_users_default( $token->get_user_id(), intval( $token_id ) );
456
				wc_add_notice( __( 'This payment method was successfully set as your default.', 'woocommerce' ) );
457
			}
458
459
			wp_redirect( wc_get_account_endpoint_url( 'payment-methods' ) );
460
			exit();
461
		}
462
463
	}
464
465
	/**
466
	 * Remove from cart/update.