|null */ private static $installed = null; /** * Name for a payment method ID. * * @param string $id Gateway ID. Empty means manual renewal. * @param string $fallback Title recorded on the subscription, used when the gateway is not installed. * @return string */ public static function name( $id, $fallback = '' ) { $id = (string) $id; if ( '' === $id ) { return __( 'None (manual renewal)', 'recast-subscriptions' ); } if ( null === self::$installed ) { self::$installed = function_exists( 'WC' ) ? WC()->payment_gateways()->payment_gateways() : array(); } if ( isset( self::$installed[ $id ] ) ) { $title = (string) self::$installed[ $id ]->get_method_title(); if ( '' !== $title ) { return $title; } } if ( '' !== (string) $fallback ) { /* translators: %s: payment method name or ID */ return sprintf( __( '%s (not installed)', 'recast-subscriptions' ), $fallback ); } /* translators: %s: payment method name or ID */ return sprintf( __( '%s (not installed)', 'recast-subscriptions' ), $id ); } /** * Whether renewals can be charged through a gateway: installed and turned on. * * @param string $id Gateway ID. * @return bool */ public static function is_available( $id ) { if ( null === self::$installed ) { self::$installed = function_exists( 'WC' ) ? WC()->payment_gateways()->payment_gateways() : array(); } return isset( self::$installed[ $id ] ) && 'yes' === self::$installed[ $id ]->enabled; } /** * Whether an installed gateway supports a feature, such as "subscriptions". * * @param string $id Gateway ID. * @param string $feature Feature. * @return bool */ public static function supports( $id, $feature ) { if ( null === self::$installed ) { self::$installed = function_exists( 'WC' ) ? WC()->payment_gateways()->payment_gateways() : array(); } return isset( self::$installed[ $id ] ) && self::$installed[ $id ]->supports( $feature ); } }