From aaf73658ae16ecfb97a7d3c3113028dedc3a585b Mon Sep 17 00:00:00 2001 From: sanchit-0 Date: Tue, 20 Aug 2024 15:35:35 +0530 Subject: [PATCH] Update collection API to work with airtel connector. --- .../channel/api/definition/CollectionApi.java | 3 ++ .../CollectionApiController.java | 11 +++++-- .../channel/camel/config/CamelProperties.java | 2 ++ .../camel/routes/ChannelRouteBuilder.java | 30 +++++++++++++++---- .../channel/model/CollectionRequestDTO.java | 1 + .../channel/zeebe/ZeebeProcessStarter.java | 1 + .../channel/zeebe/ZeebeVariables.java | 1 + src/main/resources/application-tenants.yml | 3 ++ src/main/resources/application.yml | 1 + 9 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/mifos/connector/channel/api/definition/CollectionApi.java b/src/main/java/org/mifos/connector/channel/api/definition/CollectionApi.java index 2834afa6..011a474a 100644 --- a/src/main/java/org/mifos/connector/channel/api/definition/CollectionApi.java +++ b/src/main/java/org/mifos/connector/channel/api/definition/CollectionApi.java @@ -1,6 +1,8 @@ package org.mifos.connector.channel.api.definition; +import static org.mifos.connector.channel.camel.config.CamelProperties.COUNTRY; import static org.mifos.connector.channel.camel.config.CamelProperties.PAYMENT_SCHEME_HEADER; +import static org.mifos.connector.channel.camel.config.CamelProperties.X_CALLBACKURL; import com.fasterxml.jackson.core.JsonProcessingException; import io.swagger.v3.oas.annotations.media.Content; @@ -23,6 +25,7 @@ public interface CollectionApi { GsmaP2PResponseDto collection(@RequestHeader(value = "Platform-TenantId") String tenant, @RequestHeader(value = "X-CorrelationID") String correlationId, @RequestHeader(value = PAYMENT_SCHEME_HEADER, required = false) String paymentScheme, + @RequestHeader(value = COUNTRY) String country, @RequestHeader(value = X_CALLBACKURL) String callbackUrl, @RequestBody CollectionRequestDTO requestBody) throws ExecutionException, InterruptedException, JsonProcessingException; } diff --git a/src/main/java/org/mifos/connector/channel/api/implementation/CollectionApiController.java b/src/main/java/org/mifos/connector/channel/api/implementation/CollectionApiController.java index 5d02b723..1be53342 100644 --- a/src/main/java/org/mifos/connector/channel/api/implementation/CollectionApiController.java +++ b/src/main/java/org/mifos/connector/channel/api/implementation/CollectionApiController.java @@ -1,6 +1,8 @@ package org.mifos.connector.channel.api.implementation; +import static org.mifos.connector.channel.camel.config.CamelProperties.COUNTRY; import static org.mifos.connector.channel.camel.config.CamelProperties.PAYMENT_SCHEME_HEADER; +import static org.mifos.connector.channel.camel.config.CamelProperties.X_CALLBACKURL; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -14,6 +16,9 @@ import org.mifos.connector.channel.model.CollectionRequestDTO; import org.mifos.connector.channel.utils.Headers; import org.mifos.connector.channel.utils.SpringWrapperUtil; +import org.mifos.connector.channel.zeebe.ZeebeProcessStarter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RestController; @@ -27,10 +32,10 @@ public class CollectionApiController implements CollectionApi { private ObjectMapper objectMapper; @Override - public GsmaP2PResponseDto collection(String tenant, String correlationId, String paymentScheme, CollectionRequestDTO requestBody) - throws ExecutionException, InterruptedException, JsonProcessingException { + public GsmaP2PResponseDto collection(String tenant, String correlationId, String paymentScheme, String country, String callbackUrl, + CollectionRequestDTO requestBody) throws ExecutionException, InterruptedException, JsonProcessingException { Headers headers = new Headers.HeaderBuilder().addHeader("Platform-TenantId", tenant).addHeader("X-CorrelationID", correlationId) - .addHeader(PAYMENT_SCHEME_HEADER, paymentScheme).build(); + .addHeader(PAYMENT_SCHEME_HEADER, paymentScheme).addHeader(COUNTRY, country).addHeader(X_CALLBACKURL, callbackUrl).build(); Exchange exchange = SpringWrapperUtil.getDefaultWrappedExchange(producerTemplate.getCamelContext(), headers, objectMapper.writeValueAsString(requestBody)); Exchange ex = producerTemplate.send("direct:post-collection", exchange); diff --git a/src/main/java/org/mifos/connector/channel/camel/config/CamelProperties.java b/src/main/java/org/mifos/connector/channel/camel/config/CamelProperties.java index 544bebb7..cb00c7c2 100644 --- a/src/main/java/org/mifos/connector/channel/camel/config/CamelProperties.java +++ b/src/main/java/org/mifos/connector/channel/camel/config/CamelProperties.java @@ -14,5 +14,7 @@ private CamelProperties() {} public static final String REGISTERING_INSTITUTION_ID = "X-Registering-Institution-ID"; public static final String PARTY_LOOKUP_FSP_ID = "partyLookupFspId"; public static final String PAYEE_DFSP_ID = "X-PayeeDFSP-ID"; + public static final String X_CALLBACKURL = "X-CallbackURL"; + public static final String COUNTRY = "X-Country"; } diff --git a/src/main/java/org/mifos/connector/channel/camel/routes/ChannelRouteBuilder.java b/src/main/java/org/mifos/connector/channel/camel/routes/ChannelRouteBuilder.java index dd583f24..c1b340e4 100644 --- a/src/main/java/org/mifos/connector/channel/camel/routes/ChannelRouteBuilder.java +++ b/src/main/java/org/mifos/connector/channel/camel/routes/ChannelRouteBuilder.java @@ -6,9 +6,12 @@ import static org.mifos.connector.channel.camel.config.CamelProperties.AUTH_TYPE; import static org.mifos.connector.channel.camel.config.CamelProperties.BATCH_ID; import static org.mifos.connector.channel.camel.config.CamelProperties.CLIENTCORRELATIONID; +import static org.mifos.connector.channel.camel.config.CamelProperties.COUNTRY; import static org.mifos.connector.channel.camel.config.CamelProperties.PAYEE_DFSP_ID; import static org.mifos.connector.channel.camel.config.CamelProperties.PAYMENT_SCHEME_HEADER; +import static org.mifos.connector.channel.camel.config.CamelProperties.PLATFORM_TENANT_ID; import static org.mifos.connector.channel.camel.config.CamelProperties.REGISTERING_INSTITUTION_ID; +import static org.mifos.connector.channel.camel.config.CamelProperties.X_CALLBACKURL; import static org.mifos.connector.channel.zeebe.ZeebeMessages.OPERATOR_MANUAL_RECOVERY; import static org.mifos.connector.channel.zeebe.ZeebeVariables.ACCOUNT; import static org.mifos.connector.channel.zeebe.ZeebeVariables.AMS; @@ -51,6 +54,7 @@ import org.mifos.connector.channel.camel.config.Client; import org.mifos.connector.channel.camel.config.ClientProperties; import org.mifos.connector.channel.gsma_api.GsmaP2PResponseDto; +import org.mifos.connector.channel.model.CollectionRequestDTO; import org.mifos.connector.channel.model.OpsTxnResponseDTO; import org.mifos.connector.channel.model.ValidationResponseDTO; import org.mifos.connector.channel.properties.TenantImplementation; @@ -95,6 +99,7 @@ public class ChannelRouteBuilder extends ErrorHandlerRouteBuilder { @Autowired TenantImplementationProperties tenantImplementationProperties; + private String airtelMifosFlow; private String paymentTransferFlow; private String specialPaymentTransferFlow; private String transactionRequestFlow; @@ -118,6 +123,7 @@ public class ChannelRouteBuilder extends ErrorHandlerRouteBuilder { String destinationDfspId; public ChannelRouteBuilder(@Value("#{'${dfspids}'.split(',')}") List dfspIds, + @Value("${bpmn.flows.airtel-mifos-flow}") String airtelMifosFlow, @Value("${bpmn.flows.payment-transfer}") String paymentTransferFlow, @Value("${bpmn.flows.special-payment-transfer}") String specialPaymentTransferFlow, @Value("${bpmn.flows.transaction-request}") String transactionRequestFlow, @@ -135,6 +141,7 @@ public ChannelRouteBuilder(@Value("#{'${dfspids}'.split(',')}") List dfs RestTemplate restTemplate) { super(authProcessor, authProperties); super.configure(); + this.airtelMifosFlow = airtelMifosFlow; this.paymentTransferFlow = paymentTransferFlow; this.specialPaymentTransferFlow = specialPaymentTransferFlow; this.transactionRequestFlow = transactionRequestFlow; @@ -411,16 +418,25 @@ private void collectionRoutes() { amsUtils.postConstruct(); Map extraVariables = new HashMap<>(); - extraVariables.put("initiator", "PAYEE"); - extraVariables.put("initiatorType", "BUSINESS"); - extraVariables.put("scenario", "MPESA"); + CollectionRequestDTO channelRequestBody = objectMapper.readValue((String) exchange.getIn().getBody(), + CollectionRequestDTO.class); - String tenantId = exchange.getIn().getHeader("Platform-TenantId", String.class); - String clientCorrelationId = exchange.getIn().getHeader("X-CorrelationID", String.class); + extraVariables.put("initiator", channelRequestBody.getTransactionType().getInitiator()); + extraVariables.put("initiatorType", channelRequestBody.getTransactionType().getInitiatorType()); + extraVariables.put("scenario", channelRequestBody.getTransactionType().getScenario()); + + String tenantId = exchange.getIn().getHeader(PLATFORM_TENANT_ID, String.class); + String clientCorrelationId = exchange.getIn().getHeader(CLIENTCORRELATIONID, String.class); if (tenantId == null || !dfspIds.contains(tenantId)) { throw new RuntimeException("Requested tenant " + tenantId + " not configured in the connector!"); } extraVariables.put(TENANT_ID, tenantId); + + String country = exchange.getIn().getHeader(COUNTRY, String.class); + String callBackUrl = exchange.getIn().getHeader(X_CALLBACKURL, String.class); + + extraVariables.put("country", country); + extraVariables.put(X_CALLBACKURL, callBackUrl); String paymentScheme = getCollectionPaymentScheme(exchange.getIn().getHeader(PAYMENT_SCHEME_HEADER, String.class)); extraVariables.put(PAYMENT_SCHEME, paymentScheme); String tenantSpecificBpmn; @@ -453,7 +469,7 @@ private void collectionRoutes() { extraVariables.put("isNotificationsFailureEnabled", isNotificationFailureServiceEnabled); extraVariables.put("timer", timer); extraVariables.put("clientCorrelationId", clientCorrelationId); - + extraVariables.put("payeeTenantId", destinationDfspId); String transactionId = zeebeProcessStarter.startInboundTransactionZeebeWorkflow(tenantSpecificBpmn, channelRequestBodyString, extraVariables); JSONObject response = new JSONObject(); @@ -497,6 +513,8 @@ private String getFinalAmsValue(JSONArray payer, Map extraVariab extraVariables.put("accountId", secondaryIdentifierVal); extraVariables.put("phoneNumber", primaryIdentifierVal); + extraVariables.put(PARTY_ID_TYPE, "MSISDN"); + extraVariables.put(PARTY_ID, primaryIdentifierVal); return finalAmsVal; } diff --git a/src/main/java/org/mifos/connector/channel/model/CollectionRequestDTO.java b/src/main/java/org/mifos/connector/channel/model/CollectionRequestDTO.java index 31ef98f1..d2d9dc10 100644 --- a/src/main/java/org/mifos/connector/channel/model/CollectionRequestDTO.java +++ b/src/main/java/org/mifos/connector/channel/model/CollectionRequestDTO.java @@ -14,4 +14,5 @@ public class CollectionRequestDTO { private Amount amount; private TransactionType transactionType; private List customData; + private String note; } diff --git a/src/main/java/org/mifos/connector/channel/zeebe/ZeebeProcessStarter.java b/src/main/java/org/mifos/connector/channel/zeebe/ZeebeProcessStarter.java index 2d0c24aa..4bc98f25 100644 --- a/src/main/java/org/mifos/connector/channel/zeebe/ZeebeProcessStarter.java +++ b/src/main/java/org/mifos/connector/channel/zeebe/ZeebeProcessStarter.java @@ -59,6 +59,7 @@ public String startInboundTransactionZeebeWorkflow(String workflowId, String req Map variables = new HashMap<>(); variables.put(ZeebeVariables.TRANSACTION_ID, transactionId); variables.put(ZeebeVariables.MPESA_CHANNEL_REQUEST, request); + variables.put(ZeebeVariables.REQUEST_BODY, request); variables.put(ZeebeVariables.CHANNEL_REQUEST, MpesaUtils.mpesaChannelRequestToChannelRequestConvertor(request)); variables.put(ZeebeVariables.ORIGIN_DATE, Instant.now().toEpochMilli()); if (extraVariables != null) { diff --git a/src/main/java/org/mifos/connector/channel/zeebe/ZeebeVariables.java b/src/main/java/org/mifos/connector/channel/zeebe/ZeebeVariables.java index 31253469..1d69a382 100644 --- a/src/main/java/org/mifos/connector/channel/zeebe/ZeebeVariables.java +++ b/src/main/java/org/mifos/connector/channel/zeebe/ZeebeVariables.java @@ -8,6 +8,7 @@ private ZeebeVariables() {} public static final String AUTH_RETRIES_LEFT = "authRetriesLeft"; public static final String CHANNEL_REQUEST = "channelRequest"; public static final String MPESA_CHANNEL_REQUEST = "mpesaChannelRequest"; + public static final String REQUEST_BODY = "requestBody"; public static final String ERROR_INFORMATION = "errorInformation"; public static final String ERROR_DESCRIPTION = "errorDescription"; public static final String IS_AUTHORISATION_REQUIRED = "isAuthorisationRequired"; diff --git a/src/main/resources/application-tenants.yml b/src/main/resources/application-tenants.yml index 56824b6c..00567626 100644 --- a/src/main/resources/application-tenants.yml +++ b/src/main/resources/application-tenants.yml @@ -11,3 +11,6 @@ bpmns: flows: payment-transfer: "minimal_mock_fund_transfer_account_lookup-{dfspid}" outbound-transfer-request: "minimal_mock_transfer_request-{dfspid}" + - id: "wakanda" + flows: + outbound-transfer-request: "airtel_flow_mifos-{dfspid}" diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 5b8618f8..86c543f8 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -43,6 +43,7 @@ security: bpmn: flows: + airtel-mifos-flow: "airtel_mifos_flow-{dfspid}" payment-transfer: "PayerFundTransfer-{dfspid}" special-payment-transfer: "SpecialPayerFundTransfer-{dfspid}" transaction-request: "payee_transaction_request-{dfspid}"