progress on integration to sbz
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package zw.qantra.tm.domain.services;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import zw.qantra.tm.domain.models.Category;
|
||||
import zw.qantra.tm.domain.repositories.CategoryRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CategoryService {
|
||||
private final CategoryRepository categoryRepository;
|
||||
|
||||
public List<Category> getAllCategories() {
|
||||
return categoryRepository.findAll();
|
||||
}
|
||||
|
||||
public Optional<Category> getCategory(UUID id) {
|
||||
return categoryRepository.findById(id);
|
||||
}
|
||||
|
||||
public Category createCategory(Category category) {
|
||||
return categoryRepository.save(category);
|
||||
}
|
||||
|
||||
public Category updateCategory(UUID id, Category category) {
|
||||
if (categoryRepository.existsById(id)) {
|
||||
category.setId(id);
|
||||
return categoryRepository.save(category);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean deleteCategory(UUID id) {
|
||||
if (categoryRepository.existsById(id)) {
|
||||
categoryRepository.deleteById(id);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package zw.qantra.tm.domain.services;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -11,25 +12,22 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import zw.qantra.tm.domain.dtos.SBZProductDto;
|
||||
import zw.qantra.tm.domain.models.Provider;
|
||||
import zw.qantra.tm.domain.repositories.ChargeRepository;
|
||||
import zw.qantra.tm.domain.repositories.ProviderRepository;
|
||||
import zw.qantra.tm.rest.RestService;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ProviderService {
|
||||
@Getter
|
||||
private final ProviderRepository providerRepository;
|
||||
private final RestService restService;
|
||||
|
||||
@Value("${sbz.aggregator.url}")
|
||||
private String aggregatorUrl;
|
||||
|
||||
public ProviderRepository getProviderRepository() {
|
||||
return providerRepository;
|
||||
}
|
||||
|
||||
public List<SBZProductDto> getProviderProducts(UUID providerId) {
|
||||
String token = restService.getMerchantToken();
|
||||
|
||||
@@ -57,8 +55,36 @@ public class ProviderService {
|
||||
return products;
|
||||
}
|
||||
|
||||
public List<Provider> getProviders() {
|
||||
return providerRepository.findAll();
|
||||
public Object getProviders(String category) {
|
||||
String token = restService.getMerchantToken();
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||
headers.setBearerAuth(token);
|
||||
|
||||
List<Provider> existingProviders;
|
||||
if (category != null) {
|
||||
existingProviders = getProviderRepository().findByCategory(category);
|
||||
} else {
|
||||
existingProviders = getProviderRepository().findAll();
|
||||
}
|
||||
|
||||
List<String> existingProviderIds = existingProviders.stream()
|
||||
.map(Provider::getClientId)
|
||||
.collect(Collectors.toList());
|
||||
String existingProviderIdsString = String.join(",", existingProviderIds);
|
||||
|
||||
LinkedHashMap response = this.restService.getAs(
|
||||
aggregatorUrl + "/merchant/aggregation/providers?supportedCurrencies=USD&clientIdIn=" + existingProviderIdsString,
|
||||
headers,
|
||||
LinkedHashMap.class
|
||||
);
|
||||
|
||||
LinkedHashMap body = (LinkedHashMap) response.get("body");
|
||||
List<LinkedHashMap> content = (List<LinkedHashMap>) body.get("content");
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
public Optional<Provider> getProvider(UUID id) {
|
||||
|
||||
@@ -3,10 +3,14 @@ package zw.qantra.tm.domain.services.processors.confirmations;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import zw.qantra.tm.domain.dtos.BillPaymentDto;
|
||||
import zw.qantra.tm.domain.enums.RequestType;
|
||||
import zw.qantra.tm.domain.models.Transaction;
|
||||
import zw.qantra.tm.domain.services.processors.TransactionProcessorInterface;
|
||||
import zw.qantra.tm.rest.RestService;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Service("CONFIRM_ZESA")
|
||||
@RequiredArgsConstructor
|
||||
public class ZesaConfirmationProcessor implements TransactionProcessorInterface {
|
||||
@@ -18,8 +22,27 @@ public class ZesaConfirmationProcessor implements TransactionProcessorInterface
|
||||
@Override
|
||||
public Object process(Transaction transaction) throws Exception {
|
||||
System.out.println("processing transaction");
|
||||
String token = restService.getMerchantToken();
|
||||
|
||||
BillPaymentDto request = BillPaymentDto.builder()
|
||||
.type(RequestType.CONFIRM)
|
||||
.billClientId(transaction.getBillClientId())
|
||||
.debitRef(transaction.getDebitRef())
|
||||
.debitCurrency(transaction.getDebitCurrency())
|
||||
.amount(transaction.getAmount())
|
||||
.aggregatorId(transaction.getAggregatorId())
|
||||
.debitPhone(transaction.getDebitPhone())
|
||||
.debitAccount(transaction.getDebitAccount())
|
||||
.creditAccount(transaction.getCreditAccount())
|
||||
.creditPhone(transaction.getCreditPhone())
|
||||
.billName(transaction.getBillName())
|
||||
.build();
|
||||
|
||||
String url = aggregatorUrl + "/v1/merchant/aggregation/transaction";
|
||||
|
||||
Map response = restService.postWithToken(token, url, request, Map.class);
|
||||
|
||||
System.out.println(response);
|
||||
|
||||
return transaction;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user