class PaymentUtils {

    public static CartError searchLineItemForErrors(LineItem lineItem) {
        if (lineItem == null) {
            return null;
        }

        if (!matchesCurrencyPatternOrEmpty(lineItem.getUnitPrice())) {
            return new CartError(CartError.LINE_ITEM_PRICE,
                    String.format(Locale.ENGLISH,
                            "Invalid price string: %s does not match required pattern of %s",
                            lineItem.getUnitPrice(),
                            CURRENCY_REGEX),
                    lineItem);
        }

        if (!matchesQuantityPatternOrEmpty(lineItem.getQuantity())) {
            return new CartError(CartError.LINE_ITEM_QUANTITY,
                    String.format(Locale.ENGLISH,
                            "Invalid quantity string: %s does not match required pattern of %s",
                            lineItem.getQuantity(),
                            QUANTITY_REGEX),
                    lineItem);
        }

        if (!matchesCurrencyPatternOrEmpty(lineItem.getTotalPrice())) {
            return new CartError(CartError.LINE_ITEM_PRICE,
                    String.format(Locale.ENGLISH,
                            "Invalid price string: %s does not match required pattern of %s",
                            lineItem.getTotalPrice(),
                            CURRENCY_REGEX),
                    lineItem);
        }

        return null;
    }

}