WC_Form_Handler::add_payment_method_action()
Process the add payment method form.
Description Description
Source Source
File: includes/class-wc-form-handler.php
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 | public static function add_payment_method_action() { if ( isset( $_POST [ 'woocommerce_add_payment_method' ], $_POST [ 'payment_method' ] ) ) { wc_nocache_headers(); $nonce_value = wc_get_var( $_REQUEST [ 'woocommerce-add-payment-method-nonce' ], wc_get_var( $_REQUEST [ '_wpnonce' ], '' ) ); // @codingStandardsIgnoreLine. if ( ! wp_verify_nonce( $nonce_value , 'woocommerce-add-payment-method' ) ) { return ; } if ( ! apply_filters( 'woocommerce_add_payment_method_form_is_valid' , true ) ) { return ; } // Test rate limit. $current_user_id = get_current_user_id(); $rate_limit_id = 'add_payment_method_' . $current_user_id ; $delay = (int) apply_filters( 'woocommerce_payment_gateway_add_payment_method_delay' , 20 ); if ( WC_Rate_Limiter::retried_too_soon( $rate_limit_id ) ) { wc_add_notice( sprintf( /* translators: %d number of seconds */ _n( 'You cannot add a new payment method so soon after the previous one. Please wait for %d second.' , 'You cannot add a new payment method so soon after the previous one. Please wait for %d seconds.' , $delay , 'woocommerce' ), $delay ), 'error' ); return ; } WC_Rate_Limiter::set_rate_limit( $rate_limit_id , $delay ); ob_start(); $payment_method_id = wc_clean( wp_unslash( $_POST [ 'payment_method' ] ) ); $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); if ( isset( $available_gateways [ $payment_method_id ] ) ) { $gateway = $available_gateways [ $payment_method_id ]; if ( ! $gateway ->supports( 'add_payment_method' ) && ! $gateway ->supports( 'tokenization' ) ) { wc_add_notice( __( 'Invalid payment gateway.' , 'woocommerce' ), 'error' ); return ; } $gateway ->validate_fields(); if ( wc_notice_count( 'error' ) > 0 ) { return ; } $result = $gateway ->add_payment_method(); if ( 'success' === $result [ 'result' ] ) { wc_add_notice( __( 'Payment method successfully added.' , 'woocommerce' ) ); } if ( 'failure' === $result [ 'result' ] ) { wc_add_notice( __( 'Unable to add payment method to your account.' , 'woocommerce' ), 'error' ); } if ( ! empty ( $result [ 'redirect' ] ) ) { wp_redirect( $result [ 'redirect' ] ); //phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect exit (); } } } } |