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 for logged |
17
|
|
|
* in users, and the actual payment fields. |
18
|
|
|
* @since 2.6.0 |
19
|
|
|
*/ |
20
|
|
View Code Duplication |
public function payment_fields() { |
|
|
|
|
21
|
|
|
if ( $this->supports( 'tokenization' ) && is_checkout() && is_user_logged_in() ) { |
22
|
|
|
$this->tokenization_script(); |
23
|
|
|
$this->saved_payment_methods(); |
24
|
|
|
$this->form(); |
25
|
|
|
$this->save_payment_method_checkbox(); |
26
|
|
|
} else { |
27
|
|
|
$this->form(); |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Output field name HTML |
33
|
|
|
* |
34
|
|
|
* Gateways which support tokenization do not require names - we don't want the data to post to the server. |
35
|
|
|
* |
36
|
|
|
* @since 2.6.0 |
37
|
|
|
* @param string $name |
38
|
|
|
* @return string |
39
|
|
|
*/ |
40
|
|
|
public function field_name( $name ) { |
41
|
|
|
return $this->supports( 'tokenization' ) ? '' : ' name="' . esc_attr( $this->id . '-' . $name ) . '" '; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Outputs fields for entering credit card information. |
46
|
|
|
* @since 2.6.0 |
47
|
|
|
*/ |
48
|
|
|
public function form() { |
49
|
|
|
wp_enqueue_script( 'wc-credit-card-form' ); |
50
|
|
|
|
51
|
|
|
$fields = array(); |
52
|
|
|
|
53
|
|
|
$cvc_field = '<p class="form-row form-row-last"> |
54
|
|
|
<label for="' . esc_attr( $this->id ) . '-card-cvc">' . __( 'Card Code', 'woocommerce' ) . ' <span class="required">*</span></label> |
55
|
|
|
<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" /> |
56
|
|
|
</p>'; |
57
|
|
|
|
58
|
|
|
$default_fields = array( |
59
|
|
|
'card-number-field' => '<p class="form-row form-row-wide"> |
60
|
|
|
<label for="' . esc_attr( $this->id ) . '-card-number">' . __( 'Card Number', 'woocommerce' ) . ' <span class="required">*</span></label> |
61
|
|
|
<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' ) . ' /> |
62
|
|
|
</p>', |
63
|
|
|
'card-expiry-field' => '<p class="form-row form-row-first"> |
64
|
|
|
<label for="' . esc_attr( $this->id ) . '-card-expiry">' . __( 'Expiry (MM/YY)', 'woocommerce' ) . ' <span class="required">*</span></label> |
65
|
|
|
<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' ) . ' /> |
66
|
|
|
</p>' |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
if ( ! $this->supports( 'credit_card_form_cvc_on_saved_method' ) ) { |
70
|
|
|
$default_fields['card-cvc-field'] = $cvc_field; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$fields = wp_parse_args( $fields, apply_filters( 'woocommerce_credit_card_form_fields', $default_fields, $this->id ) ); |
74
|
|
|
?> |
75
|
|
|
|
76
|
|
|
<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class='wc-credit-card-form wc-payment-form'> |
77
|
|
|
<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?> |
78
|
|
|
<?php |
79
|
|
|
foreach ( $fields as $field ) { |
80
|
|
|
echo $field; |
81
|
|
|
} |
82
|
|
|
?> |
83
|
|
|
<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?> |
84
|
|
|
<div class="clear"></div> |
85
|
|
|
</fieldset> |
86
|
|
|
<?php |
87
|
|
|
|
88
|
|
|
if ( $this->supports( 'credit_card_form_cvc_on_saved_method' ) ) { |
89
|
|
|
echo '<fieldset>' . $cvc_field . '</fieldset>'; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.