Skip to content
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

[PANC-112] Update collection API to work with airtel connector. #8

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -95,6 +99,7 @@ public class ChannelRouteBuilder extends ErrorHandlerRouteBuilder {
@Autowired
TenantImplementationProperties tenantImplementationProperties;

private String airtelMifosFlow;
private String paymentTransferFlow;
private String specialPaymentTransferFlow;
private String transactionRequestFlow;
Expand All @@ -118,6 +123,7 @@ public class ChannelRouteBuilder extends ErrorHandlerRouteBuilder {
String destinationDfspId;

public ChannelRouteBuilder(@Value("#{'${dfspids}'.split(',')}") List<String> 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,
Expand All @@ -135,6 +141,7 @@ public ChannelRouteBuilder(@Value("#{'${dfspids}'.split(',')}") List<String> dfs
RestTemplate restTemplate) {
super(authProcessor, authProperties);
super.configure();
this.airtelMifosFlow = airtelMifosFlow;
this.paymentTransferFlow = paymentTransferFlow;
this.specialPaymentTransferFlow = specialPaymentTransferFlow;
this.transactionRequestFlow = transactionRequestFlow;
Expand Down Expand Up @@ -411,16 +418,25 @@ private void collectionRoutes() {
amsUtils.postConstruct();

Map<String, Object> 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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -497,6 +513,8 @@ private String getFinalAmsValue(JSONArray payer, Map<String, Object> extraVariab

extraVariables.put("accountId", secondaryIdentifierVal);
extraVariables.put("phoneNumber", primaryIdentifierVal);
extraVariables.put(PARTY_ID_TYPE, "MSISDN");
extraVariables.put(PARTY_ID, primaryIdentifierVal);
return finalAmsVal;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public class CollectionRequestDTO {
private Amount amount;
private TransactionType transactionType;
private List<CustomData> customData;
private String note;
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public String startInboundTransactionZeebeWorkflow(String workflowId, String req
Map<String, Object> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application-tenants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
Loading