diff --git a/.gitignore b/.gitignore index 001eafd..f231909 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ build/ .vscode/ logs/ data/ +reports/ \ No newline at end of file diff --git a/src/main/java/zw/qantra/tm/domain/controllers/GroupBatchController.java b/src/main/java/zw/qantra/tm/domain/controllers/GroupBatchController.java index 17c49e6..dc8b8f4 100644 --- a/src/main/java/zw/qantra/tm/domain/controllers/GroupBatchController.java +++ b/src/main/java/zw/qantra/tm/domain/controllers/GroupBatchController.java @@ -9,6 +9,7 @@ import org.springframework.data.jpa.domain.Specification; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import zw.qantra.tm.domain.dtos.GroupBatchCreateRequest; +import zw.qantra.tm.domain.dtos.GroupBatchItemUpdateRequest; import zw.qantra.tm.domain.dtos.GroupBatchUpdateRequest; import zw.qantra.tm.domain.dtos.GroupBatchTriggerRequest; import zw.qantra.tm.domain.models.GroupBatch; @@ -16,6 +17,7 @@ import zw.qantra.tm.domain.models.GroupBatchItem; import zw.qantra.tm.domain.services.BatchReportService; import zw.qantra.tm.domain.services.GroupBatchService; +import java.util.List; import java.util.Map; import java.util.UUID; @@ -93,6 +95,16 @@ public class GroupBatchController { return ResponseEntity.ok(groupBatchService.getBatchItems(spec, pageable)); } + @PutMapping("/{batchId}/items") + public ResponseEntity> updateBatchItems( + @PathVariable UUID batchId, + @RequestBody GroupBatchItemUpdateRequest.ListWrapper wrapper) { + return ResponseEntity.ok(groupBatchService.updateBatchItems( + batchId, + wrapper.getUserId(), + wrapper.getItems())); + } + @DeleteMapping("/{batchId}") public ResponseEntity deleteBatch(@PathVariable UUID batchId, @RequestParam String userId) { diff --git a/src/main/java/zw/qantra/tm/domain/dtos/GroupBatchItemUpdateRequest.java b/src/main/java/zw/qantra/tm/domain/dtos/GroupBatchItemUpdateRequest.java new file mode 100644 index 0000000..0d155ff --- /dev/null +++ b/src/main/java/zw/qantra/tm/domain/dtos/GroupBatchItemUpdateRequest.java @@ -0,0 +1,29 @@ +package zw.qantra.tm.domain.dtos; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.List; +import java.util.UUID; + +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class GroupBatchItemUpdateRequest { + private UUID id; + private BigDecimal amount; + private String recipientName; + private String recipientPhone; + private String billClientId; + private String billName; + private String billProductName; + private String providerImage; + private String providerLabel; + + @Data + @JsonInclude(JsonInclude.Include.NON_NULL) + public static class ListWrapper { + private List items; + private String userId; + } +} \ No newline at end of file diff --git a/src/main/java/zw/qantra/tm/domain/models/GroupBatchItem.java b/src/main/java/zw/qantra/tm/domain/models/GroupBatchItem.java index f114d8f..b10b524 100644 --- a/src/main/java/zw/qantra/tm/domain/models/GroupBatchItem.java +++ b/src/main/java/zw/qantra/tm/domain/models/GroupBatchItem.java @@ -58,5 +58,11 @@ public class GroupBatchItem extends BaseEntity { @ManyToOne @JoinColumn(name = "transaction_id") private Transaction transaction; + + private String billClientId; + private String billName; + private String billProductName; + private String providerImage; + private String providerLabel; } diff --git a/src/main/java/zw/qantra/tm/domain/models/Provider.java b/src/main/java/zw/qantra/tm/domain/models/Provider.java index 88ed560..e4d0a78 100644 --- a/src/main/java/zw/qantra/tm/domain/models/Provider.java +++ b/src/main/java/zw/qantra/tm/domain/models/Provider.java @@ -34,6 +34,7 @@ public class Provider extends BaseEntity { private Boolean requiresAmount; private Boolean requiresPhone; private Boolean requiresAccount; + private Boolean requiresProducts; private double percentageCommission; @Column(columnDefinition = "TEXT") private String meta; diff --git a/src/main/java/zw/qantra/tm/domain/models/Transaction.java b/src/main/java/zw/qantra/tm/domain/models/Transaction.java index bf43a90..0aa6164 100644 --- a/src/main/java/zw/qantra/tm/domain/models/Transaction.java +++ b/src/main/java/zw/qantra/tm/domain/models/Transaction.java @@ -81,6 +81,7 @@ public class Transaction extends BaseEntity { private String paymentProcessorName; private String providerImage; private String paymentProcessorImage; + private UUID batchId; @Enumerated(EnumType.STRING) private Status authorizationStatus; diff --git a/src/main/java/zw/qantra/tm/domain/services/GroupBatchService.java b/src/main/java/zw/qantra/tm/domain/services/GroupBatchService.java index 20aa6f1..6a039b0 100644 --- a/src/main/java/zw/qantra/tm/domain/services/GroupBatchService.java +++ b/src/main/java/zw/qantra/tm/domain/services/GroupBatchService.java @@ -13,6 +13,7 @@ import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import zw.qantra.tm.domain.dtos.GroupBatchCreateRequest; +import zw.qantra.tm.domain.dtos.GroupBatchItemUpdateRequest; import zw.qantra.tm.domain.dtos.GroupBatchUpdateRequest; import zw.qantra.tm.domain.dtos.StateResponse; import zw.qantra.tm.domain.enums.AuthType; @@ -30,10 +31,13 @@ import zw.qantra.tm.exceptions.ApiException; import zw.qantra.tm.utils.Utils; import java.math.BigDecimal; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.stream.Collectors; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; @@ -43,7 +47,8 @@ public class GroupBatchService { private static final String BATCH_WORKFLOW_TYPE = "batchWorkflow"; private static final Set UPDATABLE_STATUSES = Set.of( - GroupBatchStatus.CREATED + GroupBatchStatus.CREATED, + GroupBatchStatus.CONFIRM_FAILED ); private static final Set DELETABLE_STATUSES = Set.of( @@ -74,9 +79,6 @@ public class GroupBatchService { if (members.isEmpty()) { throw new ApiException("Recipient group has no members"); } - if (request.getTransactionTemplate() == null) { - throw new ApiException("transactionTemplate is required"); - } GroupBatch batch = GroupBatch.builder() .recipientGroupId(group.getId()) @@ -327,6 +329,77 @@ public class GroupBatchService { return groupBatchRepository.save(batch); } + @Transactional + public List updateBatchItems(UUID batchId, String userId, + List items) { + GroupBatch batch = getBatch(batchId, userId); + + if (!UPDATABLE_STATUSES.contains(batch.getStatus())) { + throw new ApiException( + "Batch items cannot be updated at current status: " + batch.getStatus() + + ". Only batches in CREATED status can have items updated." + ); + } + + List existingItems = groupBatchItemRepository.findAllByGroupBatchId(batchId); + Map itemMap = existingItems.stream() + .collect(Collectors.toMap(GroupBatchItem::getId, item -> item)); + + List updatedItems = new ArrayList<>(); + + for (GroupBatchItemUpdateRequest update : items) { + if (update.getId() == null) { + throw new ApiException("Item id is required for each item update"); + } + + GroupBatchItem item = itemMap.get(update.getId()); + if (item == null) { + throw new ApiException("Group batch item not found: " + update.getId()); + } + + if (update.getAmount() != null) { + item.setAmount(update.getAmount()); + } + if (update.getRecipientName() != null) { + item.setRecipientName(update.getRecipientName()); + } + if (update.getRecipientPhone() != null) { + item.setRecipientPhone(update.getRecipientPhone()); + } + if (update.getBillClientId() != null) { + item.setBillClientId(update.getBillClientId()); + } + if (update.getBillName() != null) { + item.setBillName(update.getBillName()); + } + if (update.getBillProductName() != null) { + item.setBillProductName(update.getBillProductName()); + } + if (update.getProviderImage() != null) { + item.setProviderImage(update.getProviderImage()); + } + if (update.getProviderLabel() != null) { + item.setProviderLabel(update.getProviderLabel()); + } + + updatedItems.add(groupBatchItemRepository.save(item)); + } + + // Recalculate batch totals if any amount changed + boolean amountChanged = items.stream().anyMatch(u -> u.getAmount() != null); + if (amountChanged) { + List allItems = groupBatchItemRepository.findAllByGroupBatchId(batchId); + BigDecimal newTotalValue = allItems.stream() + .map(GroupBatchItem::getAmount) + .reduce(BigDecimal.ZERO, BigDecimal::add); + batch.setValue(newTotalValue); + batch.setCount(allItems.size()); + groupBatchRepository.save(batch); + } + + return updatedItems; + } + @Transactional public void deleteBatch(UUID batchId, String userId) { GroupBatch batch = getBatch(batchId, userId); diff --git a/src/main/java/zw/qantra/tm/domain/services/GroupBatchWorkflowService.java b/src/main/java/zw/qantra/tm/domain/services/GroupBatchWorkflowService.java index e83ea74..97bfa50 100644 --- a/src/main/java/zw/qantra/tm/domain/services/GroupBatchWorkflowService.java +++ b/src/main/java/zw/qantra/tm/domain/services/GroupBatchWorkflowService.java @@ -10,6 +10,7 @@ import zw.qantra.tm.domain.repositories.GroupBatchRepository; import zw.qantra.tm.domain.repositories.RecipientRepository; import zw.qantra.tm.domain.services.processors.workflows.handlers.*; import zw.qantra.tm.exceptions.ApiException; +import zw.qantra.tm.utils.SecurityUtils; import zw.qantra.tm.utils.Utils; import java.math.BigDecimal; @@ -32,6 +33,7 @@ public class GroupBatchWorkflowService { private final IntegrationHandler integrationHandler; private final CalculateChargesHandler calculateChargesHandler; private final CleanupHandler cleanUpHandler; + private final UserService userService; @Transactional public GroupBatch processConfirm(UUID batchId) { @@ -49,15 +51,10 @@ public class GroupBatchWorkflowService { batch.setConfirmStartedAt(LocalDateTime.now()); groupBatchRepository.save(batch); - Transaction template = Utils.fromJson(batch.getTransactionTemplate(), Transaction.class); - if (template == null) { - throw new ApiException("Batch transaction template is missing"); - } - List items = groupBatchItemRepository.findAllByGroupBatchId(batchId); List> futures = new ArrayList<>(); for (GroupBatchItem item : items) { - futures.add(CompletableFuture.runAsync(() -> confirmItem(batch, item, template))); + futures.add(CompletableFuture.runAsync(() -> confirmItem(batch, item))); } futures.forEach(CompletableFuture::join); @@ -98,17 +95,18 @@ public class GroupBatchWorkflowService { throw new ApiException("No confirmed batch items available for payment request"); } - Transaction template = Utils.fromJson(batch.getTransactionTemplate(), Transaction.class); - if (template == null) { - throw new ApiException("Batch transaction template is missing"); - } - BigDecimal total = confirmedItems.stream() .map(item -> item.getAmount() == null ? BigDecimal.ZERO : item.getAmount()) .reduce(BigDecimal.ZERO, BigDecimal::add); + User user = userService.getUserRepository().findById(UUID.fromString(batch.getUserId())).orElseThrow(); - Transaction transaction = Utils.deepCopy(template, Transaction.class); + Transaction transaction = new Transaction(); transaction.setId(null); + transaction.setDebitPhone(user.getPhone()); + transaction.setDebitName(user.getFirstName()); + transaction.setDebitCurrency(CurrencyType.valueOf(batch.getCurrency())); + transaction.setRegion("ZW"); + transaction.setPartyType(PartyType.GROUP); transaction.setType(RequestType.REQUEST); transaction.setAuthType(authType == null ? AuthType.REMOTE : authType); @@ -119,6 +117,7 @@ public class GroupBatchWorkflowService { transaction.setPaymentProcessorLabel(batch.getPaymentProcessorLabel()); transaction.setPaymentProcessorName(batch.getPaymentProcessorName()); transaction.setPaymentProcessorImage(batch.getPaymentProcessorImage()); + transaction.setBatchId(batch.getId()); transaction = calculateChargesHandler.process(transaction); transaction = (Transaction) cleanUpHandler.process(transaction); @@ -203,11 +202,23 @@ public class GroupBatchWorkflowService { return groupBatchRepository.save(batch); } - private void confirmItem(GroupBatch batch, GroupBatchItem item, Transaction template) { + private void confirmItem(GroupBatch batch, GroupBatchItem item) { GroupBatchItem mutableItem = groupBatchItemRepository.findById(item.getId()).orElse(item); try { - Transaction transaction = Utils.deepCopy(template, Transaction.class); + User user = userService.getUserRepository().findById(UUID.fromString(batch.getUserId())).orElseThrow(); + Transaction transaction = new Transaction(); transaction.setId(null); + transaction.setDebitPhone(user.getPhone()); + transaction.setDebitName(user.getFirstName()); + transaction.setDebitCurrency(CurrencyType.valueOf(batch.getCurrency())); + transaction.setRegion("ZW"); + + transaction.setBillClientId(item.getBillClientId()); + transaction.setBillName(item.getBillName()); + transaction.setBillProductName(item.getBillProductName()); + transaction.setProviderImage(item.getProviderImage()); + transaction.setProviderLabel(item.getProviderLabel()); + transaction.setUserId(batch.getUserId()); transaction.setType(RequestType.CONFIRM); transaction.setPartyType(PartyType.BATCH); @@ -241,6 +252,7 @@ public class GroupBatchWorkflowService { mutableItem.setConfirmError(result.getErrorMessage()); } } catch (Exception e) { + e.printStackTrace(); mutableItem.setConfirmStatus(GroupBatchItemConfirmStatus.FAILED); mutableItem.setStatus(GroupBatchItemStatus.FAILED); mutableItem.setIntegrationStatus(GroupBatchItemIntegrationStatus.SKIPPED); @@ -278,6 +290,7 @@ public class GroupBatchWorkflowService { mutableItem.setStatus(GroupBatchItemStatus.INTEGRATED); mutableItem.setIntegrationError(null); } catch (Exception e) { + e.printStackTrace(); mutableItem.setIntegrationStatus(GroupBatchItemIntegrationStatus.FAILED); mutableItem.setStatus(GroupBatchItemStatus.FAILED); mutableItem.setIntegrationError(e.getMessage()); diff --git a/src/main/java/zw/qantra/tm/domain/services/ProviderService.java b/src/main/java/zw/qantra/tm/domain/services/ProviderService.java index 203ad7d..a9075f7 100644 --- a/src/main/java/zw/qantra/tm/domain/services/ProviderService.java +++ b/src/main/java/zw/qantra/tm/domain/services/ProviderService.java @@ -90,6 +90,10 @@ public class ProviderService { if (provider == null) { return Collections.emptyList(); } + if(provider.getRequiresProducts().equals(false)){ + return Collections.emptyList(); + } + Map meta = Utils.fromJson(provider.getMeta(), Map.class); String providerId = meta.get("hotProductId"); diff --git a/src/main/java/zw/qantra/tm/domain/services/VelocityPaymentService.java b/src/main/java/zw/qantra/tm/domain/services/VelocityPaymentService.java index 6a530db..5116c22 100644 --- a/src/main/java/zw/qantra/tm/domain/services/VelocityPaymentService.java +++ b/src/main/java/zw/qantra/tm/domain/services/VelocityPaymentService.java @@ -16,7 +16,9 @@ import zw.qantra.tm.domain.dtos.RegisterRequest; import zw.qantra.tm.domain.dtos.erp.*; import zw.qantra.tm.domain.enums.CurrencyType; import zw.qantra.tm.domain.enums.Status; +import zw.qantra.tm.domain.models.GroupBatchItem; import zw.qantra.tm.domain.models.Transaction; +import zw.qantra.tm.domain.repositories.GroupBatchItemRepository; import zw.qantra.tm.domain.repositories.TransactionRepository; import zw.qantra.tm.configs.VelocityApiProperties; import zw.qantra.tm.exceptions.AlreadyExistsException; @@ -27,12 +29,14 @@ import java.math.BigDecimal; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.stream.Collectors; @Service @Slf4j @RequiredArgsConstructor public class VelocityPaymentService { private final TransactionRepository transactionRepository; + private final GroupBatchItemRepository groupBatchItemRepository; private final ObjectMapper objectMapper; private final RestService restService; private final VelocityApiProperties velocityApiProperties; @@ -101,19 +105,47 @@ public class VelocityPaymentService { public Transaction createSalesOrder(Transaction transaction) { BigDecimal amount = transaction.getTotalAmount(); DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + List items; + if (transaction.getBatchId() != null) { + // Fetch GroupBatchItems for this batch and summarize by providerLabel + List batchItems = groupBatchItemRepository.findAllByGroupBatchId(transaction.getBatchId()); + Map totalsByProvider = batchItems.stream() + .filter(item -> item.getProviderLabel() != null && item.getAmount() != null) + .collect(Collectors.groupingBy( + GroupBatchItem::getProviderLabel, + Collectors.mapping( + GroupBatchItem::getAmount, + Collectors.reducing(BigDecimal.ZERO, BigDecimal::add) + ) + )); + + items = totalsByProvider.entrySet().stream() + .map(entry -> VelocitySalesOrderDto.ItemDto.builder() + .name(transaction.getBillName()) + .itemCode("VLT-" + entry.getKey()) + .qty(BigDecimal.ONE) + .unitPrice(entry.getValue()) + .amount(entry.getValue()) + .build()) + .collect(Collectors.toList()); + } else { + items = Collections.singletonList(VelocitySalesOrderDto.ItemDto.builder() + .name(transaction.getBillName()) + .itemCode("VLT-" + transaction.getProviderLabel()) + .qty(BigDecimal.ONE) + .unitPrice(amount) + .amount(amount) + .build()); + } + VelocitySalesOrderDto payload = VelocitySalesOrderDto.builder() .currencyCodeString(transaction.getDebitCurrency().name()) .orderDate(LocalDate.now().format(fmt)) .dueDate(LocalDate.now().plusDays(7).format(fmt)) - .notes(transaction.getReference()) + .notes("Transaction trace - " + transaction.getTrace()) .authorized(Boolean.TRUE) - .items(Collections.singletonList(VelocitySalesOrderDto.ItemDto.builder() - .name(transaction.getBillName()) - .itemCode("VLT-" + transaction.getProviderLabel()) - .qty(BigDecimal.ONE) - .unitPrice(amount) - .amount(amount) - .build())) + .items(items) .charges(Collections.emptyList()) .build(); diff --git a/src/main/java/zw/qantra/tm/domain/services/processors/integrations/HotRechargeIntegrationProcessor.java b/src/main/java/zw/qantra/tm/domain/services/processors/integrations/HotRechargeIntegrationProcessor.java index 70c0e5b..1dd99fe 100644 --- a/src/main/java/zw/qantra/tm/domain/services/processors/integrations/HotRechargeIntegrationProcessor.java +++ b/src/main/java/zw/qantra/tm/domain/services/processors/integrations/HotRechargeIntegrationProcessor.java @@ -170,10 +170,11 @@ public class HotRechargeIntegrationProcessor implements TransactionProcessorInte } // do this for Econet bundles - if(providerId.equals("111")) { - Provider provider = providerService.getProviderRepository() - .findByClientId(transaction.getBillClientId()); - String productCode = providerService.getExternalId(provider.getId().toString(), transaction.getBillProductName()); + Provider provider = providerService.getProviderRepository() + .findByClientId(transaction.getBillClientId()); + if(provider.getRequiresProducts().equals(true)) { + String productCode = providerService.getExternalId( + provider.getId().toString(), transaction.getBillProductName()); List> rechargeOptions = new ArrayList<>(); Map option = new LinkedHashMap<>(); option.put("Name", "ProductCode"); diff --git a/src/main/java/zw/qantra/tm/domain/services/processors/workflows/handlers/CleanupHandler.java b/src/main/java/zw/qantra/tm/domain/services/processors/workflows/handlers/CleanupHandler.java index 0926338..d1c5189 100644 --- a/src/main/java/zw/qantra/tm/domain/services/processors/workflows/handlers/CleanupHandler.java +++ b/src/main/java/zw/qantra/tm/domain/services/processors/workflows/handlers/CleanupHandler.java @@ -41,19 +41,21 @@ public class CleanupHandler implements HandlerInterface { // UPDATE TRAN WITH CONFIRMATION HANDLER // ======================= - Provider provider = providerService.getProviderRepository() - .findByClientId(transaction.getBillClientId()); - if(provider == null){ - throw new ApiException("Provider not found for billClientId: " + transaction.getBillClientId()); - } - String label = - transaction.getType() + "_" + - provider.getLabel() + "_" + - provider.getIntegrationProcessorLabel(); + if(transaction.getType().equals(RequestType.CONFIRM)) { + Provider provider = providerService.getProviderRepository() + .findByClientId(transaction.getBillClientId()); + if(provider == null){ + throw new ApiException("Provider not found for billClientId: " + transaction.getBillClientId()); + } + String label = + transaction.getType() + "_" + + provider.getLabel() + "_" + + provider.getIntegrationProcessorLabel(); - transaction.setConfirmationProcessorLabel(label); - transaction.setProviderLabel(provider.getLabel()); - logger.info("label: {}", label); + transaction.setConfirmationProcessorLabel(label); + transaction.setProviderLabel(provider.getLabel()); + logger.info("label: {}", label); + } // FORMAT FIELDS CORRECTLY // ======================= diff --git a/src/main/java/zw/qantra/tm/seeders/ProviderSeeder.java b/src/main/java/zw/qantra/tm/seeders/ProviderSeeder.java index d6be574..1836510 100644 --- a/src/main/java/zw/qantra/tm/seeders/ProviderSeeder.java +++ b/src/main/java/zw/qantra/tm/seeders/ProviderSeeder.java @@ -45,6 +45,25 @@ public class ProviderSeeder implements Seeder { .meta("{\"hotProductId\": \"101\"}") .uid(Utils.getUid()) .build(), + Provider.builder() + .name("Econet Airtime") + .description("Econet Airtime") + .clientId("econet_airtime_zwg") + .currency(CurrencyType.ZWG) + .label("ECONET") + .category("AIRTIME") + .image("econet.png") + .externalId("78f1f497-c9eb-401c-b22c-884756e68e41") + .integrationProcessorLabel("HOT") + .accountFieldName("Phone Number") + .percentageCommission(5) + .requiresAccount(false) + .requiresAmount(true) + .requiresPhone(true) + .priority(2) + .meta("{\"hotProductId\": \"7\"}") + .uid(Utils.getUid()) + .build(), Provider.builder() .name("NetOne Airtime") .description("NetOne Airtime") @@ -120,6 +139,26 @@ public class ProviderSeeder implements Seeder { .priority(4) .meta("{\"hotProductId\": \"111\"}") .uid(Utils.getUid()) + .build(), + Provider.builder() + .name("Econet Bundles") + .description("Econet Bundles") + .clientId("econet_bundles_zwg") + .currency(CurrencyType.ZWG) + .label("ECONET_BUNDLES") + .category("AIRTIME") + .image("econet.png") + .externalId("287863e2-a791-4106-b629-79dadc9a6780") + .integrationProcessorLabel("HOT") + .accountFieldName("Phone Number") + .percentageCommission(5) + .requiresAccount(false) + .requiresAmount(false) + .requiresPhone(true) + .requiresProducts(true) + .priority(4) + .meta("{\"hotProductId\": \"16\"}") + .uid(Utils.getUid()) .build() ); diff --git a/src/main/java/zw/qantra/tm/utils/SecurityUtils.java b/src/main/java/zw/qantra/tm/utils/SecurityUtils.java new file mode 100644 index 0000000..a84741a --- /dev/null +++ b/src/main/java/zw/qantra/tm/utils/SecurityUtils.java @@ -0,0 +1,21 @@ +package zw.qantra.tm.utils; + +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.UserDetails; + +public class SecurityUtils { + + public static String getCurrentUsername() { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication != null && authentication.isAuthenticated()) { + Object principal = authentication.getPrincipal(); + if (principal instanceof UserDetails) { + return ((UserDetails) principal).getUsername(); + } else { + return principal.toString(); // For cases where principal might be a String + } + } + return null; // Or throw an exception if the user is expected to be logged in + } +} \ No newline at end of file diff --git a/src/main/resources/application-lab.properties b/src/main/resources/application-lab.properties index 8f328b7..6b4a13f 100644 --- a/src/main/resources/application-lab.properties +++ b/src/main/resources/application-lab.properties @@ -7,7 +7,7 @@ server.port=6950 server.servlet.context-path=/api -spring.jpa.hibernate.ddl-auto=create +spring.jpa.hibernate.ddl-auto=validate spring.datasource.driver-class-name=org.postgresql.Driver spring.datasource.url=jdbc:postgresql://localhost:5432/qpay?useLegacyDatetimeCode=false @@ -38,8 +38,8 @@ powertel.clientid=powertel_zesa ecocash.apikey=OUzGezwTgktLg_9v0I48I6WUM4LVLGFl ecocash.url=https://developers.ecocash.co.zw/api/ecocash_pay/api/v2/payment/instant/c2b/sandbox -#velocity.api.base-url=https://api.velocityafrica.net -#velocity.api.api-key=z5WdSlItIhYL6nd7rxzf-jFdKN3jJyL1LubhDFBvXmc +velocity.api.base-url=https://api.velocityafrica.net +velocity.api.api-key=Ko7_hAZjDNAqj--VI1kpkgV4D6PsjS6eWWEIgcfhG8M #velocity.api.base-url=http://localhost:6975 #velocity.api.api-key=gH13nirZdUQdqC9impgzTzqEqv-jdbLOTx_HD5fQr_A velocity.api.cancel-url=http://localhost:9005/poll diff --git a/src/main/resources/liquibase-diff-changeLog.xml b/src/main/resources/liquibase-diff-changeLog.xml index f3308c9..9cfd70d 100644 --- a/src/main/resources/liquibase-diff-changeLog.xml +++ b/src/main/resources/liquibase-diff-changeLog.xml @@ -1,214 +1,13 @@ - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + +