Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ plugins {
id 'java'
id 'maven-publish'
id 'eclipse'
id 'org.springframework.boot' version '2.6.2'
id 'org.springframework.boot' version '2.5.5'
id 'io.spring.dependency-management' version '1.1.0'
id 'checkstyle'
id 'com.diffplug.spotless' version '6.19.0'
id "org.springdoc.openapi-gradle-plugin" version "1.6.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.mifos.connector.mockpaymentschema.schema.AuthorizationRequest;
import org.mifos.connector.mockpaymentschema.schema.BatchDTO;
import org.mifos.connector.mockpaymentschema.schema.BatchDetailResponse;
import org.mifos.connector.mockpaymentschema.service.BatchService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -41,4 +45,15 @@ public ResponseEntity<Object> getAuthorization(@PathVariable String batchId,
}
return new ResponseEntity<>(HttpStatus.ACCEPTED);
}

@GetMapping(value = "/batches/{batchId}/summary", produces = MediaType.APPLICATION_JSON_VALUE)
public BatchDTO batchSummary(@PathVariable String batchId) {
return batchService.getBatchSummary(batchId);
}

@GetMapping(value = "/batches/{batchId}/detail", produces = MediaType.APPLICATION_JSON_VALUE)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API documentation should be upated. Please attach link to postman PR.
Also make sure that the validations and error handling is done.

ref: https://docs.google.com/spreadsheets/d/13TdoMUXtmV4MqwafbZu4_zvwOUhbO2WTs1UxZOLXHXI/edit#gid=0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

openMF/ph-ee-env-template#411
I have added postman collection for this.

public BatchDetailResponse batchDetail(@PathVariable String batchId, @RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
return batchService.getBatchDetails(batchId, pageNo, pageSize);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.mifos.connector.mockpaymentschema.schema;

import java.math.BigDecimal;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class BatchDTO {

private String batchId;

private String requestId;

private Long total;

private Long ongoing;

private Long failed;

private Long successful;

private BigDecimal totalAmount;

private BigDecimal successfulAmount;

private BigDecimal pendingAmount;

private BigDecimal failedAmount;

private String file;

private String notes;

private String createdAt;

private String status;

private String modes;

private String purpose;

private String failPercentage;

private String successPercentage;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.mifos.connector.mockpaymentschema.schema;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class BatchDetailResponse {

private List<Transfer> content;

private org.mifos.connector.mockpaymentschema.schema.PageableDTO pageable;

private Long totalPages;

private Long totalElements;

private boolean last;

private boolean first;

private org.mifos.connector.mockpaymentschema.schema.SortDTO sort;

private Long numberOfElements;

private Long size;

private Long number;

private boolean empty;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.mifos.connector.mockpaymentschema.schema;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class PageableDTO {

private org.mifos.connector.mockpaymentschema.schema.SortDTO sort;

private Long pageSize;

private Long pageNumber;

private Long offset;

private boolean unpaged;

private boolean paged;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.mifos.connector.mockpaymentschema.schema;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class SortDTO {

private boolean sorted;

private boolean unsorted;

private boolean empty;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.mifos.connector.mockpaymentschema.schema;

import java.math.BigDecimal;
import java.util.Date;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Transfer {

private String id;

private Long workflowInstanceKey;

private String transactionId;

private Date startedAt;
private Date completedAt;

private TransferStatus status;

private String statusDetail;

private String payeeDfspId;

private String payeePartyId;

private String payeePartyIdType;

private BigDecimal payeeFee;

private String payeeFeeCurrency;

private String payeeQuoteCode;

private String payerDfspId;

private String payerPartyId;

private String payerPartyIdType;

private BigDecimal payerFee;

private String payerFeeCurrency;

private String payerQuoteCode;

private BigDecimal amount;

private String currency;

private String direction;

private String errorInformation;

private String batchId;

private String clientCorrelationId;

public Transfer(Long workflowInstanceKey) {
this.workflowInstanceKey = workflowInstanceKey;
this.status = TransferStatus.IN_PROGRESS;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.mifos.connector.mockpaymentschema.schema;

public enum TransferStatus {
COMPLETED, FAILED, IN_PROGRESS, UNKNOWN
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import org.mifos.connector.mockpaymentschema.schema.AuthorizationRequest;
import org.mifos.connector.mockpaymentschema.schema.AuthorizationResponse;
import org.mifos.connector.mockpaymentschema.schema.BatchDTO;
import org.mifos.connector.mockpaymentschema.schema.BatchDetailResponse;
import org.mifos.connector.mockpaymentschema.schema.Transfer;
import org.mifos.connector.mockpaymentschema.schema.TransferStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -19,10 +28,16 @@ public class BatchService {
private String thresholdAmount;

@Autowired
private SendCallbackService sendCallbackService;
private org.mifos.connector.mockpaymentschema.service.SendCallbackService sendCallbackService;

protected Logger logger = LoggerFactory.getLogger(this.getClass());

private String payerPartyId = "835322416";

private String payeePartyId = "27713803912";

private int successTxnCount = 9;

@Async("asyncExecutor")
public void getAuthorization(String batchId, String clientCorrelationId, AuthorizationRequest authRequest, String callbackUrl) {
AuthorizationResponse response = new AuthorizationResponse();
Expand All @@ -42,4 +57,68 @@ public void getAuthorization(String batchId, String clientCorrelationId, Authori
logger.error(e.toString());
}
}

public BatchDTO getBatchSummary(String batchId) {
return successfulBatchSummaryResponse(batchId);
}

public BatchDetailResponse getBatchDetails(String batchId, int pageNo, int pageSize) {
List<Transfer> transactions = getTransactions(batchId);
int toIndex = pageNo * pageSize;
int fromIndex = toIndex - pageSize;
toIndex = Math.min(toIndex, transactions.size());
BatchDetailResponse batchDetailResponse = new BatchDetailResponse();
batchDetailResponse.setContent(transactions.subList(fromIndex, toIndex));
return batchDetailResponse;
}

private BatchDTO successfulBatchSummaryResponse(String batchId) {
Long total = 10L;
Long ongoing = 1L;
Long failed = 1L;
Long successful = 8L;
BigDecimal totalAmount = BigDecimal.valueOf(100);
BigDecimal ongoingAmount = BigDecimal.valueOf(0);
BigDecimal failedAmount = BigDecimal.valueOf(10);
BigDecimal successfulAmount = BigDecimal.valueOf(90);
String status = "Pending";
String successPercentage = "90";
String failedPercentage = "10";

return new BatchDTO(batchId, null, total, ongoing, failed, successful, totalAmount, successfulAmount, ongoingAmount, failedAmount,
null, null, null, status, null, null, failedPercentage, successPercentage);
}

private List<Transfer> getTransactions(String batchId) {
List<Transfer> transactionList = new ArrayList<>();

for (int index = 0; index < 10; index++) {
Transfer transfer;

if (successTxnCount > 0) {
transfer = getSingleTransaction(index, ThreadLocalRandom.current().nextLong(), UUID.randomUUID().toString(),
TransferStatus.COMPLETED, batchId);
} else {
transfer = getSingleTransaction(index, ThreadLocalRandom.current().nextLong(), UUID.randomUUID().toString(),
TransferStatus.IN_PROGRESS, batchId);
}
transactionList.add(transfer);
}
return transactionList;
}

private Transfer getSingleTransaction(int index, Long workflowInstanceKey, String requestId, TransferStatus status, String batchId) {
String id = String.valueOf(index);
Date startedAt = new Date(1685536200000L);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a test case available for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, manoj. All data is mocked.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it will always send same data. No need for test case here

Date completedAt = new Date(1685536268000L);
String payerPartyIdType = "MSISDN";
String payeePartyIdType = "MSISDN";
BigDecimal amount = BigDecimal.valueOf(10);
String currency = "USD";
String direction = "OUTGOING";

return new Transfer(id, workflowInstanceKey, requestId, startedAt, completedAt, status, null, null, payeePartyId, payeePartyIdType,
null, null, null, null, payerPartyId, payerPartyIdType, null, null, null, amount, currency, direction, null, batchId, null);
}

}