class PaymentUtils {

    @Nullable
    static Long getPriceLong(@Nullable String price, @NonNull Currency currency) {
        if (TextUtils.isEmpty(price)) {
            return null;
        }

        if (!matchesCurrencyPatternOrEmpty(price)) {
            throw new IllegalArgumentException(String.format(Locale.ENGLISH,
                    "%s is not a valid price String for a LineItem", price));
        }

        int fractionDigits = currency.getDefaultFractionDigits();
        if (fractionDigits == 0) {
            return Long.parseLong(price);
        }


        // This is the case where the currency has a decimal, but our price does not.
        // For instance if the currency was USD and the price string was "2", we want to return
        // 200L, not 2L.
        if (!price.contains(".")) {
            long multiplier = (long) Math.pow(10, fractionDigits);
            long displayNumber = Long.parseLong(price);
            return displayNumber * multiplier;
        }

        String noDecimal = price.replace(".", "");
        return Long.parseLong(noDecimal);
    }

}