/**
  * Add a payment token to an order
  *
  * @since 2.6
  * @param  WC_Payment_Token   $token     Payment token object
  * @return boolean|int The new token ID or false if it failed.
  */
 public function add_payment_token($token)
 {
     if (empty($token) || !$token instanceof WC_Payment_Token) {
         return false;
     }
     $token_ids = get_post_meta($this->get_id(), '_payment_tokens', true);
     if (empty($token_ids)) {
         $token_ids = array();
     }
     $token_ids[] = $token->get_id();
     update_post_meta($this->get_id(), '_payment_tokens', $token_ids);
     do_action('woocommerce_payment_token_added_to_order', $this->get_id(), $token->get_id(), $token, $token_ids);
     return $token->get_id();
 }
 /**
  * Read a token from the database.
  *
  * @since 2.7.0
  * @param WC_Payment_Token $token
  */
 public function read(&$token)
 {
     global $wpdb;
     if ($data = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}woocommerce_payment_tokens WHERE token_id = %d LIMIT 1;", $token->get_id()))) {
         $token->set_props(array('token' => $data->token, 'user_id' => $data->user_id, 'gateway_id' => $data->gateway_id, 'default' => $data->is_default));
         $token->read_meta_data();
         $token->set_object_read(true);
         do_action('woocommerce_payment_token_loaded', $token);
     } else {
         throw new Exception(__('Invalid payment token.', 'woocommerce'));
     }
 }
 /**
  * Add a payment token to an order
  *
  * @since 2.6
  * @param  WC_Payment_Token   $token     Payment token object
  * @return boolean|int The new token ID or false if it failed.
  */
 public function add_payment_token($token)
 {
     if (empty($token) || !$token instanceof WC_Payment_Token) {
         return false;
     }
     $token_ids = $this->data_store->get_payment_token_ids($this);
     $token_ids[] = $token->get_id();
     $this->data_store->update_payment_token_ids($this, $token_ids);
     do_action('woocommerce_payment_token_added_to_order', $this->get_id(), $token->get_id(), $token, $token_ids);
     return $token->get_id();
 }
    /**
     * Gets saved payment method HTML from a token.
     * @since 2.6.0
     * @param  WC_Payment_Token $token Payment Token
     * @return string                  Generated payment method HTML
     */
    public function get_saved_payment_method_option_html($token)
    {
        $html = sprintf('<li class="woocommerce-SavedPaymentMethods-token">
				<input id="wc-%1$s-payment-token-%2$s" type="radio" name="wc-%1$s-payment-token" value="%2$s" style="width:auto;" class="woocommerce-SavedPaymentMethods-tokenInput" %4$s />
				<label for="wc-%1$s-payment-token-%2$s">%3$s</label>
			</li>', esc_attr($this->id), esc_attr($token->get_id()), esc_html($token->get_display_name()), checked($token->is_default(), true, false));
        return apply_filters('woocommerce_payment_gateway_get_saved_payment_method_option_html', $html, $token, $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);
 }