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

Fix error when chargingMetaData is null #183

Open
wants to merge 2 commits into
base: hub-dev
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
Expand Up @@ -159,7 +159,7 @@ public boolean handle(MessageContext context) throws Exception {
}

sendingAddress = PaymentUtil.decodeSendingAddressIfMasked(executor, context, sendingAddress);
JSONObject objAmountTransaction = jsonBody.getJSONObject("amountTransaction");
JSONObject objAmountTransaction = jsonBody.getJSONObject(AttributeConstants.AMOUNT_TRANSACTION);
if (!objAmountTransaction.isNull(AttributeConstants.CLIENT_CORRELATOR)) {
clientCorrelator = nullOrTrimmed(objAmountTransaction.get(AttributeConstants.CLIENT_CORRELATOR).toString());
}
Expand All @@ -183,9 +183,11 @@ public boolean handle(MessageContext context) throws Exception {
clientCorrelator = clientCorrelator + ":" + hubGatewayId + ":" + appId;
}

if (objAmountTransaction.getJSONObject("paymentAmount").has("chargingMetaData")) {
JSONObject paymentAmount = objAmountTransaction.getJSONObject(AttributeConstants.PAYMENT_AMOUNT);
if (paymentAmount.has(AttributeConstants.CHARGING_META_DATA) &&
!paymentAmount.isNull(AttributeConstants.CHARGING_META_DATA)) {

JSONObject chargingMeta = objAmountTransaction.getJSONObject("paymentAmount").getJSONObject("chargingMetaData");
JSONObject chargingMeta = paymentAmount.getJSONObject(AttributeConstants.CHARGING_META_DATA);

boolean isAggregator = PaymentUtil.isAggregator(context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@
import com.wso2telco.dep.mediator.internal.ApiUtils;
import com.wso2telco.dep.mediator.internal.Type;
import com.wso2telco.dep.mediator.internal.UID;
import com.wso2telco.dep.mediator.mediationrule.OriginatingCountryCalculatorIDD;
import com.wso2telco.dep.mediator.service.PaymentService;
import com.wso2telco.dep.mediator.util.*;
import com.wso2telco.dep.oneapivalidation.exceptions.CustomException;
import com.wso2telco.dep.oneapivalidation.service.IServiceValidate;
import com.wso2telco.dep.oneapivalidation.service.impl.payment.ValidateRefund;
import com.wso2telco.dep.subscriptionvalidator.util.ValidatorUtils;
import com.wso2telco.dep.user.masking.configuration.UserMaskingConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpStatus;
Expand All @@ -45,7 +42,6 @@
import org.apache.synapse.core.axis2.Axis2MessageContext;
import org.json.JSONException;
import org.json.JSONObject;
import org.wso2.carbon.utils.CarbonUtils;

import java.io.File;
import java.util.HashMap;
Expand Down Expand Up @@ -194,11 +190,12 @@ public boolean handle(MessageContext context) throws Exception {
clientCorrelator = clientCorrelator + ":" + hubGatewayId + ":" + appId;
}

JSONObject paymentAmount = objAmountTransaction.getJSONObject("paymentAmount");
JSONObject paymentAmount = objAmountTransaction.getJSONObject(AttributeConstants.PAYMENT_AMOUNT);

if (paymentAmount.has("chargingMetaData")) {
if (paymentAmount.has(AttributeConstants.CHARGING_META_DATA) &&
!paymentAmount.isNull(AttributeConstants.CHARGING_META_DATA)) {

JSONObject chargingMetaData = paymentAmount.getJSONObject("chargingMetaData");
JSONObject chargingMetaData = paymentAmount.getJSONObject(AttributeConstants.CHARGING_META_DATA);
boolean isAggregator = PaymentUtil.isAggregator(context);

if (isAggregator && !chargingMetaData.isNull("onBehalfOf")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ public class AttributeConstants {
public static final String AMOUNT_TRANSACTION = "amountTransaction";
public static final String CLIENT_CORRELATOR = "clientCorrelator";
public static final String PURCHASE_CATEGORY_CODE = "purchaseCategoryCode";
public static final String CHARGING_META_DATA = "chargingMetaData";
public static final String PAYMENT_AMOUNT = "paymentAmount";

}