/**
  * Make a card as default method
  */
 public function default_card()
 {
     if (!isset($_POST['stripe_default_card']) || !is_account_page()) {
         return;
     }
     $stripe_customer = new WC_Stripe_Customer(get_current_user_id());
     $stripe_customer_id = $stripe_customer->get_id();
     $default_source = sanitize_text_field($_POST['stripe_default_card']);
     if (!is_user_logged_in() || !$stripe_customer_id || !wp_verify_nonce($_POST['_wpnonce'], "stripe_default_card")) {
         wp_die(__('Unable to make default card, please try again', 'woocommerce-gateway-stripe'));
     }
     if (!$stripe_customer->set_default_card($default_source)) {
         wc_add_notice(__('Unable to update default card.', 'woocommerce-gateway-stripe'), 'error');
     } else {
         wc_add_notice(__('Default card updated.', 'woocommerce-gateway-stripe'), 'success');
     }
 }
 /**
  * Get payment source from an order. This could be used in the future for
  * a subscription as an example, therefore using the current user ID would
  * not work - the customer won't be logged in :)
  *
  * Not using 2.6 tokens for this part since we need a customer AND a card
  * token, and not just one.
  *
  * @param object $order
  * @return object
  */
 protected function get_order_source($order = null)
 {
     $stripe_customer = new WC_Stripe_Customer();
     $stripe_source = false;
     $token_id = false;
     if ($order) {
         if ($meta_value = get_post_meta($order->id, '_stripe_customer_id', true)) {
             $stripe_customer->set_id($meta_value);
         }
         if ($meta_value = get_post_meta($order->id, '_stripe_card_id', true)) {
             $stripe_source = $meta_value;
         }
     }
     return (object) array('token_id' => $token_id, 'customer' => $stripe_customer ? $stripe_customer->get_id() : false, 'source' => $stripe_source);
 }