get_type() public method

Returns the type of this payment token (CC, eCheck, or something else).
Since: 2.6.0
public get_type ( string $context = 'view' ) : string
$context string
return string Payment Token Type (CC, eCheck)
コード例 #1
1
/**
 * Controls the output for eChecks on the my account page.
 *
 * @since 2.6
 * @param  array             $item         Individual list item from woocommerce_saved_payment_methods_list
 * @param  WC_Payment_Token $payment_token The payment token associated with this method entry
 * @return array                           Filtered item
 */
function wc_get_account_saved_payment_methods_list_item_echeck($item, $payment_token)
{
    if ('echeck' !== strtolower($payment_token->get_type())) {
        return $item;
    }
    $item['method']['last4'] = $payment_token->get_last4();
    $item['method']['brand'] = esc_html__('eCheck', 'woocommerce');
    return $item;
}
コード例 #2
1
 /**
  * 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__(wc_get_credit_card_type_label($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);
 }
コード例 #3
0
 /**
  * Update a payment token.
  *
  * @since 2.7.0
  * @param WC_Payment_Token $token
  */
 public function update(&$token)
 {
     if (false === $token->validate()) {
         throw new Exception(__('Invalid or missing payment token fields.', 'woocommerce'));
     }
     global $wpdb;
     $payment_token_data = array('gateway_id' => $token->get_gateway_id('edit'), 'token' => $token->get_token('edit'), 'user_id' => $token->get_user_id('edit'), 'type' => $token->get_type('edit'));
     $wpdb->update($wpdb->prefix . 'woocommerce_payment_tokens', $payment_token_data, array('token_id' => $token->get_id('edit')));
     $token->save_meta_data();
     $token->apply_changes();
     // Make sure all other tokens are not set to default
     if ($token->is_default() && $token->get_user_id() > 0) {
         WC_Payment_Tokens::set_users_default($token->get_user_id(), $token->get_id());
     }
     do_action('woocommerce_payment_token_updated', $token->get_id());
 }