class PaymentUtils {

    @Nullable
    static Long getTotalPrice(@NonNull Collection<LineItem> lineItems,
                                      @NonNull Currency currency) {
        Long totalPrice = null;
        for (LineItem lineItem : lineItems) {
            if (!currency.getCurrencyCode().equals(lineItem.getCurrencyCode())) {
                return null;
            }

            Long itemPrice = getPriceLong(lineItem.getTotalPrice(), currency);
            if (itemPrice != null) {
                if (totalPrice == null) {
                    totalPrice = itemPrice;
                } else {
                    totalPrice += itemPrice;
                }
            }
        }

        // In this case, the values were simply all empty, not invalid. The total price is zero.
        if (totalPrice == null) {
            return 0L;
        }

        return totalPrice;
    }

}