| 1 |  |  | <?php | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | if ( ! defined( 'ABSPATH' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | 	exit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * Credit Card Payment Gateway | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @since       2.6.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @package		WooCommerce/Classes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @author 		WooThemes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | class WC_Payment_Gateway_CC extends WC_Payment_Gateway { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 	 * Builds our payment fields area - including tokenization fields and the actualy payment fields. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 	 * If tokenization is displayed, just the fields will be displayed. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 	 * @since 2.6.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 	public function payment_fields() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 		if ( $display_tokenization ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 			$this->tokenization_script(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 			$this->saved_payment_methods(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 		$this->form(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 		if ( $display_tokenization ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 			$this->save_payment_method_checkbox(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 	 * Output field name HTML | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 	 * Gateways which support tokenization do not require names - we don't want the data to post to the server. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	 * @since  2.6.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	 * @param  string $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 	 * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 43 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  | 	public function field_name( $name ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  | 		return $this->supports( 'tokenization' ) ? '' : ' name="' . esc_attr( $this->id . '-' . $name ) . '" '; | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	 * Outputs fields for entering credit card information. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 	 * @since 2.6.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 	public function form() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 		$html   = ''; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 		$fields = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		$cvc_field = '<p class="form-row form-row-last"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 			<label for="' . esc_attr( $this->id ) . '-card-cvc">' . __( 'Card Code', 'woocommerce' ) . ' <span class="required">*</span></label> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 			<input id="' . esc_attr( $this->id ) . '-card-cvc" class="input-text wc-credit-card-form-card-cvc" type="text" autocomplete="off" placeholder="' . esc_attr__( 'CVC', 'woocommerce' ) . '" ' . $this->field_name( 'card-cvc' ) . ' style="width:100px" /> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		</p>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 		$default_fields = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 			'card-number-field' => '<p class="form-row form-row-wide"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 				<label for="' . esc_attr( $this->id ) . '-card-number">' . __( 'Card Number', 'woocommerce' ) . ' <span class="required">*</span></label> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 				<input id="' . esc_attr( $this->id ) . '-card-number" class="input-text wc-credit-card-form-card-number" type="text" maxlength="20" autocomplete="off" placeholder="•••• •••• •••• ••••" ' . $this->field_name( 'card-number' ) . ' /> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 			</p>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 			'card-expiry-field' => '<p class="form-row form-row-first"> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 				<label for="' . esc_attr( $this->id ) . '-card-expiry">' . __( 'Expiry (MM/YY)', 'woocommerce' ) . ' <span class="required">*</span></label> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 				<input id="' . esc_attr( $this->id ) . '-card-expiry" class="input-text wc-credit-card-form-card-expiry" type="text" autocomplete="off" placeholder="' . esc_attr__( 'MM / YY', 'woocommerce' ) . '" ' . $this->field_name( 'card-expiry' ) . ' /> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 			</p>' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 		if ( ! $this->supports( 'credit_card_form_cvc_on_saved_method' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 			$default_fields['card-cvc-field'] = $cvc_field; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 		$fields = wp_parse_args( $fields, apply_filters( 'woocommerce_credit_card_form_fields', $default_fields, $this->id ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 		?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class='wc-credit-card-form'> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 			<?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 				foreach ( $fields as $field ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 					echo $field; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 			?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 			<div class="clear"></div> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 		</fieldset> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 		<?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 		if ( $this->supports( 'credit_card_form_cvc_on_saved_method' ) ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 			echo '<fieldset>' . $cvc_field . '</fieldset>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 95 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 96 |  |  |  | 
            
                        
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.