autoship_filter_saved_methods()

(src/payments.php) Takes an array of saved payment methods as an argument and returns the autoship cloud supported methods that have active payment gateways for the site.

Function:

/**
 * Returns the filtered version of the supplied saved payment methods.
 *
 * @param array $methods An array of saved customer payment methods
 * @return array The valid supported saved methods
 */
function autoship_filter_saved_methods( $methods ){

  // If there are no saved methods or no credit card saved methods
  if ( empty( $methods ) || !isset( $methods['cc'] ) )
  return array();

  $valid_methods = array();

  // Get the current valid gateways
  $valid_gateways = autoship_get_available_valid_gateways();

  foreach ($methods['cc'] as $key => $method) {

    if ( isset( $valid_gateways[$method['method']['gateway']] ) )
    $valid_methods['cc'][$key] = $method;

  }

  // Return only valid saved methods
  return $valid_methods;

}