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

        if (!is_array($setting)) {
            if (preg_match('/^\d+%$/', $setting)) {
                return -1;
            }

            if (is_numeric($setting)) {
                return max(0, $setting);
            }
        } elseif (!empty($setting['amount'])) {
            if (is_numeric($setting['amount'])) {
                return max(0, $setting['amount']);
            }

            if (is_array($setting['amount'])
                && $currency
                && !empty($setting['amount'][$currency])
                && is_numeric($setting['amount'][$currency])
            ) {
                return max(0, $setting['amount'][$currency]);
            }
        }

        return 0;
    }