Skip to content

Commit 4d69e18

Browse files
abhinavm117apurbrajAbhinav Mishra
authored
[PHEE-637] Batch Payment Mock API's (#28)
* Mock Apis * Bug Fix * Chnages * Wrong server port --------- Co-authored-by: Apurb Rajdhan <103931815+apurbraj@users.noreply.github.com> Co-authored-by: Abhinav Mishra <abhinav@fynarfin.in>
1 parent 3decd53 commit 4d69e18

9 files changed

Lines changed: 303 additions & 2 deletions

File tree

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ plugins {
66
id 'java'
77
id 'maven-publish'
88
id 'eclipse'
9-
id 'org.springframework.boot' version '2.6.2'
9+
id 'org.springframework.boot' version '2.5.5'
10+
id 'io.spring.dependency-management' version '1.1.0'
1011
id 'checkstyle'
1112
id 'com.diffplug.spotless' version '6.19.0'
1213
id "org.springdoc.openapi-gradle-plugin" version "1.6.0"

src/main/java/org/mifos/connector/mockpaymentschema/api/BatchApi.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
import io.swagger.v3.oas.annotations.Operation;
44
import io.swagger.v3.oas.annotations.tags.Tag;
55
import org.mifos.connector.mockpaymentschema.schema.AuthorizationRequest;
6+
import org.mifos.connector.mockpaymentschema.schema.BatchDTO;
7+
import org.mifos.connector.mockpaymentschema.schema.BatchDetailResponse;
68
import org.mifos.connector.mockpaymentschema.service.BatchService;
79
import org.slf4j.Logger;
810
import org.slf4j.LoggerFactory;
911
import org.springframework.beans.factory.annotation.Autowired;
1012
import org.springframework.http.HttpStatus;
13+
import org.springframework.http.MediaType;
1114
import org.springframework.http.ResponseEntity;
15+
import org.springframework.web.bind.annotation.GetMapping;
1216
import org.springframework.web.bind.annotation.PathVariable;
1317
import org.springframework.web.bind.annotation.PostMapping;
1418
import org.springframework.web.bind.annotation.RequestBody;
@@ -41,4 +45,15 @@ public ResponseEntity<Object> getAuthorization(@PathVariable String batchId,
4145
}
4246
return new ResponseEntity<>(HttpStatus.ACCEPTED);
4347
}
48+
49+
@GetMapping(value = "/batches/{batchId}/summary", produces = MediaType.APPLICATION_JSON_VALUE)
50+
public BatchDTO batchSummary(@PathVariable String batchId) {
51+
return batchService.getBatchSummary(batchId);
52+
}
53+
54+
@GetMapping(value = "/batches/{batchId}/detail", produces = MediaType.APPLICATION_JSON_VALUE)
55+
public BatchDetailResponse batchDetail(@PathVariable String batchId, @RequestParam(value = "pageNo", defaultValue = "0") Integer pageNo,
56+
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
57+
return batchService.getBatchDetails(batchId, pageNo, pageSize);
58+
}
4459
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.mifos.connector.mockpaymentschema.schema;
2+
3+
import java.math.BigDecimal;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
import lombok.Setter;
8+
9+
@Getter
10+
@Setter
11+
@AllArgsConstructor
12+
@NoArgsConstructor
13+
public class BatchDTO {
14+
15+
private String batchId;
16+
17+
private String requestId;
18+
19+
private Long total;
20+
21+
private Long ongoing;
22+
23+
private Long failed;
24+
25+
private Long successful;
26+
27+
private BigDecimal totalAmount;
28+
29+
private BigDecimal successfulAmount;
30+
31+
private BigDecimal pendingAmount;
32+
33+
private BigDecimal failedAmount;
34+
35+
private String file;
36+
37+
private String notes;
38+
39+
private String createdAt;
40+
41+
private String status;
42+
43+
private String modes;
44+
45+
private String purpose;
46+
47+
private String failPercentage;
48+
49+
private String successPercentage;
50+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.mifos.connector.mockpaymentschema.schema;
2+
3+
import java.util.List;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
import lombok.Setter;
8+
9+
@Getter
10+
@Setter
11+
@AllArgsConstructor
12+
@NoArgsConstructor
13+
public class BatchDetailResponse {
14+
15+
private List<Transfer> content;
16+
17+
private org.mifos.connector.mockpaymentschema.schema.PageableDTO pageable;
18+
19+
private Long totalPages;
20+
21+
private Long totalElements;
22+
23+
private boolean last;
24+
25+
private boolean first;
26+
27+
private org.mifos.connector.mockpaymentschema.schema.SortDTO sort;
28+
29+
private Long numberOfElements;
30+
31+
private Long size;
32+
33+
private Long number;
34+
35+
private boolean empty;
36+
37+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.mifos.connector.mockpaymentschema.schema;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
import lombok.NoArgsConstructor;
6+
import lombok.Setter;
7+
8+
@Getter
9+
@Setter
10+
@AllArgsConstructor
11+
@NoArgsConstructor
12+
public class PageableDTO {
13+
14+
private org.mifos.connector.mockpaymentschema.schema.SortDTO sort;
15+
16+
private Long pageSize;
17+
18+
private Long pageNumber;
19+
20+
private Long offset;
21+
22+
private boolean unpaged;
23+
24+
private boolean paged;
25+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.mifos.connector.mockpaymentschema.schema;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
import lombok.NoArgsConstructor;
6+
import lombok.Setter;
7+
8+
@Getter
9+
@Setter
10+
@AllArgsConstructor
11+
@NoArgsConstructor
12+
public class SortDTO {
13+
14+
private boolean sorted;
15+
16+
private boolean unsorted;
17+
18+
private boolean empty;
19+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package org.mifos.connector.mockpaymentschema.schema;
2+
3+
import java.math.BigDecimal;
4+
import java.util.Date;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Getter;
7+
import lombok.NoArgsConstructor;
8+
import lombok.Setter;
9+
10+
@Getter
11+
@Setter
12+
@AllArgsConstructor
13+
@NoArgsConstructor
14+
public class Transfer {
15+
16+
private String id;
17+
18+
private Long workflowInstanceKey;
19+
20+
private String transactionId;
21+
22+
private Date startedAt;
23+
private Date completedAt;
24+
25+
private TransferStatus status;
26+
27+
private String statusDetail;
28+
29+
private String payeeDfspId;
30+
31+
private String payeePartyId;
32+
33+
private String payeePartyIdType;
34+
35+
private BigDecimal payeeFee;
36+
37+
private String payeeFeeCurrency;
38+
39+
private String payeeQuoteCode;
40+
41+
private String payerDfspId;
42+
43+
private String payerPartyId;
44+
45+
private String payerPartyIdType;
46+
47+
private BigDecimal payerFee;
48+
49+
private String payerFeeCurrency;
50+
51+
private String payerQuoteCode;
52+
53+
private BigDecimal amount;
54+
55+
private String currency;
56+
57+
private String direction;
58+
59+
private String errorInformation;
60+
61+
private String batchId;
62+
63+
private String clientCorrelationId;
64+
65+
public Transfer(Long workflowInstanceKey) {
66+
this.workflowInstanceKey = workflowInstanceKey;
67+
this.status = TransferStatus.IN_PROGRESS;
68+
}
69+
70+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.mifos.connector.mockpaymentschema.schema;
2+
3+
public enum TransferStatus {
4+
COMPLETED, FAILED, IN_PROGRESS, UNKNOWN
5+
}

src/main/java/org/mifos/connector/mockpaymentschema/service/BatchService.java

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@
33
import com.fasterxml.jackson.core.JsonProcessingException;
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import java.math.BigDecimal;
6+
import java.util.ArrayList;
7+
import java.util.Date;
8+
import java.util.List;
9+
import java.util.UUID;
10+
import java.util.concurrent.ThreadLocalRandom;
611
import org.mifos.connector.mockpaymentschema.schema.AuthorizationRequest;
712
import org.mifos.connector.mockpaymentschema.schema.AuthorizationResponse;
13+
import org.mifos.connector.mockpaymentschema.schema.BatchDTO;
14+
import org.mifos.connector.mockpaymentschema.schema.BatchDetailResponse;
15+
import org.mifos.connector.mockpaymentschema.schema.Transfer;
16+
import org.mifos.connector.mockpaymentschema.schema.TransferStatus;
817
import org.slf4j.Logger;
918
import org.slf4j.LoggerFactory;
1019
import org.springframework.beans.factory.annotation.Autowired;
@@ -19,10 +28,16 @@ public class BatchService {
1928
private String thresholdAmount;
2029

2130
@Autowired
22-
private SendCallbackService sendCallbackService;
31+
private org.mifos.connector.mockpaymentschema.service.SendCallbackService sendCallbackService;
2332

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

35+
private String payerPartyId = "835322416";
36+
37+
private String payeePartyId = "27713803912";
38+
39+
private int successTxnCount = 9;
40+
2641
@Async("asyncExecutor")
2742
public void getAuthorization(String batchId, String clientCorrelationId, AuthorizationRequest authRequest, String callbackUrl) {
2843
AuthorizationResponse response = new AuthorizationResponse();
@@ -42,4 +57,68 @@ public void getAuthorization(String batchId, String clientCorrelationId, Authori
4257
logger.error(e.toString());
4358
}
4459
}
60+
61+
public BatchDTO getBatchSummary(String batchId) {
62+
return successfulBatchSummaryResponse(batchId);
63+
}
64+
65+
public BatchDetailResponse getBatchDetails(String batchId, int pageNo, int pageSize) {
66+
List<Transfer> transactions = getTransactions(batchId);
67+
int toIndex = pageNo * pageSize;
68+
int fromIndex = toIndex - pageSize;
69+
toIndex = Math.min(toIndex, transactions.size());
70+
BatchDetailResponse batchDetailResponse = new BatchDetailResponse();
71+
batchDetailResponse.setContent(transactions.subList(fromIndex, toIndex));
72+
return batchDetailResponse;
73+
}
74+
75+
private BatchDTO successfulBatchSummaryResponse(String batchId) {
76+
Long total = 10L;
77+
Long ongoing = 1L;
78+
Long failed = 1L;
79+
Long successful = 8L;
80+
BigDecimal totalAmount = BigDecimal.valueOf(100);
81+
BigDecimal ongoingAmount = BigDecimal.valueOf(0);
82+
BigDecimal failedAmount = BigDecimal.valueOf(10);
83+
BigDecimal successfulAmount = BigDecimal.valueOf(90);
84+
String status = "Pending";
85+
String successPercentage = "90";
86+
String failedPercentage = "10";
87+
88+
return new BatchDTO(batchId, null, total, ongoing, failed, successful, totalAmount, successfulAmount, ongoingAmount, failedAmount,
89+
null, null, null, status, null, null, failedPercentage, successPercentage);
90+
}
91+
92+
private List<Transfer> getTransactions(String batchId) {
93+
List<Transfer> transactionList = new ArrayList<>();
94+
95+
for (int index = 0; index < 10; index++) {
96+
Transfer transfer;
97+
98+
if (successTxnCount > 0) {
99+
transfer = getSingleTransaction(index, ThreadLocalRandom.current().nextLong(), UUID.randomUUID().toString(),
100+
TransferStatus.COMPLETED, batchId);
101+
} else {
102+
transfer = getSingleTransaction(index, ThreadLocalRandom.current().nextLong(), UUID.randomUUID().toString(),
103+
TransferStatus.IN_PROGRESS, batchId);
104+
}
105+
transactionList.add(transfer);
106+
}
107+
return transactionList;
108+
}
109+
110+
private Transfer getSingleTransaction(int index, Long workflowInstanceKey, String requestId, TransferStatus status, String batchId) {
111+
String id = String.valueOf(index);
112+
Date startedAt = new Date(1685536200000L);
113+
Date completedAt = new Date(1685536268000L);
114+
String payerPartyIdType = "MSISDN";
115+
String payeePartyIdType = "MSISDN";
116+
BigDecimal amount = BigDecimal.valueOf(10);
117+
String currency = "USD";
118+
String direction = "OUTGOING";
119+
120+
return new Transfer(id, workflowInstanceKey, requestId, startedAt, completedAt, status, null, null, payeePartyId, payeePartyIdType,
121+
null, null, null, null, payerPartyId, payerPartyIdType, null, null, null, amount, currency, direction, null, batchId, null);
122+
}
123+
45124
}

0 commit comments

Comments
 (0)