7
7
import org .json .JSONObject ;
8
8
import org .mifos .connector .ams .pesacore .pesacore .dto .PesacoreRequestDTO ;
9
9
import org .mifos .connector .ams .pesacore .util .ConnectionUtils ;
10
+ import org .mifos .connector .ams .pesacore .util .PesacoreUtils ;
10
11
import org .slf4j .Logger ;
11
12
import org .slf4j .LoggerFactory ;
12
13
import org .springframework .beans .factory .annotation .Value ;
@@ -55,6 +56,29 @@ public void configure() {
55
56
})
56
57
.to ("direct:transfer-settlement-base" );
57
58
59
+ from ("rest:POST:/api/v1/paybill/validate/roster" )
60
+ .id ("validate-user" )
61
+ .log (LoggingLevel .INFO , "## Roster user validation" )
62
+ .setBody (e -> {
63
+ String body =e .getIn ().getBody (String .class );
64
+ logger .debug ("Body : {}" ,body );
65
+ e .setProperty ("dfspId" ,e .getProperty ("dfspId" ));
66
+ return body ;
67
+ })
68
+ .to ("direct:transfer-validation-base" )
69
+ .process (e ->{
70
+ String transactionId = e .getProperty (TRANSACTION_ID ).toString ();
71
+ logger .debug ("Transaction Id : " +transactionId );
72
+ logger .debug ("Response received from validation base : {}" ,e .getIn ().getBody ());
73
+ // Building the response
74
+ JSONObject responseObject =new JSONObject ();
75
+ responseObject .put ("reconciled" , e .getProperty (PARTY_LOOKUP_FAILED ).equals (false ));
76
+ responseObject .put ("AMS" , "roster" );
77
+ responseObject .put ("transaction_id" , transactionId );
78
+ logger .debug ("response object " +responseObject );
79
+ e .getIn ().setBody (responseObject .toString ());
80
+ });
81
+
58
82
from ("direct:transfer-validation-base" )
59
83
.id ("transfer-validation-base" )
60
84
.log (LoggingLevel .INFO , "## Starting transfer Validation base route" )
@@ -65,12 +89,16 @@ public void configure() {
65
89
.process (exchange -> {
66
90
// processing success case
67
91
exchange .setProperty (PARTY_LOOKUP_FAILED , false );
92
+ exchange .setProperty ("dfspId" ,exchange .getProperty ("dfspId" ));
93
+ logger .debug ("Pesacore Validation Success" );
68
94
})
69
95
.otherwise ()
70
96
.log (LoggingLevel .ERROR , "Validation unsuccessful" )
71
97
.process (exchange -> {
72
98
// processing unsuccessful case
73
99
exchange .setProperty (PARTY_LOOKUP_FAILED , true );
100
+ exchange .setProperty ("dfspId" ,exchange .getProperty ("dfspId" ));
101
+ logger .debug ("Pesacore Validation Failure" );
74
102
});
75
103
76
104
from ("direct:transfer-validation" )
@@ -81,14 +109,26 @@ public void configure() {
81
109
.setHeader ("Content-Type" , constant ("application/json" ))
82
110
.setHeader ("Authorization" , simple ("Token " + authHeader ))
83
111
.setBody (exchange -> {
84
- JSONObject channelRequest = (JSONObject ) exchange .getProperty (CHANNEL_REQUEST );
85
- String transactionId = exchange .getProperty (TRANSACTION_ID , String .class );
86
-
87
- PesacoreRequestDTO verificationRequestDTO = buildPesacoreDtoFromChannelRequest (channelRequest ,
88
- transactionId );
89
-
90
- logger .info ("Validation request DTO: \n \n \n " + verificationRequestDTO );
91
- return verificationRequestDTO ;
112
+ if (exchange .getProperty (CHANNEL_REQUEST )!=null ) {
113
+ JSONObject channelRequest = (JSONObject ) exchange .getProperty (CHANNEL_REQUEST );
114
+ String transactionId = exchange .getProperty (TRANSACTION_ID , String .class );
115
+
116
+ PesacoreRequestDTO verificationRequestDTO = buildPesacoreDtoFromChannelRequest (channelRequest ,
117
+ transactionId );
118
+ logger .debug ("Validation request DTO: \n \n \n " + verificationRequestDTO );
119
+ return verificationRequestDTO ;
120
+ }
121
+ else {
122
+ JSONObject paybillRequest = new JSONObject (exchange .getIn ().getBody (String .class ));
123
+ PesacoreRequestDTO pesacoreRequestDTO = PesacoreUtils .convertPaybillPayloadToAmsPesacorePayload (paybillRequest );
124
+
125
+ String transactionId = pesacoreRequestDTO .getRemoteTransactionId ();
126
+ log .info (pesacoreRequestDTO .toString ());
127
+ exchange .setProperty (TRANSACTION_ID , transactionId );
128
+ exchange .setProperty ("dfspId" ,exchange .getProperty ("dfspId" ));
129
+ logger .debug ("Validation request DTO: \n \n \n " + pesacoreRequestDTO );
130
+ return pesacoreRequestDTO ;
131
+ }
92
132
})
93
133
.marshal ().json (JsonLibrary .Jackson )
94
134
.toD (getVerificationEndpoint ()+ "?bridgeEndpoint=true&throwExceptionOnFailure=false&" +
@@ -129,18 +169,28 @@ public void configure() {
129
169
.setHeader ("Content-Type" , constant ("application/json" ))
130
170
.setHeader ("Authorization" , simple ("Token " + authHeader ))
131
171
.setBody (exchange -> {
132
-
133
- JSONObject channelRequest = (JSONObject ) exchange .getProperty (CHANNEL_REQUEST );
134
- String transactionId = exchange .getProperty (TRANSACTION_ID , String .class );
135
- String mpesaReceiptNumber = exchange .getProperty (EXTERNAL_ID , String .class );
136
-
137
- PesacoreRequestDTO confirmationRequestDTO = buildPesacoreDtoFromChannelRequest (channelRequest ,
138
- mpesaReceiptNumber );
139
- confirmationRequestDTO .setStatus ("successful" );
140
- confirmationRequestDTO .setReceiptId (mpesaReceiptNumber );
141
-
142
- logger .info ("Confirmation request DTO: \n \n \n " + confirmationRequestDTO );
143
- return confirmationRequestDTO ;
172
+ if (exchange .getProperty (CHANNEL_REQUEST ).toString ().contains ("customData" )){
173
+ JSONObject channelRequest = (JSONObject ) exchange .getProperty (CHANNEL_REQUEST );
174
+ String transactionId = exchange .getProperty (TRANSACTION_ID , String .class );
175
+ String mpesaReceiptNumber = exchange .getProperty (EXTERNAL_ID , String .class );
176
+
177
+ PesacoreRequestDTO confirmationRequestDTO = buildPesacoreDtoFromChannelRequest (channelRequest ,
178
+ mpesaReceiptNumber );
179
+ confirmationRequestDTO .setStatus ("successful" );
180
+ confirmationRequestDTO .setReceiptId (mpesaReceiptNumber );
181
+
182
+ logger .info ("Confirmation request DTO: \n \n \n " + confirmationRequestDTO );
183
+ return confirmationRequestDTO ;
184
+ }else {
185
+ JSONObject paybillRequest = new JSONObject (exchange .getIn ().getBody (String .class ));
186
+ PesacoreRequestDTO pesacoreRequestDTO = PesacoreUtils .convertPaybillPayloadToAmsPesacorePayload (paybillRequest );
187
+
188
+ String transactionId = pesacoreRequestDTO .getRemoteTransactionId ();
189
+ log .debug (pesacoreRequestDTO .toString ());
190
+ exchange .setProperty (TRANSACTION_ID , transactionId );
191
+ logger .debug ("Confirmation request DTO: {}" ,pesacoreRequestDTO );
192
+ return pesacoreRequestDTO ;
193
+ }
144
194
})
145
195
.marshal ().json (JsonLibrary .Jackson )
146
196
.toD (getConfirmationEndpoint () + "?bridgeEndpoint=true&throwExceptionOnFailure=false&" +
@@ -149,6 +199,7 @@ public void configure() {
149
199
150
200
}
151
201
202
+
152
203
// returns the complete URL for verification request
153
204
private String getVerificationEndpoint () {
154
205
return pesacoreBaseUrl + verificationEndpoint ;
0 commit comments