@Test public void getPriceLong_whenNonDecimalValueGivenInDecimalCurrency_correctlyMovesUpResult() { assertEquals(Long.valueOf(1000L), getPriceLong("10", Currency.getInstance("USD"))); assertEquals(Long.valueOf(30000L), getPriceLong("30", Currency.getInstance("OMR"))); }
@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); } 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); }
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); } 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); } }
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); } 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); }  }
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); } 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); }  static boolean matchesCurrencyPatternOrEmpty(@Nullable String priceString); static boolean matchesQuantityPatternOrEmpty(@Nullable String quantityString); @NonNull static List<CartError> validateLineItemList(
            List<LineItem> lineItems,
            @NonNull String currencyCode); static CartError searchLineItemForErrors(LineItem lineItem); @NonNull static String getPriceString(long price); @NonNull static List<CartError> removeErrorType(
            @NonNull List<CartError> errors,
            @NonNull @CartError.CartErrorType String errorType); @NonNull static String getPriceString(Long price, @NonNull Currency currency); static IsReadyToPayRequest getStripeIsReadyToPayRequest(); }
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); } 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); }  static boolean matchesCurrencyPatternOrEmpty(@Nullable String priceString); static boolean matchesQuantityPatternOrEmpty(@Nullable String quantityString); @NonNull static List<CartError> validateLineItemList(
            List<LineItem> lineItems,
            @NonNull String currencyCode); static CartError searchLineItemForErrors(LineItem lineItem); @NonNull static String getPriceString(long price); @NonNull static List<CartError> removeErrorType(
            @NonNull List<CartError> errors,
            @NonNull @CartError.CartErrorType String errorType); @NonNull static String getPriceString(Long price, @NonNull Currency currency); static IsReadyToPayRequest getStripeIsReadyToPayRequest();  }