* Remove WC_Payment_Gateway_Form in favor of having a Payment_Gateway_CC and Payment_Gateway_eCheck
* Fix up some comments to match other comments in the WC code base * Add some missing esc_* functions * Add a gateway filter to get_customer_tokens + a test for it
This commit is contained in:
parent
fa5283d3df
commit
c0b74296ff
|
@ -109,6 +109,20 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
|
|||
*/
|
||||
public $new_method_label = '';
|
||||
|
||||
protected $tokens = array();
|
||||
|
||||
public function get_tokens() {
|
||||
if ( sizeof( $this->tokens ) > 0 ) {
|
||||
return $this->tokens;
|
||||
}
|
||||
|
||||
if ( is_user_logged_in() && $this->supports( 'tokenization' ) && is_checkout() ) {
|
||||
$this->tokens = WC_Payment_Tokens::get_customer_tokens( get_current_user_id(), $this->id );
|
||||
}
|
||||
|
||||
return $this->tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the title for admin screens.
|
||||
* @return string
|
||||
|
@ -313,15 +327,12 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
|
|||
* Override this in your gateway if you have some.
|
||||
*/
|
||||
public function payment_fields() {
|
||||
|
||||
if ( $description = $this->get_description() ) {
|
||||
echo wpautop( wptexturize( $description ) );
|
||||
}
|
||||
|
||||
if ( $this->supports( 'default_credit_card_form' ) ) {
|
||||
$this->credit_card_form();
|
||||
} else {
|
||||
new WC_Payment_Gateway_Form( $this );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -339,6 +350,119 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
|
|||
return apply_filters( 'woocommerce_payment_gateway_supports', in_array( $feature, $this->supports ) ? true : false, $feature, $this );
|
||||
}
|
||||
|
||||
public function payment_gateway_script() {
|
||||
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
||||
wp_enqueue_script(
|
||||
'woocommerce-payment-gateway-form',
|
||||
plugins_url( '/assets/js/frontend/payment-gateway-form' . $suffix . '.js', WC_PLUGIN_FILE ),
|
||||
array( 'jquery' ),
|
||||
WC()->version
|
||||
);
|
||||
wp_localize_script( 'woocommerce-payment-gateway-form', 'woocommercePaymentGatewayParams', array(
|
||||
'gatewayID' => $this->id,
|
||||
'userLoggedIn' => (bool) is_user_logged_in(),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab and display our saved payment methods.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function saved_payment_methods() {
|
||||
$this->payment_gateway_script();
|
||||
$html = '<p>';
|
||||
foreach ( $this->get_tokens() as $token ) {
|
||||
$html .= $this->saved_payment_method( $token );
|
||||
}
|
||||
$html .= '</p><span id="wc-' . esc_attr( $this->id ) . '-method-count" data-count="' . esc_attr( count( $this->get_tokens() ) ) . '"></span>';
|
||||
$html .= '<div class="clear"></div>';
|
||||
echo apply_filters( 'wc_payment_gateway_form_saved_payment_methods_html', $html, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a saved payment method from a token.
|
||||
* @since 2.6.0
|
||||
* @param WC_Payment_Token $token Payment Token
|
||||
* @return string Generated payment method HTML
|
||||
*/
|
||||
public function saved_payment_method( $token ) {
|
||||
$html = sprintf(
|
||||
'<input type="radio" id="wc-%1$s-payment-token-%2$s" name="wc-%1$s-payment-token" style="width:auto;" class="wc-gateway-payment-token wc-%1$s-payment-token" value="%2$s" %3$s/>',
|
||||
esc_attr( $this->id ),
|
||||
esc_attr( $token->get_id() ),
|
||||
checked( $token->is_default(), true, false )
|
||||
);
|
||||
|
||||
$html .= sprintf( '<label class="wc-gateway-payment-form-saved-payment-method wc-gateway-payment-token-label" for="wc-%s-payment-token-%s">',
|
||||
esc_attr( $this->id ),
|
||||
esc_attr( $token->get_id() )
|
||||
);
|
||||
|
||||
$html .= $this->saved_payment_method_title( $token );
|
||||
$html .= '</label><br />';
|
||||
|
||||
return apply_filters( 'wc_payment_gateway_form_saved_payment_method_html', $html, $token, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a saved payment method's title based on the passed token.
|
||||
* @since 2.6.0
|
||||
* @param WC_Payment_Token $token Payment Token
|
||||
* @return string Generated payment method title HTML
|
||||
*/
|
||||
public function saved_payment_method_title( $token ) {
|
||||
if ( 'CC' == $token->get_type() && is_callable( array( $token, 'get_card_type' ) ) ) {
|
||||
$type = esc_html__( ucfirst( $token->get_card_type() ), 'woocommerce' );
|
||||
} else if ( 'eCheck' === $token->get_type() ) {
|
||||
$type = esc_html__( 'eCheck', 'woocommerce' );
|
||||
}
|
||||
|
||||
$type = apply_filters( 'wc_payment_gateway_form_saved_payment_method_title_type_html', $type, $token, $this );
|
||||
$title = $type;
|
||||
|
||||
if ( is_callable( array( $token, 'get_last4' ) ) ) {
|
||||
$title .= ' ' . sprintf( esc_html__( 'ending in %s', 'woocommerce' ), $token->get_last4() );
|
||||
}
|
||||
|
||||
if ( is_callable( array( $token, 'get_expiry_month' ) ) && is_callable( array( $token, 'get_expiry_year' ) ) ) {
|
||||
$title .= ' ' . sprintf( esc_html__( '(expires %s)', 'woocommerce' ), $token->get_expiry_month() . '/' . substr( $token->get_expiry_year(), 2 ) );
|
||||
}
|
||||
|
||||
return apply_filters( 'wc_payment_gateway_form_saved_payment_method_title_html', $title, $token, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a checkbox for saving a new payment method.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function save_payment_method_checkbox() {
|
||||
$html = sprintf(
|
||||
'<p class="form-row" id="wc-%s-new-payment-method-wrap">',
|
||||
esc_attr( $this->id )
|
||||
);
|
||||
$html .= sprintf(
|
||||
'<input name="wc-%1$s-new-payment-method" id="wc-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;"/>',
|
||||
esc_attr( $this->id )
|
||||
);
|
||||
$html .= sprintf(
|
||||
'<label for="wc-%s-new-payment-method" style="display:inline;">%s</label>',
|
||||
esc_attr( $this->id ),
|
||||
esc_html__( 'Save to Account', 'woocommerce' )
|
||||
);
|
||||
$html .= '</p><div class="clear"></div>';
|
||||
echo $html;
|
||||
}
|
||||
|
||||
public function use_new_payment_method_checkbox() {
|
||||
$label = ( ! empty( $this->new_method_label ) ? esc_html( $this->new_method_label ) : esc_html__( 'Use a new payment method', 'woocommerce' ) );
|
||||
|
||||
$html = '<input type="radio" id="wc-' . esc_attr( $this->id ). '-new" name="wc-' . esc_attr( $this->id ) . '-payment-token" value="new" style="width:auto;">';
|
||||
$html .= '<label class="wc-' . esc_attr( $this->id ) . '-payment-form-new-checkbox wc-gateway-payment-token-label" for="wc-' . esc_attr( $this->id ) . '-new">';
|
||||
$html .= apply_filters( 'woocommerce_payment_gateway_form_new_method_label', $label, $this );
|
||||
$html .= '</label>';
|
||||
echo '<div class="wc-' . esc_attr( $this->id ) . '-payment-form-new-checkbox-wrap">' . $html . '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Core credit card form which gateways can used if needed.
|
||||
*
|
||||
|
@ -346,42 +470,11 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
|
|||
* @param array $fields
|
||||
*/
|
||||
public function credit_card_form( $args = array(), $fields = array() ) {
|
||||
|
||||
wp_enqueue_script( 'wc-credit-card-form' );
|
||||
|
||||
$default_args = array(
|
||||
'fields_have_names' => true, // Some gateways like stripe don't need names as the form is tokenized.
|
||||
);
|
||||
|
||||
$args = wp_parse_args( $args, apply_filters( 'woocommerce_credit_card_form_args', $default_args, $this->id ) );
|
||||
|
||||
$default_fields = array(
|
||||
'card-number-field' => '<p class="form-row form-row-wide">
|
||||
<label for="' . esc_attr( $this->id ) . '-card-number">' . __( 'Card Number', 'woocommerce' ) . ' <span class="required">*</span></label>
|
||||
<input id="' . esc_attr( $this->id ) . '-card-number" class="input-text wc-credit-card-form-card-number" type="text" maxlength="20" autocomplete="off" placeholder="•••• •••• •••• ••••" name="' . ( $args['fields_have_names'] ? $this->id . '-card-number' : '' ) . '" />
|
||||
</p>',
|
||||
'card-expiry-field' => '<p class="form-row form-row-first">
|
||||
<label for="' . esc_attr( $this->id ) . '-card-expiry">' . __( 'Expiry (MM/YY)', 'woocommerce' ) . ' <span class="required">*</span></label>
|
||||
<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' ) . '" name="' . ( $args['fields_have_names'] ? $this->id . '-card-expiry' : '' ) . '" />
|
||||
</p>',
|
||||
'card-cvc-field' => '<p class="form-row form-row-last">
|
||||
<label for="' . esc_attr( $this->id ) . '-card-cvc">' . __( 'Card Code', 'woocommerce' ) . ' <span class="required">*</span></label>
|
||||
<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' ) . '" name="' . ( $args['fields_have_names'] ? $this->id . '-card-cvc' : '' ) . '" />
|
||||
</p>'
|
||||
);
|
||||
|
||||
$fields = wp_parse_args( $fields, apply_filters( 'woocommerce_credit_card_form_fields', $default_fields, $this->id ) );
|
||||
?>
|
||||
<fieldset id="<?php echo $this->id; ?>-cc-form">
|
||||
<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
|
||||
<?php
|
||||
foreach ( $fields as $field ) {
|
||||
echo $field;
|
||||
}
|
||||
?>
|
||||
<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
|
||||
<div class="clear"></div>
|
||||
</fieldset>
|
||||
<?php
|
||||
_deprecated_function( 'credit_card_form', '2.6', 'WC_Payment_Gateway_CC->form' );
|
||||
$cc_form = new WC_Payment_Gateway_CC;
|
||||
$cc_form->id = $this->id;
|
||||
$cc_form->supports = $this->supports;
|
||||
$cc_form->form();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,292 +0,0 @@
|
|||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* Default payment Form for gateways.
|
||||
*
|
||||
* @class WC_Payment_Gateway_Form
|
||||
* @since 2.6
|
||||
* @package WooCommerce/Classes
|
||||
* @category Class
|
||||
* @author WooThemes
|
||||
*/
|
||||
class WC_Payment_Gateway_Form {
|
||||
|
||||
/** @protected WC_Payment_Gateway Gateway Class */
|
||||
protected $gateway;
|
||||
|
||||
/**
|
||||
* Setup and hook into WordPress & WooCommerce.
|
||||
*
|
||||
* @since 2.6
|
||||
* @param WC_Payment_Gateway $gateway
|
||||
*/
|
||||
public function __construct( $gateway ) {
|
||||
$this->gateway = $gateway;
|
||||
$gateway_id = $this->gateway->id;
|
||||
|
||||
if ( is_user_logged_in() && $this->gateway->supports( 'tokenization' ) && is_checkout() ) {
|
||||
$this->tokens = $this->filter_tokens_by_gateway(
|
||||
$gateway_id,
|
||||
WC_Payment_Tokens::get_customer_tokens( get_current_user_id() )
|
||||
);
|
||||
$this->saved_payment_methods();
|
||||
}
|
||||
|
||||
if ( $this->gateway->supports( 'tokenization' ) && is_checkout() ) {
|
||||
$this->use_new_payment_method_checkbox();
|
||||
}
|
||||
|
||||
$this->load_scripts();
|
||||
$this->payment_fields();
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab and display our saved payment methods.
|
||||
*
|
||||
* @since 2.6
|
||||
*/
|
||||
public function saved_payment_methods() {
|
||||
$html = '<p>';
|
||||
|
||||
foreach ( $this->tokens as $token ) {
|
||||
$html .= $this->saved_payment_method( $token );
|
||||
}
|
||||
|
||||
$html .= '</p><span id="wc-' . $this->gateway->id . '-method-count" data-count="' . esc_attr( count( $this->tokens ) ) . '"></span>';
|
||||
$html .= '<div class="clear"></div>';
|
||||
|
||||
echo apply_filters( 'wc_payment_gateway_form_saved_payment_methods_html', $html, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a saved payment method from a token.
|
||||
*
|
||||
* @since 2.6
|
||||
* @param WC_Payment_Token $token Payment Token
|
||||
* @return string Generated payment method HTML
|
||||
*/
|
||||
public function saved_payment_method( $token ) {
|
||||
$html = sprintf(
|
||||
'<input type="radio" id="wc-%1$s-payment-token-%2$s" name="wc-%1$s-payment-token" style="width:auto;" class="wc-gateway-payment-token wc-%1$s-payment-token" value="%2$s" %3$s/>',
|
||||
esc_attr( $this->gateway->id ),
|
||||
esc_attr( $token->get_id() ),
|
||||
checked( $token->is_default(), true, false )
|
||||
);
|
||||
|
||||
$html .= sprintf( '<label class="wc-gateway-payment-form-saved-payment-method wc-gateway-payment-token-label" for="wc-%s-payment-token-%s">',
|
||||
esc_attr( $this->gateway->id ),
|
||||
esc_attr( $token->get_id() )
|
||||
);
|
||||
|
||||
$html .= $this->saved_payment_method_title( $token );
|
||||
$html .= '</label><br />';
|
||||
|
||||
return apply_filters( 'wc_payment_gateway_form_saved_payment_method_html', $html, $token, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a saved payment method's title based on the passed token.
|
||||
*
|
||||
* @since 2.6
|
||||
* @param WC_Payment_Token $token Payment Token
|
||||
* @return string Generated payment method title HTML
|
||||
*/
|
||||
public function saved_payment_method_title( $token ) {
|
||||
if ( 'CC' == $token->get_type() && is_callable( array( $token, 'get_card_type' ) ) ) {
|
||||
$type = esc_html__( ucfirst( $token->get_card_type() ), 'woocommerce' );
|
||||
} else if ( 'eCheck' === $token->get_type() ) {
|
||||
$type = esc_html__( 'eCheck', 'woocommerce' );
|
||||
}
|
||||
|
||||
$type = apply_filters( 'wc_payment_gateway_form_saved_payment_method_title_type_html', $type, $token, $this );
|
||||
$title = $type;
|
||||
|
||||
if ( is_callable( array( $token, 'get_last4' ) ) ) {
|
||||
$title .= ' ' . sprintf( esc_html__( 'ending in %s', 'woocommerce' ), $token->get_last4() );
|
||||
}
|
||||
|
||||
if ( is_callable( array( $token, 'get_expiry_month' ) ) && is_callable( array( $token, 'get_expiry_year' ) ) ) {
|
||||
$title .= ' ' . sprintf( esc_html__( '(expires %s)', 'woocommerce' ), $token->get_expiry_month() . '/' . substr( $token->get_expiry_year(), 2 ) );
|
||||
}
|
||||
|
||||
return apply_filters( 'wc_payment_gateway_form_saved_payment_method_title_html', $title, $token, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs payment fields for entering new card info.
|
||||
*
|
||||
* @since 2.6
|
||||
*/
|
||||
public function payment_fields() {
|
||||
if ( $this->gateway->supports( 'credit_card_form' ) ) {
|
||||
echo $this->credit_card_payment_fields();
|
||||
if ( $this->gateway->supports( 'tokenization' ) && is_checkout() ) {
|
||||
$this->save_payment_method_checkbox();
|
||||
}
|
||||
} else if ( $this->gateway->supports( 'echeck_form' ) ) {
|
||||
echo $this->echeck_payment_fields();
|
||||
if ( $this->gateway->supports( 'tokenization' ) && is_checkout() ) {
|
||||
$this->save_payment_method_checkbox();
|
||||
}
|
||||
} else {
|
||||
echo apply_filters( 'wc_payment_gateway_form_payment_fields_html', '', $this );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters out tokens not for the current gateway.
|
||||
*
|
||||
* @since 2.6
|
||||
* @param string $gateway_id Gateway ID
|
||||
* @param array $tokens Set of tokens
|
||||
* @return array Subset of tokens based on gateway ID
|
||||
*/
|
||||
public function filter_tokens_by_gateway( $gateway_id, $tokens ) {
|
||||
$filtered_tokens = array();
|
||||
foreach ( $tokens as $key => $token ) {
|
||||
if ( $gateway_id === $token->get_gateway_id() ) {
|
||||
$filtered_tokens[ $key ] = $token;
|
||||
}
|
||||
}
|
||||
return $filtered_tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs fields for entering credit card information.
|
||||
*
|
||||
* @since 2.6
|
||||
*/
|
||||
public function credit_card_payment_fields() {
|
||||
$html = '';
|
||||
$fields = array();
|
||||
$cvc_class = '';
|
||||
|
||||
$cvc_field = '<p class="form-row form-row-wide">
|
||||
<label for="' . esc_attr( $this->gateway->id ) . '-card-cvc">' . __( 'Card Code', 'woocommerce' ) . ' <span class="required">*</span></label>
|
||||
<input id="' . esc_attr( $this->gateway->id ) . '-card-cvc" class="input-text wc-credit-card-form-card-cvc" type="text" autocomplete="off" placeholder="' . esc_attr__( 'CVC', 'woocommerce' ) . '" name="' . esc_attr( $this->gateway->id ) . '-card-cvc" style="width:100px" />
|
||||
</p>';
|
||||
|
||||
$default_fields = array(
|
||||
'card-number-field' => '<p class="form-row form-row-wide">
|
||||
<label for="' . esc_attr( $this->gateway->id ) . '-card-number">' . __( 'Card Number', 'woocommerce' ) . ' <span class="required">*</span></label>
|
||||
<input id="' . esc_attr( $this->gateway->id ) . '-card-number" class="input-text wc-credit-card-form-card-number" type="text" maxlength="20" autocomplete="off" placeholder="•••• •••• •••• ••••" name="' . esc_attr( $this->gateway->id ) . '-card-number" />
|
||||
</p>',
|
||||
'card-expiry-field' => '<p class="form-row form-row-first">
|
||||
<label for="' . esc_attr( $this->gateway->id ) . '-card-expiry">' . __( 'Expiry (MM/YY)', 'woocommerce' ) . ' <span class="required">*</span></label>
|
||||
<input id="' . esc_attr( $this->gateway->id ) . '-card-expiry" class="input-text wc-credit-card-form-card-expiry" type="text" autocomplete="off" placeholder="' . esc_attr__( 'MM / YY', 'woocommerce' ) . '" name="' . esc_attr( $this->gateway->id ) . '-card-expiry" />
|
||||
</p>'
|
||||
);
|
||||
|
||||
if ( ! $this->gateway->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->gateway->id ) );
|
||||
?>
|
||||
|
||||
<fieldset id="wc-<?php echo esc_attr( $this->gateway->id ); ?>-cc-form" class='wc-credit-card-form'>
|
||||
<?php do_action( 'woocommerce_credit_card_form_start', $this->gateway->id ); ?>
|
||||
<?php
|
||||
foreach ( $fields as $field ) {
|
||||
echo $field;
|
||||
}
|
||||
?>
|
||||
<?php do_action( 'woocommerce_credit_card_form_end', $this->gateway->id ); ?>
|
||||
<div class="clear"></div>
|
||||
</fieldset>
|
||||
<?php
|
||||
if ( $this->gateway->supports( 'credit_card_form_cvc_on_saved_method' ) ) {
|
||||
echo '<fieldset>' . $cvc_field . '</fieldset>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs fields for entering echeck information.
|
||||
*
|
||||
* @since 2.6
|
||||
* @return string eCheck form HTML
|
||||
*/
|
||||
public function echeck_payment_fields() {
|
||||
$html = '';
|
||||
$fields = array();
|
||||
|
||||
$default_fields = array(
|
||||
'routing-number' => '<p class="form-row form-row-first">
|
||||
<label for="' . esc_attr( $this->gateway->id ) . '-routing-number">' . __( 'Routing Number', 'woocommerce' ) . ' <span class="required">*</span></label>
|
||||
<input id="' . esc_attr( $this->gateway->id ) . '-routing-number" class="input-text wc-echeck-form-routing-number" type="text" maxlength="9" autocomplete="off" placeholder="•••••••••" name="' . esc_attr( $this->gateway->id ) . '-routing-number" />
|
||||
</p>',
|
||||
'account-number' => '<p class="form-row form-row-wide">
|
||||
<label for="' . esc_attr( $this->gateway->id ) . '-account-number">' . __( 'Account Number', 'woocommerce' ) . ' <span class="required">*</span></label>
|
||||
<input id="' . esc_attr( $this->gateway->id ) . '-account-number" class="input-text wc-echeck-form-account-number" type="text" autocomplete="off" name="' . esc_attr( $this->gateway->id ) . '-account-number" maxlength="17" />
|
||||
</p>',
|
||||
);
|
||||
|
||||
$fields = wp_parse_args( $fields, apply_filters( 'woocommerce_echeck_form_fields', $default_fields, $this->gateway->id ) );
|
||||
?>
|
||||
|
||||
<fieldset id="<?php echo esc_attr( $this->gateway->id ); ?>-cc-form" class='wc-echeck-form'>
|
||||
<?php do_action( 'woocommerce_echeck_form_start', $this->gateway->id ); ?>
|
||||
<?php
|
||||
foreach ( $fields as $field ) {
|
||||
echo $field;
|
||||
}
|
||||
?>
|
||||
<?php do_action( 'woocommerce_echeck_form_end', $this->gateway->id ); ?>
|
||||
<div class="clear"></div>
|
||||
</fieldset><?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a checkbox for saving a new payment method.
|
||||
*
|
||||
* @since 2.6
|
||||
*/
|
||||
public function save_payment_method_checkbox() {
|
||||
$html = sprintf(
|
||||
'<p class="form-row" id="wc-%s-new-payment-method-wrap">',
|
||||
esc_attr( $this->gateway->id )
|
||||
);
|
||||
$html .= sprintf(
|
||||
'<input name="wc-%1$s-new-payment-method" id="wc-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;"/>',
|
||||
esc_attr( $this->gateway->id )
|
||||
);
|
||||
$html .= sprintf(
|
||||
'<label for="wc-%s-new-payment-method" style="display:inline;">%s</label>',
|
||||
esc_attr( $this->gateway->id ),
|
||||
esc_html__( 'Save to Account', 'woocommerce' )
|
||||
);
|
||||
$html .= '</p><div class="clear"></div>';
|
||||
echo $html;
|
||||
}
|
||||
|
||||
public function use_new_payment_method_checkbox() {
|
||||
$label = ( ! empty( $this->gateway->new_method_label ) ? esc_html( $this->gateway->new_method_label ) : esc_html__( 'Use a new payment method', 'woocommerce' ) );
|
||||
|
||||
$html = '<input type="radio" id="wc-' . esc_attr( $this->gateway->id ). '-new" name="wc-' . esc_attr( $this->gateway->id ) . '-payment-token" value="new" style="width:auto;">';
|
||||
$html .= '<label class="wc-' . esc_attr( $this->gateway->id ) . '-payment-form-new-checkbox wc-gateway-payment-token-label" for="wc-' . esc_attr( $this->gateway->id ) . '-new">';
|
||||
$html .= apply_filters( 'woocommerce_payment_gateway_form_new_method_label', $label, $this->gateway );
|
||||
$html .= '</label>';
|
||||
echo '<div class="wc-' . esc_attr( $this->gateway->id ) . '-payment-form-new-checkbox-wrap">' . $html . '</div>';
|
||||
}
|
||||
|
||||
public function load_scripts() {
|
||||
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
||||
wp_enqueue_script(
|
||||
'woocommerce-payment-gateway-form',
|
||||
plugins_url( '/assets/js/frontend/payment-gateway-form' . $suffix . '.js', WC_PLUGIN_FILE ),
|
||||
array( 'jquery' ),
|
||||
WC()->version
|
||||
);
|
||||
|
||||
wp_localize_script( 'woocommerce-payment-gateway-form', 'woocommercePaymentGatewayParams', array(
|
||||
'gatewayID' => $this->gateway->id,
|
||||
'userLoggedIn' => (bool) is_user_logged_in(),
|
||||
) );
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -19,11 +19,12 @@ class WC_Payment_Tokens {
|
|||
|
||||
/**
|
||||
* Returns an array of payment token objects associated with the passed customer ID
|
||||
* @since 2.6
|
||||
* @param int $customer_id Customer ID
|
||||
* @return array Array of token objects
|
||||
* @since 2.6.0
|
||||
* @param int $customer_id Customer ID
|
||||
* @param string $gateway Optional Gateway ID for getting tokens for a specific gateway
|
||||
* @return array Array of token objects
|
||||
*/
|
||||
public static function get_customer_tokens( $customer_id ) {
|
||||
public static function get_customer_tokens( $customer_id, $gateway_id = '' ) {
|
||||
if ( $customer_id < 1 ) {
|
||||
return array();
|
||||
}
|
||||
|
@ -41,9 +42,11 @@ class WC_Payment_Tokens {
|
|||
|
||||
$tokens = array();
|
||||
foreach ( $token_results as $token_result ) {
|
||||
$_token = self::get( $token_result->token_id, $token_result );
|
||||
if ( ! empty( $_token ) ) {
|
||||
$tokens[ $token_result->token_id ] = $_token;
|
||||
if ( empty( $gateway_id ) || $gateway_id === $token_result->gateway_id ) {
|
||||
$_token = self::get( $token_result->token_id, $token_result );
|
||||
if ( ! empty( $_token ) ) {
|
||||
$tokens[ $token_result->token_id ] = $_token;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Credit Card Payment Gateway
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @package WooCommerce/Classes
|
||||
* @author WooThemes
|
||||
*/
|
||||
class WC_Payment_Gateway_CC extends WC_Payment_Gateway {
|
||||
|
||||
public function payment_fields() {
|
||||
$display_tokenization = $this->supports( 'tokenization' ) && is_checkout();
|
||||
|
||||
if ( $display_tokenization ) {
|
||||
if ( is_user_logged_in() ) {
|
||||
$this->saved_payment_methods();
|
||||
}
|
||||
$this->use_new_payment_method_checkbox();
|
||||
}
|
||||
|
||||
$this->form();
|
||||
|
||||
if ( $display_tokenization ) {
|
||||
$this->save_payment_method_checkbox();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs fields for entering credit card information.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function form() {
|
||||
$html = '';
|
||||
$fields = array();
|
||||
$cvc_class = '';
|
||||
|
||||
$cvc_field = '<p class="form-row form-row-wide">
|
||||
<label for="' . esc_attr( $this->id ) . '-card-cvc">' . __( 'Card Code', 'woocommerce' ) . ' <span class="required">*</span></label>
|
||||
<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' ) . '" name="' . esc_attr( $this->id ) . '-card-cvc" style="width:100px" />
|
||||
</p>';
|
||||
|
||||
$default_fields = array(
|
||||
'card-number-field' => '<p class="form-row form-row-wide">
|
||||
<label for="' . esc_attr( $this->id ) . '-card-number">' . __( 'Card Number', 'woocommerce' ) . ' <span class="required">*</span></label>
|
||||
<input id="' . esc_attr( $this->id ) . '-card-number" class="input-text wc-credit-card-form-card-number" type="text" maxlength="20" autocomplete="off" placeholder="•••• •••• •••• ••••" name="' . esc_attr( $this->id ) . '-card-number" />
|
||||
</p>',
|
||||
'card-expiry-field' => '<p class="form-row form-row-first">
|
||||
<label for="' . esc_attr( $this->id ) . '-card-expiry">' . __( 'Expiry (MM/YY)', 'woocommerce' ) . ' <span class="required">*</span></label>
|
||||
<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' ) . '" name="' . esc_attr( $this->id ) . '-card-expiry" />
|
||||
</p>'
|
||||
);
|
||||
|
||||
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 ) );
|
||||
?>
|
||||
|
||||
<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class='wc-credit-card-form'>
|
||||
<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
|
||||
<?php
|
||||
foreach ( $fields as $field ) {
|
||||
echo $field;
|
||||
}
|
||||
?>
|
||||
<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
|
||||
<div class="clear"></div>
|
||||
</fieldset>
|
||||
<?php
|
||||
if ( $this->supports( 'credit_card_form_cvc_on_saved_method' ) ) {
|
||||
echo '<fieldset>' . $cvc_field . '</fieldset>';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* eCheck Payment Gateway
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @package WooCommerce/Classes
|
||||
* @author WooThemes
|
||||
*/
|
||||
class WC_Payment_Gateway_eCheck extends WC_Payment_Gateway {
|
||||
|
||||
public function payment_fields() {
|
||||
$display_tokenization = $this->supports( 'tokenization' ) && is_checkout();
|
||||
|
||||
if ( $display_tokenization ) {
|
||||
if ( is_user_logged_in() ) {
|
||||
$this->saved_payment_methods();
|
||||
}
|
||||
$this->use_new_payment_method_checkbox();
|
||||
}
|
||||
|
||||
$this->form();
|
||||
|
||||
if ( $display_tokenization ) {
|
||||
$this->save_payment_method_checkbox();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs fields for entering eCheck information.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function form() {
|
||||
$html = '';
|
||||
$fields = array();
|
||||
|
||||
$default_fields = array(
|
||||
'routing-number' => '<p class="form-row form-row-first">
|
||||
<label for="' . esc_attr( $this->id ) . '-routing-number">' . __( 'Routing Number', 'woocommerce' ) . ' <span class="required">*</span></label>
|
||||
<input id="' . esc_attr( $this->id ) . '-routing-number" class="input-text wc-echeck-form-routing-number" type="text" maxlength="9" autocomplete="off" placeholder="•••••••••" name="' . esc_attr( $this->id ) . '-routing-number" />
|
||||
</p>',
|
||||
'account-number' => '<p class="form-row form-row-wide">
|
||||
<label for="' . esc_attr( $this->id ) . '-account-number">' . __( 'Account Number', 'woocommerce' ) . ' <span class="required">*</span></label>
|
||||
<input id="' . esc_attr( $this->id ) . '-account-number" class="input-text wc-echeck-form-account-number" type="text" autocomplete="off" name="' . esc_attr( $this->id ) . '-account-number" maxlength="17" />
|
||||
</p>',
|
||||
);
|
||||
|
||||
$fields = wp_parse_args( $fields, apply_filters( 'woocommerce_echeck_form_fields', $default_fields, $this->id ) );
|
||||
?>
|
||||
|
||||
<fieldset id="<?php echo esc_attr( $this->id ); ?>-cc-form" class='wc-echeck-form'>
|
||||
<?php do_action( 'woocommerce_echeck_form_start', $this->id ); ?>
|
||||
<?php
|
||||
foreach ( $fields as $field ) {
|
||||
echo $field;
|
||||
}
|
||||
?>
|
||||
<?php do_action( 'woocommerce_echeck_form_end', $this->id ); ?>
|
||||
<div class="clear"></div>
|
||||
</fieldset><?php
|
||||
}
|
||||
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
// Form handler
|
||||
function simplifyFormHandler() {
|
||||
var $form = $( 'form.checkout, form#order_review, orm#add_payment_method' );
|
||||
var $form = $( 'form.checkout, form#order_review, form#add_payment_method' );
|
||||
|
||||
if ( ( $( '#payment_method_simplify_commerce' ).is( ':checked' ) && $( '#wc-simplify_commerce-new' ).is( ':checked' ) ) || ( '1' === $( '#woocommerce_add_payment_method' ).val() ) ) {
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
!function(a){function b(){var b=a("form.checkout, form#order_review, orm#add_payment_method");if((a("#payment_method_simplify_commerce").is(":checked")&&a("#wc-simplify_commerce-new").is(":checked")||"1"===a("#woocommerce_add_payment_method").val())&&0===a("input.simplify-token").length){b.block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var d=a("#simplify_commerce-card-number").val(),e=a("#simplify_commerce-card-cvc").val(),f=a.payment.cardExpiryVal(a("#simplify_commerce-card-expiry").val()),g=b.find("#billing_address_1").val(),h=b.find("#billing_address_2").val(),i=b.find("#billing_country").val(),j=b.find("#billing_state").val(),k=b.find("#billing_city").val(),l=b.find("#billing_postcode").val();return d=d.replace(/\s/g,""),SimplifyCommerce.generateToken({key:Simplify_commerce_params.key,card:{number:d,cvc:e,expMonth:f.month,expYear:f.year-2e3,addressLine1:g,addressLine2:h,addressCountry:i,addressState:j,addressZip:l,addressCity:k}},c),!1}return!0}function c(b){var c=a("form.checkout, form#order_review, form#add_payment_method"),d=a("#wc-simplify_commerce-cc-form");if(b.error){if(a(".woocommerce-error, .simplify-token",d).remove(),c.unblock(),"validation"===b.error.code){for(var e=b.error.fieldErrors,f=e.length,g="",h=0;f>h;h++)g+="<li>"+Simplify_commerce_params[e[h].field]+" "+Simplify_commerce_params.is_invalid+" - "+e[h].message+".</li>";d.prepend('<ul class="woocommerce-error">'+g+"</ul>")}}else d.append('<input type="hidden" class="simplify-token" name="simplify_token" value="'+b.id+'"/>'),c.submit()}a(function(){a(document.body).on("checkout_error",function(){a(".simplify-token").remove()}),a("form.checkout").on("checkout_place_order_simplify_commerce",function(){return b()}),a("form#order_review").on("submit",function(){return b()}),a("form#add_payment_method").on("submit",function(){return b()}),a("form.checkout, form#order_review, form#add_payment_method").on("change","#wc-simplify_commerce-cc-form input",function(){a(".simplify-token").remove()})})}(jQuery);
|
||||
!function(a){function b(){var b=a("form.checkout, form#order_review, form#add_payment_method");if((a("#payment_method_simplify_commerce").is(":checked")&&a("#wc-simplify_commerce-new").is(":checked")||"1"===a("#woocommerce_add_payment_method").val())&&0===a("input.simplify-token").length){b.block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var d=a("#simplify_commerce-card-number").val(),e=a("#simplify_commerce-card-cvc").val(),f=a.payment.cardExpiryVal(a("#simplify_commerce-card-expiry").val()),g=b.find("#billing_address_1").val(),h=b.find("#billing_address_2").val(),i=b.find("#billing_country").val(),j=b.find("#billing_state").val(),k=b.find("#billing_city").val(),l=b.find("#billing_postcode").val();return d=d.replace(/\s/g,""),SimplifyCommerce.generateToken({key:Simplify_commerce_params.key,card:{number:d,cvc:e,expMonth:f.month,expYear:f.year-2e3,addressLine1:g,addressLine2:h,addressCountry:i,addressState:j,addressZip:l,addressCity:k}},c),!1}return!0}function c(b){var c=a("form.checkout, form#order_review, form#add_payment_method"),d=a("#wc-simplify_commerce-cc-form");if(b.error){if(a(".woocommerce-error, .simplify-token",d).remove(),c.unblock(),"validation"===b.error.code){for(var e=b.error.fieldErrors,f=e.length,g="",h=0;f>h;h++)g+="<li>"+Simplify_commerce_params[e[h].field]+" "+Simplify_commerce_params.is_invalid+" - "+e[h].message+".</li>";d.prepend('<ul class="woocommerce-error">'+g+"</ul>")}}else d.append('<input type="hidden" class="simplify-token" name="simplify_token" value="'+b.id+'"/>'),c.submit()}a(function(){a(document.body).on("checkout_error",function(){a(".simplify-token").remove()}),a("form.checkout").on("checkout_place_order_simplify_commerce",function(){return b()}),a("form#order_review").on("submit",function(){return b()}),a("form#add_payment_method").on("submit",function(){return b()}),a("form.checkout, form#order_review, form#add_payment_method").on("change","#wc-simplify_commerce-cc-form input",function(){a(".simplify-token").remove()})})}(jQuery);
|
|
@ -8,13 +8,13 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
* Simplify Commerce Gateway.
|
||||
*
|
||||
* @class WC_Gateway_Simplify_Commerce
|
||||
* @extends WC_Payment_Gateway
|
||||
* @extends WC_Payment_Gateway_CC
|
||||
* @since 2.2.0
|
||||
* @version 1.0.0
|
||||
* @package WooCommerce/Classes/Payment
|
||||
* @author WooThemes
|
||||
*/
|
||||
class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway {
|
||||
class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway_CC {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -37,7 +37,7 @@ class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway {
|
|||
'subscription_payment_method_change_admin',
|
||||
'subscription_date_changes',
|
||||
'multiple_subscriptions',
|
||||
'credit_card_form',
|
||||
'default_credit_card_form',
|
||||
'tokenization',
|
||||
'refunds',
|
||||
'pre-orders'
|
||||
|
@ -276,7 +276,7 @@ class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway {
|
|||
}
|
||||
|
||||
if ( 'standard' == $this->mode ) {
|
||||
new WC_Payment_Gateway_Form( $this );
|
||||
parent::payment_fields();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,9 +8,8 @@ namespace WooCommerce\Tests\Payment_Tokens;
|
|||
class Payment_Token_CC extends \WC_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* Test validation for empty/unset values
|
||||
*
|
||||
* @since 2.6
|
||||
* Test validation for empty/unset values.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
function test_wc_payment_token_cc_validate_empty() {
|
||||
$token = new \WC_Payment_Token_CC( 1 );
|
||||
|
@ -24,9 +23,8 @@ class Payment_Token_CC extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test validation for expiry length
|
||||
*
|
||||
* @since 2.6
|
||||
* Test validation for expiry length.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
function test_wc_payment_token_cc_validate_expiry_length() {
|
||||
$token = new \WC_Payment_Token_CC( 1 );
|
||||
|
@ -48,9 +46,8 @@ class Payment_Token_CC extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test getting a card type
|
||||
*
|
||||
* @since 2.6
|
||||
* Test getting a card type.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_cc_get_card_type() {
|
||||
$token = new \WC_Payment_Token_CC( 1, array(), array( 'card_type' => 'mastercard' ) );
|
||||
|
@ -58,9 +55,8 @@ class Payment_Token_CC extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test setting a token's card type
|
||||
*
|
||||
* @since 2.6
|
||||
* Test setting a token's card type.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_cc_set_card_type() {
|
||||
$token = new \WC_Payment_Token_CC( 1 );
|
||||
|
@ -69,9 +65,8 @@ class Payment_Token_CC extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test getting expiry year
|
||||
*
|
||||
* @since 2.6
|
||||
* Test getting expiry year.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_cc_get_expiry_year() {
|
||||
$token = new \WC_Payment_Token_CC( 1, array(), array( 'expiry_year' => '2016' ) );
|
||||
|
@ -79,9 +74,8 @@ class Payment_Token_CC extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test setting a token's expiry year
|
||||
*
|
||||
* @since 2.6
|
||||
* Test setting a token's expiry year.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_cc_set_expiry_year() {
|
||||
$token = new \WC_Payment_Token_CC( 1 );
|
||||
|
@ -90,9 +84,8 @@ class Payment_Token_CC extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test getting expiry month
|
||||
*
|
||||
* @since 2.6
|
||||
* Test getting expiry month.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_cc_get_expiry_month() {
|
||||
$token = new \WC_Payment_Token_CC( 1, array(), array( 'expiry_month' => '08' ) );
|
||||
|
@ -100,9 +93,8 @@ class Payment_Token_CC extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test setting a token's expiry month
|
||||
*
|
||||
* @since 2.6
|
||||
* Test setting a token's expiry month.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_cc_set_expiry_month() {
|
||||
$token = new \WC_Payment_Token_CC( 1 );
|
||||
|
@ -111,9 +103,8 @@ class Payment_Token_CC extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test getting last4
|
||||
*
|
||||
* @since 2.6
|
||||
* Test getting last4.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_cc_get_last4() {
|
||||
$token = new \WC_Payment_Token_CC( 1, array(), array( 'last4' => '1111' ) );
|
||||
|
@ -121,9 +112,8 @@ class Payment_Token_CC extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test setting a token's last4
|
||||
*
|
||||
* @since 2.6
|
||||
* Test setting a token's last4.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_cc_set_last4() {
|
||||
$token = new \WC_Payment_Token_CC( 1 );
|
||||
|
@ -132,9 +122,8 @@ class Payment_Token_CC extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test reading/getting a token from DB correctly sets meta
|
||||
*
|
||||
* @since 2.6
|
||||
* Test reading/getting a token from DB correctly sets meta.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_cc_read_pulls_meta() {
|
||||
$token = \WC_Helper_Payment_Token::create_cc_token();
|
||||
|
|
|
@ -8,9 +8,8 @@ namespace WooCommerce\Tests\Payment_Tokens;
|
|||
class Payment_Token_eCheck extends \WC_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* Test validation for empty/unset values
|
||||
*
|
||||
* @since 2.6
|
||||
* Test validation for empty/unset values.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
function test_wc_payment_token_echeck_validate_empty() {
|
||||
$token = new \WC_Payment_Token_eCheck( 1 );
|
||||
|
@ -21,9 +20,8 @@ class Payment_Token_eCheck extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test getting last4
|
||||
*
|
||||
* @since 2.6
|
||||
* Test getting last4.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_echeck_get_last4() {
|
||||
$token = new \WC_Payment_Token_eCheck( 1, array(), array( 'last4' => '1111' ) );
|
||||
|
@ -31,9 +29,8 @@ class Payment_Token_eCheck extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test setting a token's last4
|
||||
*
|
||||
* @since 2.6
|
||||
* Test setting a token's last4.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_echeck_set_last4() {
|
||||
$token = new \WC_Payment_Token_eCheck( 1 );
|
||||
|
@ -42,9 +39,8 @@ class Payment_Token_eCheck extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test reading/getting a token from DB correctly sets meta
|
||||
*
|
||||
* @since 2.6
|
||||
* Test reading/getting a token from DB correctly sets meta.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_echeck_read_pulls_meta() {
|
||||
$token = \WC_Helper_Payment_Token::create_eCheck_token();
|
||||
|
|
|
@ -8,9 +8,8 @@ namespace WooCommerce\Tests\Payment_Tokens;
|
|||
class Payment_Token extends \WC_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* Test get_id to make sure it returns the ID passed into the class
|
||||
*
|
||||
* @since 2.6
|
||||
* Test get_id to make sure it returns the ID passed into the class.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_get_id() {
|
||||
$token = new \WC_Payment_Token_Stub( 1 );
|
||||
|
@ -18,9 +17,8 @@ class Payment_Token extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test get type returns the class name/type
|
||||
*
|
||||
* @since 2.6
|
||||
* Test get type returns the class name/type.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_get_type() {
|
||||
$token = new \WC_Payment_Token_Stub( 1 );
|
||||
|
@ -28,9 +26,8 @@ class Payment_Token extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test get token to make sure it returns the passed token
|
||||
*
|
||||
* @since 2.6
|
||||
* Test get token to make sure it returns the passed token.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_get_token() {
|
||||
$raw_token = time() . ' ' . __FUNCTION__;
|
||||
|
@ -39,9 +36,8 @@ class Payment_Token extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test set token to make sure it sets the pased token
|
||||
*
|
||||
* @since 2.6
|
||||
* Test set token to make sure it sets the pased token.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_set_token() {
|
||||
$raw_token = time() . ' ' . __FUNCTION__;
|
||||
|
@ -51,9 +47,8 @@ class Payment_Token extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test get user ID to make sure it passes the correct ID
|
||||
*
|
||||
* @since 2.6
|
||||
* Test get user ID to make sure it passes the correct ID.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_get_user_id() {
|
||||
$token = new \WC_Payment_Token_Stub( 1, array( 'user_id' => 1 ) );
|
||||
|
@ -61,9 +56,8 @@ class Payment_Token extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test get user ID to make sure it returns 0 if there is no user ID
|
||||
*
|
||||
* @since 2.6
|
||||
* Test get user ID to make sure it returns 0 if there is no user ID.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_get_user_id_defaults_to_0() {
|
||||
$token = new \WC_Payment_Token_Stub( 1 );
|
||||
|
@ -71,9 +65,8 @@ class Payment_Token extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test set user ID to make sure it passes the correct ID
|
||||
*
|
||||
* @since 2.6
|
||||
* Test set user ID to make sure it passes the correct ID.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_set_user_id() {
|
||||
$token = new \WC_Payment_Token_Stub( 1 );
|
||||
|
@ -82,9 +75,8 @@ class Payment_Token extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test getting the gateway ID
|
||||
*
|
||||
* @since 2.6
|
||||
* Test getting the gateway ID.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_get_gateway_id() {
|
||||
$token = new \WC_Payment_Token_Stub( 1, array( 'gateway_id' => 'paypal' ) );
|
||||
|
@ -92,9 +84,8 @@ class Payment_Token extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test set the gateway ID
|
||||
*
|
||||
* @since 2.6
|
||||
* Test set the gateway ID.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_set_gateway_id() {
|
||||
$token = new \WC_Payment_Token_Stub( 1 );
|
||||
|
@ -103,9 +94,8 @@ class Payment_Token extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test setting a token as default
|
||||
*
|
||||
* @since 2.6
|
||||
* Test setting a token as default.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_set_default() {
|
||||
$token = new \WC_Payment_Token_Stub( 1 );
|
||||
|
@ -116,9 +106,8 @@ class Payment_Token extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test is_default
|
||||
*
|
||||
* @since 2.6
|
||||
* Test is_default.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_is_default_returns_correct_state() {
|
||||
$token = new \WC_Payment_Token_Stub( 1, array( 'is_default' => true ) );
|
||||
|
@ -130,9 +119,8 @@ class Payment_Token extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test that get_data returns the correct internal representation for a token
|
||||
*
|
||||
* @since 2.6
|
||||
* Test that get_data returns the correct internal representation for a token.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_get_data() {
|
||||
$raw_token = time() . ' ' . __FUNCTION__;
|
||||
|
@ -151,9 +139,8 @@ class Payment_Token extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test token validation
|
||||
*
|
||||
* @since 2.6
|
||||
* Test token validation.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_validation() {
|
||||
$token = new \WC_Payment_Token_Stub( 1 );
|
||||
|
@ -165,9 +152,8 @@ class Payment_Token extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test reading a token from the database
|
||||
*
|
||||
* @since 2.6
|
||||
* Test reading a token from the database.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_read() {
|
||||
$token = \WC_Helper_Payment_Token::create_stub_token( __FUNCTION__ );
|
||||
|
@ -181,9 +167,8 @@ class Payment_Token extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test updating a token
|
||||
*
|
||||
* @since 2.6
|
||||
* Test updating a token.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_update() {
|
||||
$token = \WC_Helper_Payment_Token::create_stub_token( __FUNCTION__ );
|
||||
|
@ -194,9 +179,8 @@ class Payment_Token extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test creating a new token
|
||||
*
|
||||
* @since 2.6
|
||||
* Test creating a new token.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_create() {
|
||||
$token = new \WC_Payment_Token_Stub();
|
||||
|
@ -209,9 +193,8 @@ class Payment_Token extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test deleting a token
|
||||
*
|
||||
* @since 2.6
|
||||
* Test deleting a token.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_delete() {
|
||||
$token = \WC_Helper_Payment_Token::create_stub_token( __FUNCTION__ );
|
||||
|
@ -222,9 +205,8 @@ class Payment_Token extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test a meta function (like CC's last4) doesn't work on the core abstract class
|
||||
*
|
||||
* @since 2.6
|
||||
* Test a meta function (like CC's last4) doesn't work on the core abstract class.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function test_wc_payment_token_last4_doesnt_work() {
|
||||
$token = new \WC_Payment_Token_Stub();
|
||||
|
|
|
@ -8,9 +8,8 @@ namespace WooCommerce\Tests\Payment_Tokens;
|
|||
class Payment_Tokens extends \WC_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* Test getting tokens associated with an order
|
||||
*
|
||||
* @since 2.6
|
||||
* Test getting tokens associated with an order.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
function test_wc_payment_tokens_get_order_tokens() {
|
||||
$order = \WC_Helper_Order::create_order();
|
||||
|
@ -24,24 +23,51 @@ class Payment_Tokens extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test getting tokens associated with a user
|
||||
*
|
||||
* @since 2.6
|
||||
* Test getting tokens associated with a user and no gateway ID.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
function test_wc_payment_tokens_get_customer_token() {
|
||||
function test_wc_payment_tokens_get_customer_tokens_no_gateway() {
|
||||
$this->assertEmpty( \WC_Payment_Tokens::get_customer_tokens( 1 ) );
|
||||
|
||||
$token = \WC_Helper_Payment_Token::create_cc_token();
|
||||
$token->set_user_id( 1 );
|
||||
$token->save();
|
||||
|
||||
$this->assertCount( 1, \WC_Payment_Tokens::get_customer_tokens( 1 ) );
|
||||
$token = \WC_Helper_Payment_Token::create_cc_token();
|
||||
$token->set_user_id( 1 );
|
||||
$token->save();
|
||||
|
||||
$this->assertCount( 2, \WC_Payment_Tokens::get_customer_tokens( 1 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting a token by ID
|
||||
*
|
||||
* @since 2.6
|
||||
* Test getting tokens associated with a user and for a specific gateway.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
function test_wc_payment_tokens_get_customer_tokens_with_gateway() {
|
||||
$this->assertEmpty( \WC_Payment_Tokens::get_customer_tokens( 1 ) );
|
||||
|
||||
$token = \WC_Helper_Payment_Token::create_cc_token();
|
||||
$token->set_user_id( 1 );
|
||||
$token->set_gateway_id( 'simplify_commerce' );
|
||||
$token->save();
|
||||
|
||||
$token = \WC_Helper_Payment_Token::create_cc_token();
|
||||
$token->set_user_id( 1 );
|
||||
$token->set_gateway_id( 'paypal' );
|
||||
$token->save();
|
||||
|
||||
$this->assertCount( 2, \WC_Payment_Tokens::get_customer_tokens( 1 ) );
|
||||
$this->assertCount( 1, \WC_Payment_Tokens::get_customer_tokens( 1, 'simplify_commerce' ) );
|
||||
|
||||
foreach ( \WC_Payment_Tokens::get_customer_tokens( 1, 'simplify_commerce' ) as $simplify_token ) {
|
||||
$this->assertEquals( 'simplify_commerce', $simplify_token->get_gateway_id() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting a token by ID.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
function test_wc_payment_tokens_get() {
|
||||
$token = \WC_Helper_Payment_Token::create_cc_token();
|
||||
|
@ -51,9 +77,8 @@ class Payment_Tokens extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test deleting a token by ID
|
||||
*
|
||||
* @since 2.6
|
||||
* Test deleting a token by ID.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
function test_wc_payment_tokens_delete() {
|
||||
$token = \WC_Helper_Payment_Token::create_cc_token();
|
||||
|
@ -66,9 +91,8 @@ class Payment_Tokens extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test getting a token's type by ID
|
||||
*
|
||||
* @since 2.6
|
||||
* Test getting a token's type by ID.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
function test_wc_payment_tokens_get_type_by_id() {
|
||||
$token = \WC_Helper_Payment_Token::create_cc_token();
|
||||
|
@ -77,9 +101,8 @@ class Payment_Tokens extends \WC_Unit_Test_Case {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test setting a users default token
|
||||
*
|
||||
* @since 2.6
|
||||
* Test setting a users default token.
|
||||
* @since 2.6.0
|
||||
*/
|
||||
function test_wc_payment_tokens_set_users_default() {
|
||||
$token = \WC_Helper_Payment_Token::create_cc_token();
|
||||
|
|
|
@ -252,23 +252,25 @@ final class WooCommerce {
|
|||
include_once( 'includes/class-wc-tracker.php' );
|
||||
}
|
||||
|
||||
$this->query = include( 'includes/class-wc-query.php' ); // The main query class
|
||||
$this->api = include( 'includes/class-wc-api.php' ); // API Class
|
||||
$this->query = include( 'includes/class-wc-query.php' ); // The main query class
|
||||
$this->api = include( 'includes/class-wc-api.php' ); // API Class
|
||||
|
||||
include_once( 'includes/class-wc-auth.php' ); // Auth Class
|
||||
include_once( 'includes/class-wc-post-types.php' ); // Registers post types
|
||||
include_once( 'includes/abstracts/abstract-wc-payment-token.php' ); // Payment Tokens
|
||||
include_once( 'includes/abstracts/abstract-wc-product.php' ); // Products
|
||||
include_once( 'includes/abstracts/abstract-wc-order.php' ); // Orders
|
||||
include_once( 'includes/abstracts/abstract-wc-settings-api.php' ); // Settings API (for gateways, shipping, and integrations)
|
||||
include_once( 'includes/abstracts/abstract-wc-shipping-method.php' ); // A Shipping method
|
||||
include_once( 'includes/abstracts/abstract-wc-payment-gateway.php' ); // A Payment gateway
|
||||
include_once( 'includes/abstracts/abstract-wc-integration.php' ); // An integration with a service
|
||||
include_once( 'includes/class-wc-product-factory.php' ); // Product factory
|
||||
include_once( 'includes/class-wc-payment-tokens.php' ); // Payment tokens controller
|
||||
include_once( 'includes/class-wc-countries.php' ); // Defines countries and states
|
||||
include_once( 'includes/class-wc-integrations.php' ); // Loads integrations
|
||||
include_once( 'includes/class-wc-cache-helper.php' ); // Cache Helper
|
||||
include_once( 'includes/class-wc-auth.php' ); // Auth Class
|
||||
include_once( 'includes/class-wc-post-types.php' ); // Registers post types
|
||||
include_once( 'includes/abstracts/abstract-wc-payment-token.php' ); // Payment Tokens
|
||||
include_once( 'includes/abstracts/abstract-wc-product.php' ); // Products
|
||||
include_once( 'includes/abstracts/abstract-wc-order.php' ); // Orders
|
||||
include_once( 'includes/abstracts/abstract-wc-settings-api.php' ); // Settings API (for gateways, shipping, and integrations)
|
||||
include_once( 'includes/abstracts/abstract-wc-shipping-method.php' ); // A Shipping method
|
||||
include_once( 'includes/abstracts/abstract-wc-payment-gateway.php' ); // A Payment gateway
|
||||
include_once( 'includes/abstracts/abstract-wc-integration.php' ); // An integration with a service
|
||||
include_once( 'includes/class-wc-product-factory.php' ); // Product factory
|
||||
include_once( 'includes/class-wc-payment-tokens.php' ); // Payment tokens controller
|
||||
include_once( 'includes/gateways/class-wc-payment-gateway-cc.php' ); // CC Payment Gateway
|
||||
include_once( 'includes/gateways/class-wc-payment-gateway-echeck.php' ); // eCheck Payment Gateway
|
||||
include_once( 'includes/class-wc-countries.php' ); // Defines countries and states
|
||||
include_once( 'includes/class-wc-integrations.php' ); // Loads integrations
|
||||
include_once( 'includes/class-wc-cache-helper.php' ); // Cache Helper
|
||||
|
||||
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
||||
include_once( 'includes/class-wc-cli.php' );
|
||||
|
|
Loading…
Reference in New Issue