-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The response codes in the `application.yml` file have been added from the Airtel documentation. Similarly, the responses returned by the API are based on the Airtel documentation.
- Loading branch information
Showing
6 changed files
with
214 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/org/mifos/connector/airtel/mockairtel/api/definition/AirtelMockApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.mifos.connector.airtel.mockairtel.api.definition; | ||
|
||
import org.mifos.connector.airtel.mockairtel.api.implementation.AirtelMockService; | ||
import org.mifos.connector.common.mobilemoney.airtel.dto.AirtelEnquiryResponseDTO; | ||
import org.mifos.connector.common.mobilemoney.airtel.dto.AirtelPaymentRequestDTO; | ||
import org.mifos.connector.common.mobilemoney.airtel.dto.AirtelPaymentResponseDTO; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
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; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class AirtelMockApi { | ||
|
||
@Autowired | ||
private AirtelMockService airtelMockService; | ||
|
||
protected Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
|
||
@GetMapping(value = "/standard/v1/payments/{transactionId}", produces = MediaType.APPLICATION_JSON_VALUE) | ||
public ResponseEntity<AirtelEnquiryResponseDTO> airtelTransactionEnquiry(@PathVariable String transactionId) { | ||
return airtelMockService.getTransactionStatus(transactionId); | ||
} | ||
|
||
@PostMapping("/merchant/v2/payments/") | ||
public ResponseEntity<AirtelPaymentResponseDTO> getAuthorization(@RequestBody AirtelPaymentRequestDTO airtelPaymentRequestDTO) { | ||
return airtelMockService.initiateTransaction(airtelPaymentRequestDTO); | ||
} | ||
|
||
} |
154 changes: 154 additions & 0 deletions
154
...main/java/org/mifos/connector/airtel/mockairtel/api/implementation/AirtelMockService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
package org.mifos.connector.airtel.mockairtel.api.implementation; | ||
|
||
import java.util.UUID; | ||
import org.mifos.connector.airtel.mockairtel.utils.TransactionStatus; | ||
import org.mifos.connector.airtel.mockairtel.utils.TransferStatus; | ||
import org.mifos.connector.common.mobilemoney.airtel.dto.AirtelEnquiryResponseDTO; | ||
import org.mifos.connector.common.mobilemoney.airtel.dto.AirtelEnquiryResponseDataDTO; | ||
import org.mifos.connector.common.mobilemoney.airtel.dto.AirtelEnquiryResponseDataTransactionDTO; | ||
import org.mifos.connector.common.mobilemoney.airtel.dto.AirtelPaymentRequestDTO; | ||
import org.mifos.connector.common.mobilemoney.airtel.dto.AirtelPaymentResponseDTO; | ||
import org.mifos.connector.common.mobilemoney.airtel.dto.AirtelPaymentResponseDataDTO; | ||
import org.mifos.connector.common.mobilemoney.airtel.dto.AirtelPaymentResponseDataTransactionDTO; | ||
import org.mifos.connector.common.mobilemoney.airtel.dto.AirtelResponseStatusDTO; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class AirtelMockService { | ||
|
||
@Value("${mock-airtel.MSISDN_SUCCESSFUL}") | ||
private String msisdnSuccessful; | ||
|
||
@Value("${mock-airtel.MSISDN_FAILED}") | ||
private String msisdnFailed; | ||
|
||
@Value("${mock-airtel.TRANSACTION_ID_SUCCESSFUL}") | ||
private String transactionIdSuccessful; | ||
|
||
@Value("${mock-airtel.TRANSACTION_ID_FAILED}") | ||
private String transactionIdFailed; | ||
|
||
@Value("${mock-airtel.SUCCESS_RESPONSE_CODE}") | ||
private String successResponseCode; | ||
|
||
@Value("${mock-airtel.FAILED_RESPONSE_CODE}") | ||
private String failedResponseCode; | ||
|
||
@Value("${mock-airtel.PENDING_RESPONSE_CODE}") | ||
private String pendingResponseCode; | ||
|
||
@Value("${mock-airtel.RESULT_CODE}") | ||
private String resultCode; | ||
|
||
public ResponseEntity<AirtelEnquiryResponseDTO> getTransactionStatus(String transactionId) { | ||
String airtelMoneyId = UUID.randomUUID().toString().replace("-", ""); | ||
String message; | ||
String status; | ||
String code; | ||
String responseCode; | ||
boolean success; | ||
HttpStatus httpStatus; | ||
|
||
if (transactionId.equals(transactionIdSuccessful)) { | ||
message = TransferStatus.SUCCESSFUL.name(); | ||
status = TransactionStatus.TS.name(); | ||
code = HttpStatus.OK.toString(); | ||
responseCode = successResponseCode; | ||
success = true; | ||
httpStatus = HttpStatus.OK; | ||
} | ||
|
||
else if (transactionId.equals(transactionIdFailed)) { | ||
message = TransferStatus.FAILED.name(); | ||
status = TransactionStatus.TF.name(); | ||
code = HttpStatus.BAD_REQUEST.toString(); | ||
responseCode = failedResponseCode; | ||
success = false; | ||
httpStatus = HttpStatus.BAD_REQUEST; | ||
} | ||
|
||
else { | ||
message = TransferStatus.IN_PROGRESS.name(); | ||
status = TransactionStatus.TP.name(); | ||
code = HttpStatus.ACCEPTED.toString(); | ||
responseCode = pendingResponseCode; | ||
success = true; | ||
httpStatus = HttpStatus.ACCEPTED; | ||
} | ||
|
||
return airtelEnquiryResponse(airtelMoneyId, transactionId, message, status, code, responseCode, success, httpStatus); | ||
} | ||
|
||
public ResponseEntity<AirtelPaymentResponseDTO> initiateTransaction(AirtelPaymentRequestDTO airtelPaymentRequestDTO) { | ||
String message; | ||
String status; | ||
String code; | ||
String responseCode; | ||
boolean success; | ||
HttpStatus httpStatus; | ||
|
||
String msisdn = airtelPaymentRequestDTO.getSubscriber().getMsisdn(); | ||
if (msisdn.equals(msisdnSuccessful)) { | ||
message = TransferStatus.SUCCESSFUL.name(); | ||
status = TransferStatus.SUCCESSFUL.name(); | ||
code = HttpStatus.OK.toString(); | ||
responseCode = successResponseCode; | ||
success = true; | ||
httpStatus = HttpStatus.OK; | ||
} | ||
|
||
else if (msisdn.equals(msisdnFailed)) { | ||
message = TransferStatus.FAILED.name(); | ||
status = TransferStatus.FAILED.name(); | ||
code = HttpStatus.BAD_REQUEST.toString(); | ||
responseCode = failedResponseCode; | ||
success = false; | ||
httpStatus = HttpStatus.BAD_REQUEST; | ||
} | ||
|
||
else { | ||
message = TransferStatus.IN_PROGRESS.name(); | ||
status = TransferStatus.IN_PROGRESS.name(); | ||
code = HttpStatus.ACCEPTED.toString(); | ||
responseCode = pendingResponseCode; | ||
success = true; | ||
httpStatus = HttpStatus.ACCEPTED; | ||
} | ||
|
||
return airtelPaymentRespone(message, status, code, responseCode, success, httpStatus); | ||
|
||
} | ||
|
||
private ResponseEntity<AirtelEnquiryResponseDTO> airtelEnquiryResponse(String airtelMoneyId, String transactionId, String message, | ||
String status, String code, String responseCode, Boolean success, HttpStatus httpStatus) { | ||
String id = transactionId; | ||
|
||
AirtelEnquiryResponseDataTransactionDTO airtelEnquiryResponseDataTransactionDTO = new AirtelEnquiryResponseDataTransactionDTO( | ||
airtelMoneyId, id, message, status); | ||
AirtelEnquiryResponseDataDTO airtelResponseDataDTO = new AirtelEnquiryResponseDataDTO(airtelEnquiryResponseDataTransactionDTO); | ||
|
||
AirtelResponseStatusDTO airtelResponseStatusDTO = new AirtelResponseStatusDTO(code, message, resultCode, responseCode, success); | ||
|
||
AirtelEnquiryResponseDTO responseEntity = new AirtelEnquiryResponseDTO(airtelResponseDataDTO, airtelResponseStatusDTO); | ||
return ResponseEntity.status(httpStatus).body(responseEntity); | ||
|
||
} | ||
|
||
private ResponseEntity<AirtelPaymentResponseDTO> airtelPaymentRespone(String message, String status, String code, String responseCode, | ||
Boolean success, HttpStatus httpStatus) { | ||
boolean id = false; | ||
|
||
AirtelPaymentResponseDataTransactionDTO airtelPaymentResponseDataTransactionDTO = new AirtelPaymentResponseDataTransactionDTO(id, | ||
status); | ||
AirtelPaymentResponseDataDTO airtelResponseDataDTO = new AirtelPaymentResponseDataDTO(airtelPaymentResponseDataTransactionDTO); | ||
|
||
AirtelResponseStatusDTO airtelResponseStatusDTO = new AirtelResponseStatusDTO(code, message, resultCode, responseCode, success); | ||
|
||
AirtelPaymentResponseDTO responseEntity = new AirtelPaymentResponseDTO(airtelResponseDataDTO, airtelResponseStatusDTO); | ||
return ResponseEntity.status(httpStatus).body(responseEntity); | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/org/mifos/connector/airtel/mockairtel/utils/TransactionStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.mifos.connector.airtel.mockairtel.utils; | ||
|
||
public enum TransactionStatus { | ||
TS, TF, TP | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/org/mifos/connector/airtel/mockairtel/utils/TransferStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.mifos.connector.airtel.mockairtel.utils; | ||
|
||
public enum TransferStatus { | ||
COMPLETED, FAILED, IN_PROGRESS, UNKNOWN, SUCCESSFUL | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters