'; } add_action( 'edd_after_cc_fields', 'edds_add_stripe_errors', 999 ); /** * Stripe uses it's own credit card form because the card details are tokenized. * * We don't want the name attributes to be present on the fields in order to prevent them from getting posted to the server * * @since 1.7.5 * @return void */ function edds_credit_card_form( $echo = true ) { if ( edd_stripe()->rate_limiting->has_hit_card_error_limit() ) { edd_set_error( 'edd_stripe_error_limit', __( 'We are unable to process your payment at this time, please try again later or contact support.', 'easy-digital-downloads' ) ); return; } ob_start(); ?>
'lock', 'width' => 18, 'height' => 28, 'classes' => array( 'edd-icon', 'edd-icon-lock', ), ) ); ?>
>
rate_limiting->has_hit_card_error_limit() ) { edd_set_error( 'edd_stripe_error_limit', __( 'Adding new payment methods is currently unavailable.', 'easy-digital-downloads' ) ); edd_print_errors(); return; } $elements_mode = edds_get_elements_mode(); if ( 'payment-elements' === $elements_mode ) { edds_output_payment_elements_form(); } else { edds_output_legacy_new_card_form(); } } add_action( 'edd_stripe_new_card_form', 'edd_stripe_new_card_form' ); /** * Add the element for the Stripe Payment Elements to attach to. * * @since 2.9.0 */ function edds_output_payment_elements_form() { // Payment Elements needs to not allow checking out with mixed carts or multiple subscriptions. if ( function_exists( 'edd_recurring' ) ) { if ( ( count( edd_get_cart_contents() ) > 1 && edd_recurring()->cart_contains_recurring() ) || edd_recurring()->cart_is_mixed() ) { add_filter( 'edd_checkout_button_purchase', '__return_empty_string', 999 ); ?>

has_regional_support && edd_stripe()->regional_support->requires_card_name ) : ?>

isset( $default_card->address_line1 ) ? $default_card->address_line1 : null, 'line2' => isset( $default_card->address_line2 ) ? $default_card->address_line2 : null, 'city' => isset( $default_card->address_city ) ? $default_card->address_city : null, 'state' => isset( $default_card->address_state ) ? $default_card->address_state : null, 'zip' => isset( $default_card->address_zip ) ? $default_card->address_zip : null, 'country' => isset( $default_card->address_country ) ? $default_card->address_country : null, ); $address_fields = array_filter( $address_fields ); echo esc_html( implode( ', ', $address_fields ) ); endif; ?>

rate_limiting->has_hit_card_error_limit() ) { edd_set_error( 'edd_stripe_error_limit', __( 'We are unable to process your payment at this time, please try again later or contacts support.', 'easy-digital-downloads' ) ); return; } // Can't use just edd_is_checkout() because this could happen in an AJAX request. $is_checkout = edd_is_checkout() || ( isset( $_REQUEST['action'] ) && 'edd_load_gateway' === $_REQUEST['action'] ); edd_stripe_css( true ); $existing_cards = edd_stripe_get_existing_cards( $user_id ); if ( ! empty( $existing_cards ) ) : ?>
rate_limiting->has_hit_card_error_limit() ) { edd_set_error( 'edd_stripe_error_limit', __( 'Payment method management is currently unavailable.', 'easy-digital-downloads' ) ); edd_print_errors(); return; } $existing_cards = edd_stripe_get_existing_cards( get_current_user_id() ); edd_stripe_css( true ); edd_stripe_js( true ); $display = edd_get_option( 'stripe_billing_fields', 'full' ); ?>
' . esc_html( $source->brand ) . '', '' . esc_html( $source->last4 ) . '' ), array( 'span' => array( 'class' => true, ), ) ); ?> : exp_month; ?>/exp_year; ?> isset( $source->address_line1 ) ? $source->address_line1 : '', 'zip' => isset( $source->address_zip ) ? $source->address_zip : '', 'country' => isset( $source->address_country ) ? $source->address_country : '', ); echo esc_html( implode( ' ', $address_fields ) ); ?> | |

html->text( array( 'id' => sprintf( 'edds_address_line1_%1$s', $source->id ), 'value' => sanitize_text_field( isset( $source->address_line1 ) ? $source->address_line1 : '' ), 'label' => esc_html__( 'Address Line 1', 'easy-digital-downloads' ), 'name' => 'address_line1', 'class' => 'card-update-field address_line1 text edd-input', 'data' => array( 'key' => 'address_line1', ) ) ); ?>

html->text( array( 'id' => sprintf( 'edds_address_line2_%1$s', $source->id ), 'value' => sanitize_text_field( isset( $source->address_line2 ) ? $source->address_line2 : '' ), 'label' => esc_html__( 'Address Line 2', 'easy-digital-downloads' ), 'name' => 'address_line2', 'class' => 'card-update-field address_line2 text edd-input', 'data' => array( 'key' => 'address_line2', ) ) ); ?>

html->text( array( 'id' => sprintf( 'edds_address_city_%1$s', $source->id ), 'value' => sanitize_text_field( isset( $source->address_city ) ? $source->address_city : '' ), 'label' => esc_html__( 'City', 'easy-digital-downloads' ), 'name' => 'address_city', 'class' => 'card-update-field address_city text edd-input', 'data' => array( 'key' => 'address_city', ) ) ); ?>

html->text( array( 'id' => sprintf( 'edds_address_zip_%1$s', $source->id ), 'value' => sanitize_text_field( isset( $source->address_zip ) ? $source->address_zip : '' ), 'label' => esc_html__( 'ZIP Code', 'easy-digital-downloads' ), 'name' => 'address_zip', 'class' => 'card-update-field address_zip text edd-input', 'data' => array( 'key' => 'address_zip', ) ) ); ?>

address_country ) ? $source->address_country : edd_get_shop_country(); echo EDD()->html->select( array( 'id' => sprintf( 'edds_address_country_%1$s', $source->id ), 'name' => 'address_country', 'label' => esc_html__( 'Country', 'easy-digital-downloads' ), 'options' => $countries, 'selected' => $country, 'class' => 'card-update-field address_country', 'data' => array( 'key' => 'address_country' ), 'show_option_all' => false, 'show_option_none' => false, ) ); ?>

address_state ) ? $source->address_state : edd_get_shop_state(); $states = edd_get_shop_states( $country ); echo EDD()->html->select( array( 'id' => sprintf( 'edds_address_state_%1$s', $source->id ), 'name' => 'address_state', 'options' => $states, 'selected' => $selected_state, 'class' => 'card-update-field address_state card_state', 'data' => array( 'key' => 'address_state' ), 'show_option_all' => false, 'show_option_none' => false, ) ); ?>

html->select( array( 'id' => sprintf( 'edds_card_exp_month_%1$s', $source->id ), 'name' => 'exp_month', 'options' => $months, 'selected' => $source->exp_month, 'class' => 'card-expiry-month edd-select edd-select-small card-update-field exp_month', 'data' => array( 'key' => 'exp_month' ), 'show_option_all' => false, 'show_option_none' => false, ) ); ?> / html->select( array( 'id' => sprintf( 'edds_card_exp_year_%1$s', $source->id ), 'name' => 'exp_year', 'options' => $years, 'selected' => $source->exp_year, 'class' => 'card-expiry-year edd-select edd-select-small card-update-field exp_year', 'data' => array( 'key' => 'exp_year' ), 'show_option_all' => false, 'show_option_none' => false, ) ); ?>

id . '_update', 'card_update_nonce_' . $source->id, true ); echo edds_get_tokenizer_input( $source->id ); ?>

#edd_profile_address_fieldset { display: none; }'; } add_action( 'edd_profile_editor_after', 'edd_stripe_maybe_hide_profile_editor_billing_address' ); /** * Zip / Postal Code field for when full billing address is disabled * * @since 2.5 * @return void */ function edd_stripe_zip_and_country() { $logged_in = is_user_logged_in(); $customer = EDD()->session->get( 'customer' ); $customer = wp_parse_args( $customer, array( 'address' => array( 'line1' => '', 'line2' => '', 'city' => '', 'zip' => '', 'state' => '', 'country' => '' ) ) ); $customer['address'] = array_map( 'sanitize_text_field', $customer['address'] ); if( $logged_in ) { $existing_cards = edd_stripe_get_existing_cards( get_current_user_id() ); if ( empty( $existing_cards ) ) { $user_address = edd_get_customer_address( get_current_user_id() ); foreach( $customer['address'] as $key => $field ) { if ( empty( $field ) && ! empty( $user_address[ $key ] ) ) { $customer['address'][ $key ] = $user_address[ $key ]; } else { $customer['address'][ $key ] = ''; } } } else { foreach ( $existing_cards as $card ) { if ( false === $card['default'] ) { continue; } $source = $card['source']; $customer['address'] = array( 'line1' => $source->address_line1, 'line2' => $source->address_line2, 'city' => $source->address_city, 'zip' => $source->address_zip, 'state' => $source->address_state, 'country' => $source->address_country, ); } } } ?>

autocomplete="billing postal-code" />

0 ) { return; } $hook = 'payment-elements' === edds_get_elements_mode() || apply_filters( 'edds_address_before_payment', false ) ? 'edd_before_cc_fields' : 'edd_after_cc_fields'; if ( edd_use_taxes() ) { remove_action( 'edd_after_cc_fields', 'edd_default_cc_address_fields' ); add_action( $hook, 'edd_default_cc_address_fields' ); return; } $display = edd_get_option( 'stripe_billing_fields', 'full' ); switch ( $display ) { case 'full': // Make address fields required. add_filter( 'edd_require_billing_address', '__return_true' ); remove_action( 'edd_after_cc_fields', 'edd_default_cc_address_fields' ); add_action( $hook, 'edd_default_cc_address_fields' ); break; case 'zip_country': remove_action( 'edd_after_cc_fields', 'edd_default_cc_address_fields', 10 ); add_action( $hook, 'edd_stripe_zip_and_country', 9 ); // Make Zip required. add_filter( 'edd_purchase_form_required_fields', 'edd_stripe_require_zip_and_country' ); break; case 'none': remove_action( 'edd_after_cc_fields', 'edd_default_cc_address_fields', 10 ); break; } } add_action( 'init', 'edd_stripe_setup_billing_address_fields', 9 ); /** * Force zip code and country to be required when billing address display is zip only * * @access public * @since 2.5 * @return array $fields The required fields */ function edd_stripe_require_zip_and_country( $fields ) { $fields['card_zip'] = array( 'error_id' => 'invalid_zip_code', 'error_message' => __( 'Please enter your zip / postal code', 'easy-digital-downloads' ) ); $fields['billing_country'] = array( 'error_id' => 'invalid_country', 'error_message' => __( 'Please select your billing country', 'easy-digital-downloads' ) ); return $fields; }