completed initial charge logic

This commit is contained in:
2025-06-18 09:28:01 +02:00
parent b214d42d2f
commit 9ae78635c7
34 changed files with 614 additions and 102 deletions

View File

@@ -0,0 +1,83 @@
package zw.qantra.tm.domain.controllers;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zw.qantra.tm.domain.enums.ChargeConditionType;
import zw.qantra.tm.domain.enums.ChargeLabelEnum;
import zw.qantra.tm.domain.enums.CurrencyType;
import zw.qantra.tm.domain.models.Charge;
import zw.qantra.tm.domain.models.ChargeCondition;
import zw.qantra.tm.domain.services.ChargeConditionService;
import zw.qantra.tm.domain.services.ChargeService;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
@RestController
@RequestMapping("/configs")
@RequiredArgsConstructor
public class ConfigController {
private final ChargeConditionService chargeConditionService;
private final ChargeService chargeService;
@GetMapping("/charges")
public ResponseEntity charges(){
List<ChargeCondition> chargeConditions = Arrays.asList(
ChargeCondition.builder()
.name("Ecocash Gateway")
.type(ChargeConditionType.GATEWAY)
.codes("ECOCASH")
.build(),
ChargeCondition.builder()
.name("Steward Gateway")
.type(ChargeConditionType.GATEWAY)
.codes("STEWARD")
.build(),
ChargeCondition.builder()
.name("Mastercard Gateway")
.type(ChargeConditionType.GATEWAY)
.codes("MPGS")
.build()
);
chargeService.getChargeRepository().deleteAll();
chargeConditionService.getChargeConditionRepository().deleteAll();
chargeConditionService.getChargeConditionRepository().saveAll(chargeConditions);
List<Charge> charges = Arrays.asList(
Charge.builder()
.description("Gateway fee")
.chargeLabel(ChargeLabelEnum.GATEWAY_FEE)
.currency(CurrencyType.USD)
.percentageRate(new BigDecimal("1"))
.includes(new HashSet<>() {{
add(chargeConditions.get(0));
add(chargeConditions.get(1));
add(chargeConditions.get(2));
}})
.build(),
Charge.builder()
.description("Tax")
.chargeLabel(ChargeLabelEnum.TAX)
.currency(CurrencyType.USD)
.percentageRate(new BigDecimal("2"))
.max(new BigDecimal("10150"))
.minimumAmount(new BigDecimal("5"))
.maximumAmount(new BigDecimal("500000"))
.includes(new HashSet<>() {{
add(chargeConditions.get(0));
add(chargeConditions.get(1));
add(chargeConditions.get(2));
}})
.build()
);
chargeService.getChargeRepository().saveAll(charges);
return ResponseEntity.ok("Charges configuration complete");
}
}