/**
  * Render the payment method used for a subscription in the "My Subscriptions" table
  *
  * @since 4.1.0
  * @param string $payment_method_to_display the default payment method text to display
  * @param \WC_Subscription $subscription
  * @return string the subscription payment method
  */
 public function maybe_render_payment_method($payment_method_to_display, $subscription)
 {
     // bail for other payment methods
     if ($this->get_gateway()->get_id() !== $subscription->payment_method) {
         return $payment_method_to_display;
     }
     $token = $this->get_gateway()->get_payment_tokens_handler()->get_token($subscription->get_user_id(), $this->get_gateway()->get_order_meta($subscription->id, 'payment_token'));
     if ($token instanceof SV_WC_Payment_Gateway_Payment_Token) {
         $payment_method_to_display = sprintf(__('Via %s ending in %s', 'woocommerce-plugin-framework'), $token->get_type_full(), $token->get_last_four());
     }
     return $payment_method_to_display;
 }
 /**
  * Render the payment method used for a subscription in the "My Subscriptions" table
  *
  * @since 4.1.0
  * @param string $payment_method_to_display the default payment method text to display
  * @param \WC_Subscription $subscription
  * @return string the subscription payment method
  */
 public function maybe_render_payment_method($payment_method_to_display, $subscription)
 {
     // bail for other payment methods
     if ($this->get_gateway()->get_id() !== $subscription->payment_method) {
         return $payment_method_to_display;
     }
     $token = $this->get_gateway()->get_payment_token($subscription->get_user_id(), $this->get_gateway()->get_order_meta($subscription->id, 'payment_token'));
     if ($token instanceof SV_WC_Payment_Gateway_Payment_Token) {
         $payment_method_to_display = sprintf(_x('Via %s ending in %s', 'Supports direct payment method subscriptions', $this->get_gateway()->get_text_domain()), $token->get_type_full(), $token->get_last_four());
     }
     return $payment_method_to_display;
 }
 /**
  * Because the upgrader may have attempted to set an invalid end date on the subscription, it could
  * lead to the entire date update process failing, which would mean that a next payment date would
  * not be set even when one existed.
  *
  * This method checks if a given subscription has no next payment date, and if it doesn't, it checks
  * if one was previously scheduled for the old subscription. If one was, and that date is in the future,
  * it will pass that date back for being set on the subscription. If a date was scheduled but that is now
  * in the past, it will recalculate it.
  *
  * @param  WC_Subscription $subscription the subscription to check
  * @return string|bool false if the date does not need to be repaired or the new date if it should be repaired
  */
 protected static function check_next_payment_date($subscription)
 {
     global $wpdb;
     // the subscription doesn't have a next payment date set, let's see if it should
     if (0 == $subscription->get_time('next_payment') && $subscription->has_status('active')) {
         $old_hook_args = array('user_id' => (int) $subscription->get_user_id(), 'subscription_key' => wcs_get_old_subscription_key($subscription));
         // get the latest scheduled subscription payment in v1.5
         $old_next_payment_date = $wpdb->get_var($wpdb->prepare("SELECT post_date_gmt FROM {$wpdb->posts}\n\t\t\t\t WHERE post_type = %s\n\t\t\t\t AND post_content = %s\n\t\t\t\t AND post_title = 'scheduled_subscription_payment'\n\t\t\t\t ORDER BY post_date_gmt DESC", ActionScheduler_wpPostStore::POST_TYPE, wcs_json_encode($old_hook_args)));
         WCS_Upgrade_Logger::add(sprintf('For subscription %d: new next payment date = %s.', $subscription->id, var_export($subscription->get_date('next_payment'), true)));
         WCS_Upgrade_Logger::add(sprintf('For subscription %d: old next payment date = %s.', $subscription->id, var_export($old_next_payment_date, true)));
         // if we have a date, make sure it's valid
         if (null !== $old_next_payment_date) {
             if (strtotime($old_next_payment_date) <= gmdate('U')) {
                 $repair_date = $subscription->calculate_date('next_payment');
                 if (0 == $repair_date) {
                     $repair_date = false;
                 }
                 WCS_Upgrade_Logger::add(sprintf('For subscription %d: old next payment date is in the past, setting it to %s.', $subscription->id, var_export($repair_date, true)));
             } else {
                 $repair_date = $old_next_payment_date;
             }
         } else {
             // let's just double check we shouldn't have a date set by recalculating it
             $calculated_next_payment_date = $subscription->calculate_date('next_payment');
             if (0 != $calculated_next_payment_date && strtotime($calculated_next_payment_date) > gmdate('U')) {
                 $repair_date = $calculated_next_payment_date;
             } else {
                 $repair_date = false;
             }
             WCS_Upgrade_Logger::add(sprintf('For subscription %d: no old next payment date, setting it to %s.', $subscription->id, var_export($repair_date, true)));
         }
     } else {
         $repair_date = false;
     }
     WCS_Upgrade_Logger::add(sprintf('For subscription %d: repair next payment date = %s.', $subscription->id, var_export($repair_date, true)));
     return $repair_date;
 }