public static function maxExcessCapturePercent($gateway)
    {
        $setting = self::getConfigSetting($gateway, 'max_capture');
        if (!$setting) {
            return 0;
        }

        $pattern = '/^(\d+)%$/';

        if (!is_array($setting)) {
            if (preg_match($pattern, $setting, $match)) {
                return $match[1];
            }

            if (is_numeric($setting) && $setting > 0) {
                return -1;
            }
        } elseif (!empty($setting['percent'])) {
            if (is_numeric($setting['percent'])) {
                return max(0, $setting['percent']);
            }

            if (preg_match($pattern, $setting['percent'], $match)) {
                return $match[1];
            }
        }

        return 0;
    }