Untitled

mail@pastecode.io avatar
unknown
java
7 months ago
2.8 kB
4
Indexable
Never
public static String getTransferAmount(String transactionDetails, String transactionType) throws JsonProcessingException {
        TypeReference<Map<String, String>> typeReference = new TypeReference<Map<String, String>>() {
        };
        Map<String, String> map = mapper.readValue(transactionDetails, typeReference);
        Optional<String> transferAmounts;
        Optional<String> currency;
        switch (transactionType) {
            case ASBN_TOPUP_SUBCRIPTION, FPX_PAYMENT, "DuitNow":
                transferAmounts = Optional.ofNullable(map.values().stream().filter(val -> StringUtils.containsIgnoreCase(val, "Transfer Amount")).findFirst().orElse("-|-").split("\\|")[1]);
                currency = Optional.ofNullable(map.values().stream().filter(val -> StringUtils.containsIgnoreCase(val, FROM_ACCOUNT)).findFirst().orElse(CURRENCY_ELSE).split("\\|")[1].split(" ")[4]);
                break;
            case "DuitNow Request Authorization":
                transferAmounts = Optional.ofNullable(map.values().stream().filter(val -> StringUtils.containsIgnoreCase(val, "Request Amount")).findFirst().orElse("-|-").split("\\|")[1]);
                currency = Optional.ofNullable(map.values().stream().filter(val -> StringUtils.containsIgnoreCase(val, "Paying Account")).findFirst().orElse(CURRENCY_ELSE).split("\\|")[1].split(" ")[4]);
                break;
            case "DuitNow AutoDebit Registration":
                transferAmounts = Optional.ofNullable(map.values().stream().filter(val -> StringUtils.containsIgnoreCase(val, "Maximum Payment Amount")).findFirst().orElse("-|-").split("\\|")[1]);
                currency = Optional.ofNullable(map.values().stream().filter(val -> StringUtils.containsIgnoreCase(val, "duitNow.consent.register.fromAccount.label")).findFirst().orElse(CURRENCY_ELSE).split("\\|")[1].split(" ")[4]);
                break;
            case "Investment Withdrawal":
                transferAmounts = Optional.ofNullable(map.values().stream().filter(val -> StringUtils.containsIgnoreCase(val, "Amount")).findFirst().orElse("-|-").split("\\|")[1]);
                currency = Optional.of("MYR");
                break;
            case "Account Opening", "Bill Presentment":
                transferAmounts = Optional.ofNullable(map.values().stream().filter(val -> StringUtils.containsIgnoreCase(val, "Amount")).findFirst().orElse("-|-").split("\\|")[1]);
                currency = Optional.ofNullable(map.values().stream().filter(val -> StringUtils.containsIgnoreCase(val, FROM_ACCOUNT)).findFirst().orElse(CURRENCY_ELSE).split("\\|")[1].split(" ")[4]);
                break;
            default:
                currency = Optional.of("-");
                transferAmounts = Optional.of("-");
        }
        return currency.orElse("-") + " " + transferAmounts.orElse("-");
    }
Leave a Comment