2016-03-01 17:09:29 +00:00
|
|
|
<?php
|
2018-03-09 18:44:24 +00:00
|
|
|
/**
|
|
|
|
* Class WC_Payment_Gateway_CC file.
|
|
|
|
*
|
|
|
|
* @package WooCommerce\Gateways
|
|
|
|
*/
|
|
|
|
|
2016-03-01 17:09:29 +00:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Credit Card Payment Gateway
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
2020-08-05 16:36:24 +00:00
|
|
|
* @package WooCommerce\Classes
|
2016-03-01 17:09:29 +00:00
|
|
|
*/
|
2016-04-29 14:28:09 +00:00
|
|
|
class WC_Payment_Gateway_CC extends WC_Payment_Gateway {
|
2016-03-01 17:09:29 +00:00
|
|
|
|
2016-03-01 17:24:32 +00:00
|
|
|
/**
|
2016-05-26 10:48:25 +00:00
|
|
|
* Builds our payment fields area - including tokenization fields for logged
|
|
|
|
* in users, and the actual payment fields.
|
2018-03-09 12:53:10 +00:00
|
|
|
*
|
2016-03-01 17:24:32 +00:00
|
|
|
* @since 2.6.0
|
|
|
|
*/
|
2016-03-01 17:09:29 +00:00
|
|
|
public function payment_fields() {
|
2016-06-22 16:09:34 +00:00
|
|
|
if ( $this->supports( 'tokenization' ) && is_checkout() ) {
|
2016-03-01 18:14:34 +00:00
|
|
|
$this->tokenization_script();
|
2016-05-10 14:05:55 +00:00
|
|
|
$this->saved_payment_methods();
|
2016-05-26 10:48:25 +00:00
|
|
|
$this->form();
|
2016-03-01 17:09:29 +00:00
|
|
|
$this->save_payment_method_checkbox();
|
2016-05-26 10:48:25 +00:00
|
|
|
} else {
|
|
|
|
$this->form();
|
2016-03-01 17:09:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-10 15:17:12 +00:00
|
|
|
/**
|
|
|
|
* Output field name HTML
|
|
|
|
*
|
|
|
|
* Gateways which support tokenization do not require names - we don't want the data to post to the server.
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
2018-03-09 18:44:24 +00:00
|
|
|
* @param string $name Field name.
|
2016-05-10 15:17:12 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function field_name( $name ) {
|
|
|
|
return $this->supports( 'tokenization' ) ? '' : ' name="' . esc_attr( $this->id . '-' . $name ) . '" ';
|
|
|
|
}
|
|
|
|
|
2016-03-01 17:09:29 +00:00
|
|
|
/**
|
|
|
|
* Outputs fields for entering credit card information.
|
2018-03-09 12:53:10 +00:00
|
|
|
*
|
2016-03-01 17:09:29 +00:00
|
|
|
* @since 2.6.0
|
|
|
|
*/
|
|
|
|
public function form() {
|
2016-05-17 19:42:18 +00:00
|
|
|
wp_enqueue_script( 'wc-credit-card-form' );
|
|
|
|
|
2016-05-10 15:17:12 +00:00
|
|
|
$fields = array();
|
2016-03-01 17:09:29 +00:00
|
|
|
|
2016-03-04 12:32:38 +00:00
|
|
|
$cvc_field = '<p class="form-row form-row-last">
|
2018-04-04 14:45:40 +00:00
|
|
|
<label for="' . esc_attr( $this->id ) . '-card-cvc">' . esc_html__( 'Card code', 'woocommerce' ) . ' <span class="required">*</span></label>
|
2016-10-07 20:11:47 +00:00
|
|
|
<input id="' . esc_attr( $this->id ) . '-card-cvc" class="input-text wc-credit-card-form-card-cvc" inputmode="numeric" autocomplete="off" autocorrect="no" autocapitalize="no" spellcheck="no" type="tel" maxlength="4" placeholder="' . esc_attr__( 'CVC', 'woocommerce' ) . '" ' . $this->field_name( 'card-cvc' ) . ' style="width:100px" />
|
2016-03-01 17:09:29 +00:00
|
|
|
</p>';
|
|
|
|
|
|
|
|
$default_fields = array(
|
|
|
|
'card-number-field' => '<p class="form-row form-row-wide">
|
2018-04-04 14:45:40 +00:00
|
|
|
<label for="' . esc_attr( $this->id ) . '-card-number">' . esc_html__( 'Card number', 'woocommerce' ) . ' <span class="required">*</span></label>
|
2016-10-07 20:11:47 +00:00
|
|
|
<input id="' . esc_attr( $this->id ) . '-card-number" class="input-text wc-credit-card-form-card-number" inputmode="numeric" autocomplete="cc-number" autocorrect="no" autocapitalize="no" spellcheck="no" type="tel" placeholder="•••• •••• •••• ••••" ' . $this->field_name( 'card-number' ) . ' />
|
2016-03-01 17:09:29 +00:00
|
|
|
</p>',
|
|
|
|
'card-expiry-field' => '<p class="form-row form-row-first">
|
2018-04-04 14:45:40 +00:00
|
|
|
<label for="' . esc_attr( $this->id ) . '-card-expiry">' . esc_html__( 'Expiry (MM/YY)', 'woocommerce' ) . ' <span class="required">*</span></label>
|
2016-10-07 20:11:47 +00:00
|
|
|
<input id="' . esc_attr( $this->id ) . '-card-expiry" class="input-text wc-credit-card-form-card-expiry" inputmode="numeric" autocomplete="cc-exp" autocorrect="no" autocapitalize="no" spellcheck="no" type="tel" placeholder="' . esc_attr__( 'MM / YY', 'woocommerce' ) . '" ' . $this->field_name( 'card-expiry' ) . ' />
|
2016-08-27 13:56:21 +00:00
|
|
|
</p>',
|
2016-03-01 17:09:29 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if ( ! $this->supports( 'credit_card_form_cvc_on_saved_method' ) ) {
|
|
|
|
$default_fields['card-cvc-field'] = $cvc_field;
|
|
|
|
}
|
|
|
|
|
|
|
|
$fields = wp_parse_args( $fields, apply_filters( 'woocommerce_credit_card_form_fields', $default_fields, $this->id ) );
|
|
|
|
?>
|
|
|
|
|
2016-05-24 16:52:32 +00:00
|
|
|
<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class='wc-credit-card-form wc-payment-form'>
|
2016-03-01 17:09:29 +00:00
|
|
|
<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
|
|
|
|
<?php
|
2018-03-09 12:53:10 +00:00
|
|
|
foreach ( $fields as $field ) {
|
2018-03-09 18:44:24 +00:00
|
|
|
echo $field; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
|
2018-03-09 12:53:10 +00:00
|
|
|
}
|
2016-03-01 17:09:29 +00:00
|
|
|
?>
|
|
|
|
<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
|
|
|
|
<div class="clear"></div>
|
|
|
|
</fieldset>
|
|
|
|
<?php
|
2016-05-26 10:48:25 +00:00
|
|
|
|
2016-03-01 17:09:29 +00:00
|
|
|
if ( $this->supports( 'credit_card_form_cvc_on_saved_method' ) ) {
|
2018-03-09 18:44:24 +00:00
|
|
|
echo '<fieldset>' . $cvc_field . '</fieldset>'; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
|
2016-03-01 17:09:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|