Skip to content

Commit

Permalink
VRP consent initiation flow implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
kalpanakanagasabai committed Nov 26, 2023
1 parent 0d2fca3 commit beb78fa
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public class ErrorConstants {
public static final String PATH_CONSENT_ID = "Data.Initiation.Consent-id";
public static final String PATH_DATA = "Data";
public static final String PATH_INITIATION = "Data.Initiation";
public static final String PATH_RISK = "Data.Risk";
public static final String PATH_URL = "Data.Url";
public static final String PATH_EXPIRATION_DATE = "Data.Expiration-Date";
public static final String MSG_MISSING_DEBTOR_ACC = "Mandatory parameter DebtorAccount is missing in the payload.";
Expand Down Expand Up @@ -206,6 +207,11 @@ public class ErrorConstants {
ErrorConstants.PATH_DATA;
public static final String INITIATION_NOT_FOUND = "Initiation is not found or empty in the request.:" +
ErrorConstants.PATH_INITIATION;

public static final String RISK_MISMATCH = "RISK Does Not Match.:" + ErrorConstants.PATH_RISK;
public static final String RISK_NOT_FOUND = "RISK is not found or empty in the request.:" +
ErrorConstants.PATH_RISK;

public static final String INVALID_URI_ERROR = "Path requested is invalid. :" + ErrorConstants.PATH_URL;
public static final String COF_CONSENT_STATE_INVALID = "Confirmation of Funds validation failed due to invalid" +
" consent state.:" + ErrorConstants.PATH_STATUS;
Expand All @@ -219,13 +225,24 @@ public class ErrorConstants {
public static final String CONSENT_ID_NOT_FOUND = "Consent ID not available in consent data";
public static final String FIELD_INVALID_DATE = "OB.Field.InvalidDate";
public static final String EXPIRED_DATE_ERROR = "The ExpirationDateTime value has to be a future date.";
public static final String PATH_MAXIMUM_INDIVIDUAL_AMOUNT = "Data.ControlParameters.MaximumIndividualAmount.Amount";
public static final String INVALID_MAXIMUM_INDIVIDUAL_AMOUNT = "Invalid value for Amount in MaximumIndividualAmount";
public static final String INVALID_CURRENCY = "Invalid value for currency in MaximumIndividualAmount" ;
// vrp
public static final String MAXIMUM_INDIVIDUAL_AMOUNT_NOT_FOUND = "Mandatory parameter MaximumIndividualAmount" +
" Amount is missing in the payload.";
public static final String PATH_MAXIMUM_INDIVIDUAL_CURRENCY = "Data.ControlParameters." +
"MaximumIndividualAmount.Currency";
public static final String MAXIMUM_INDIVIDUAL_AMOUNT_CURRENCY_NOT_FOUND = "Mandatory parameter " +
"MaximumIndividualAmount Currency is missing in the payload";
public static final String INVALID_MAXIMUM_INDIVIDUAL_AMOUNT = "Invalid value for Amount " +
"in MaximumIndividualAmount";
public static final String INVALID_CURRENCY = "Mandatory parameter " +
"MaximumIndividualAmount Currency is missing in the payload";
public static final String INVALID_PERIOD_ALIGNMENT = "Invalid value for period alignment in PeriodicLimits";
public static final String INVALID_PERIOD_TYPE = "Invalid value for period type in PeriodicLimits";
public static final String PATH_PERIOD_TYPE = "Data.ControlParameters.PeriodicLimits.PeriodType";
public static final String INVALID_PERIOD_TYPE = "Mandatory parameter " +
"period type is missing in the payload";
public static final String INVALID_VALID_TO_DATE = "Valid to Date specified in the request is invalid";
public static final String PATH_VALID_TO_DATE = "Data.ControlParameters.ValidToDateTime";
public static final String PATH_MAXIMUM_INDIVIDUAL_AMOUNT = "Data.ControlParameters.MaximumIndividualAmount.Amount";
public static final String PATH_PERIOD_TYPE = "Data.ControlParameters.PeriodicLimits.PeriodType";
public static final String PATH_PERIOD_ALIGNMENT = "Data.ControlParameters.PeriodLimits.PeriodAlignment";
}

Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ public class ConsentExtensionConstants {
public static final String INSTRUCTION_IDENTIFICATION = "InstructionIdentification";
public static final String REJECTED_STATUS = "rejected";
public static final String OPEN_ENDED_AUTHORIZATION = "Open Ended Authorization Requested";
public static final String DEBTOR_ACC_TITLE = "DebtorAccount";
public static final String SCHEME_NAME_TITLE = "SchemeName";
public static final String DEBTOR_ACC_TITLE = "Debtor Account";
public static final String SCHEME_NAME_TITLE = "Scheme Name";
public static final String IDENTIFICATION_TITLE = "Identification";
public static final String NAME_TITLE = "Name";
public static final String SECONDARY_IDENTIFICATION_TITLE = "Secondary Identification";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
/**
* Copyright (c) 2021-2022, WSO2 LLC. (https://www.wso2.com). All Rights Reserved.
* This software is the property of WSO2 LLC. and its suppliers, if any.
* Dissemination of any information or reproduction of any material contained
* herein in any form is strictly forbidden, unless permitted by WSO2 expressly.
* You may not alter or remove any copyright or other notice from copies of this content.
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.wso2.openbanking.accelerator.consent.extensions.manage.impl;
Expand All @@ -12,7 +22,6 @@
import com.wso2.openbanking.accelerator.common.util.ErrorConstants;
import com.wso2.openbanking.accelerator.consent.extensions.common.ConsentException;
import com.wso2.openbanking.accelerator.consent.extensions.common.ConsentExtensionConstants;
import com.wso2.openbanking.accelerator.consent.extensions.common.ConsentExtensionUtils;
import com.wso2.openbanking.accelerator.consent.extensions.common.ConsentServiceUtil;
import com.wso2.openbanking.accelerator.consent.extensions.common.ResponseStatus;
import com.wso2.openbanking.accelerator.consent.extensions.internal.ConsentExtensionsDataHolder;
Expand Down Expand Up @@ -51,12 +60,6 @@ public class VRPConsentRequestHandler implements ConsentManageRequestHandler {
public void handleConsentManagePost(ConsentManageData consentManageData) {

try {
//Validate cutoff datetime
if (ConsentExtensionUtils.shouldInitiationRequestBeRejected()) {
log.error(ErrorConstants.MSG_ELAPSED_CUT_OFF_DATE_TIME);
throw new ConsentException(ResponseStatus.BAD_REQUEST, ErrorConstants.PAYMENT_INITIATION_HANDLE_ERROR);
}

//Get the request payload from the ConsentManageData
Object request = consentManageData.getPayload();
if (!(request instanceof JSONObject)) {
Expand All @@ -79,11 +82,11 @@ public void handleConsentManagePost(ConsentManageData consentManageData) {
handlePaymentPost(consentManageData, requestObject, response);

} catch (ConsentManagementException e) {
log.error(e.getMessage());
log.error("Error occurred while handling the initiation request", e);
throw new ConsentException(ResponseStatus.INTERNAL_SERVER_ERROR,
ErrorConstants.PAYMENT_INITIATION_HANDLE_ERROR);
}
}
}


@Override
Expand Down Expand Up @@ -176,11 +179,12 @@ private void handlePaymentPost(ConsentManageData consentManageData, JSONObject r
consentAttributes.put(ConsentExtensionConstants.PERIOD_TYPE, ((JSONObject) ((JSONArray) (controlParameters)
.get(ConsentExtensionConstants.PERIODIC_LIMITS)).get(0)).get(ConsentExtensionConstants.PERIOD_TYPE)
.toString());
consentAttributes.put(ConsentExtensionConstants.PERIOD_ALIGNMENT, ((JSONObject) ((JSONArray) (controlParameters)
.get(ConsentExtensionConstants.PERIODIC_LIMITS)).get(0)).get(ConsentExtensionConstants.PERIOD_TYPE)
.toString());
consentAttributes.put(ConsentExtensionConstants.PERIOD_AMOUNT_LIMIT, ((JSONObject)
((JSONArray) (controlParameters).get(ConsentExtensionConstants.PERIODIC_LIMITS)).get(0))
.get(ConsentExtensionConstants.PERIOD_AMOUNT_LIMIT).toString());
consentAttributes.put(ConsentExtensionConstants.PAID_AMOUNT, "0");
consentAttributes.put(ConsentExtensionConstants.LAST_PAYMENT_DATE, "0");

Map<String, String> headers = consentManageData.getHeaders();
//Setting response headers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
/**
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com). All Rights Reserved.
* Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
*
* This software is the property of WSO2 Inc. and its suppliers, if any.
* Dissemination of any information or reproduction of any material contained
* herein is strictly forbidden, unless permitted by WSO2 in accordance with
* the WSO2 Software License available at https://wso2.com/licenses/eula/3.1.
* For specific language governing the permissions and limitations under this
* license, please see the license as well as any agreement you’ve entered into
* with WSO2 governing the purchase of this software and any associated services.
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.wso2.openbanking.accelerator.consent.extensions.manage.validator;
Expand All @@ -31,19 +37,6 @@
public class VRPConsentRequestValidator {

private static final Log log = LogFactory.getLog(VRPConsentRequestValidator.class);

public static final String MAXIMUM_INDIVIDUAL_AMOUNT_NOT_FOUND = "Instructed Amount isn't present in the payload";

public static final String PATH_MAXIMUM_INDIVIDUAL_CURRENCY = "Data.ControlParameters." +
"MaximumIndividualAmount.Currency";

public static final String MAXIMUM_INDIVIDUAL_AMOUNT_CURRENCY_NOT_FOUND = "Instructed currency isn't " +
"present in the payload";

public static final String INVALID_PERIOD_ALIGNMENT = "Invalid value for period alignment in PeriodicLimits";

public static final String PATH_PERIOD_ALIGNMENT = "Data.ControlParameters.PeriodLimits.PeriodAlignment";

/**
* Method to validate variable recurring payment control parameters.
*
Expand All @@ -57,27 +50,28 @@ public static JSONObject validatecontrolParameters(JSONObject controlParameters)
if (controlParameters.containsKey(ConsentExtensionConstants.MAXIMUM_INDIVIDUAL_AMOUNT)) {
JSONObject maximumIndividualAmount = (JSONObject) controlParameters
.get(ConsentExtensionConstants.MAXIMUM_INDIVIDUAL_AMOUNT);
Object amount = maximumIndividualAmount.get(ConsentExtensionConstants.AMOUNT);
Object currency = maximumIndividualAmount.get(ConsentExtensionConstants.CURRENCY);
String amount = maximumIndividualAmount.getAsString(ConsentExtensionConstants.AMOUNT);
String currency = maximumIndividualAmount.getAsString(ConsentExtensionConstants.CURRENCY);

// validate amount
if (!ConsentManageUtil.validateAmount(maximumIndividualAmount)) {
if (!ConsentManageUtil.validateMaximumIndividualAmount(maximumIndividualAmount)) {
log.error(ErrorConstants.INVALID_MAXIMUM_INDIVIDUAL_AMOUNT);
return ConsentManageUtil.getValidationResponse(ErrorConstants.FIELD_INVALID,
ErrorConstants.INVALID_MAXIMUM_INDIVIDUAL_AMOUNT,
ErrorConstants.PATH_MAXIMUM_INDIVIDUAL_AMOUNT);
}

if (amount == null || StringUtils.isEmpty(amount.toString())) {
log.error(MAXIMUM_INDIVIDUAL_AMOUNT_NOT_FOUND);
if (StringUtils.isEmpty(amount)) {
log.error(ErrorConstants.MAXIMUM_INDIVIDUAL_AMOUNT_NOT_FOUND);
validationResponse.put(ConsentExtensionConstants.IS_VALID, false);
validationResponse.put(ConsentExtensionConstants.HTTP_CODE, ResponseStatus.BAD_REQUEST);
validationResponse.put(ConsentExtensionConstants.ERRORS, MAXIMUM_INDIVIDUAL_AMOUNT_NOT_FOUND);
validationResponse.put(ConsentExtensionConstants.ERRORS,
ErrorConstants.MAXIMUM_INDIVIDUAL_AMOUNT_NOT_FOUND);
return validationResponse;
}

//validate currency
if (!ConsentManageUtil.validateCurrency(maximumIndividualAmount)) {
if (!ConsentManageUtil.validateMaximumIndividualAmountCurrency(maximumIndividualAmount)) {
log.error(ErrorConstants.INVALID_CURRENCY);
validationResponse.put(ConsentExtensionConstants.IS_VALID, false);
validationResponse.put(ConsentExtensionConstants.HTTP_CODE, ResponseStatus.BAD_REQUEST);
Expand All @@ -87,12 +81,12 @@ public static JSONObject validatecontrolParameters(JSONObject controlParameters)
ErrorConstants.INVALID_CURRENCY, ErrorConstants.PATH_MAXIMUM_INDIVIDUAL_AMOUNT);
}

if (currency == null || StringUtils.isEmpty(currency.toString())) {
log.error(MAXIMUM_INDIVIDUAL_AMOUNT_CURRENCY_NOT_FOUND);
if (StringUtils.isEmpty(currency)) {
log.error(ErrorConstants.MAXIMUM_INDIVIDUAL_AMOUNT_CURRENCY_NOT_FOUND);
validationResponse.put(ConsentExtensionConstants.IS_VALID, false);
validationResponse.put(ConsentExtensionConstants.HTTP_CODE, ResponseStatus.BAD_REQUEST);
validationResponse.put(ConsentExtensionConstants.ERRORS,
MAXIMUM_INDIVIDUAL_AMOUNT_CURRENCY_NOT_FOUND);
ErrorConstants.MAXIMUM_INDIVIDUAL_AMOUNT_CURRENCY_NOT_FOUND);
return validationResponse;
}
}
Expand Down Expand Up @@ -123,48 +117,48 @@ public static JSONObject validatecontrolParameters(JSONObject controlParameters)
while (it.hasNext()) {
JSONObject limit = (JSONObject) it.next();

Object amount = limit.get(ConsentExtensionConstants.AMOUNT);
Object currency = limit.get(ConsentExtensionConstants.CURRENCY);
Object periodType = limit.get(ConsentExtensionConstants.PERIOD_TYPE);
String amount = limit.getAsString(ConsentExtensionConstants.AMOUNT);
String currency = limit.getAsString(ConsentExtensionConstants.CURRENCY);
String periodType = limit.getAsString(ConsentExtensionConstants.PERIOD_TYPE);

// validate amount
if (!ConsentManageUtil.validateAmount(limit)) {
if (!ConsentManageUtil.validateMaximumIndividualAmount(limit)) {
log.error(ErrorConstants.INVALID_MAXIMUM_INDIVIDUAL_AMOUNT);
return ConsentManageUtil.getValidationResponse(ErrorConstants.FIELD_INVALID,
ErrorConstants.INVALID_MAXIMUM_INDIVIDUAL_AMOUNT,
ErrorConstants.PATH_MAXIMUM_INDIVIDUAL_AMOUNT);
}

if (amount == null || StringUtils.isEmpty(amount.toString())) {
log.error(MAXIMUM_INDIVIDUAL_AMOUNT_NOT_FOUND);
if (StringUtils.isEmpty(amount)) {
log.error(ErrorConstants.MAXIMUM_INDIVIDUAL_AMOUNT_NOT_FOUND);
validationResponse.put(ConsentExtensionConstants.IS_VALID, false);
validationResponse.put(ConsentExtensionConstants.HTTP_CODE, ResponseStatus.BAD_REQUEST);
validationResponse.put(ConsentExtensionConstants.ERRORS,
MAXIMUM_INDIVIDUAL_AMOUNT_NOT_FOUND);
ErrorConstants.MAXIMUM_INDIVIDUAL_AMOUNT_NOT_FOUND);
return validationResponse;
}

//validate currency
if (!ConsentManageUtil.validateCurrency(limit)) {
if (!ConsentManageUtil.validateMaximumIndividualAmountCurrency(limit)) {
log.error(ErrorConstants.INVALID_CURRENCY);
return ConsentManageUtil.getValidationResponse(ErrorConstants.FIELD_INVALID,
ErrorConstants.INVALID_CURRENCY, ErrorConstants.PATH_MAXIMUM_INDIVIDUAL_AMOUNT);
}

if (currency == null || StringUtils.isEmpty(currency.toString())) {
log.error(MAXIMUM_INDIVIDUAL_AMOUNT_CURRENCY_NOT_FOUND);
if (StringUtils.isEmpty(currency)) {
log.error(ErrorConstants.MAXIMUM_INDIVIDUAL_AMOUNT_CURRENCY_NOT_FOUND);
validationResponse.put(ConsentExtensionConstants.IS_VALID, false);
validationResponse.put(ConsentExtensionConstants.HTTP_CODE, ResponseStatus.BAD_REQUEST);
validationResponse.put(ConsentExtensionConstants.ERRORS,
MAXIMUM_INDIVIDUAL_AMOUNT_CURRENCY_NOT_FOUND);
ErrorConstants.MAXIMUM_INDIVIDUAL_AMOUNT_CURRENCY_NOT_FOUND);
return validationResponse;
}

//validate period alignment
if (ConsentManageUtil.validatePeriodicAlignment(limit)) {
log.error(ErrorConstants.INVALID_PERIOD_ALIGNMENT);
return ConsentManageUtil.getValidationResponse(ErrorConstants.FIELD_INVALID,
INVALID_PERIOD_ALIGNMENT, PATH_PERIOD_ALIGNMENT);
ErrorConstants.INVALID_PERIOD_ALIGNMENT, ErrorConstants.PATH_PERIOD_ALIGNMENT);
}

//validate period type
Expand All @@ -174,7 +168,7 @@ public static JSONObject validatecontrolParameters(JSONObject controlParameters)
ErrorConstants.INVALID_PERIOD_TYPE, ErrorConstants.PATH_PERIOD_TYPE);
}

if (periodType == null || StringUtils.isEmpty(periodType.toString())) {
if (StringUtils.isEmpty(periodType)) {
log.error(ErrorConstants.INVALID_PERIOD_TYPE);
validationResponse.put(ConsentExtensionConstants.IS_VALID, false);
validationResponse.put(ConsentExtensionConstants.HTTP_CODE, ResponseStatus.BAD_REQUEST);
Expand Down
Loading

0 comments on commit beb78fa

Please sign in to comment.