-
Notifications
You must be signed in to change notification settings - Fork 14
[PHEE-637] Batch Payment Mock API's #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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(); | ||
|
|
@@ -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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a test case available for this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, manoj. All data is mocked.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.