Search in sources :

Example 46 with GeneralException

use of org.apache.ofbiz.base.util.GeneralException in project ofbiz-framework by apache.

the class PcChargeServices method ccRelease.

public static Map<String, Object> ccRelease(DispatchContext dctx, Map<String, ? extends Object> context) {
    GenericValue orderPaymentPreference = (GenericValue) context.get("orderPaymentPreference");
    Delegator delegator = dctx.getDelegator();
    // lets see if there is a auth transaction already in context
    GenericValue authTransaction = (GenericValue) context.get("authTrans");
    Locale locale = (Locale) context.get("locale");
    if (authTransaction == null) {
        authTransaction = PaymentGatewayServices.getAuthTransaction(orderPaymentPreference);
    }
    if (authTransaction == null) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingPaymentTransactionAuthorizationNotFoundCannotRelease", locale));
    }
    // setup the PCCharge Interface
    Properties props = buildPccProperties(context, delegator);
    PcChargeApi api = getApi(props);
    if (api == null) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingPcChargeErrorGettingPaymentGatewayConfig", locale));
    }
    api.set(PcChargeApi.TROUTD, authTransaction.getString("referenceNum"));
    api.set(PcChargeApi.COMMAND, "3");
    // check to make sure we are configured for SALE mode
    if (!"true".equalsIgnoreCase(props.getProperty("autoBill"))) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingPcChargeCannotSupportReleasingPreAuth", locale));
    }
    // send the transaction
    PcChargeApi out = null;
    try {
        out = api.send();
    } catch (IOException | GeneralException e) {
        Debug.logError(e, module);
        return ServiceUtil.returnError(e.getMessage());
    }
    Map<String, Object> result = ServiceUtil.returnSuccess();
    String resultCode = out.get(PcChargeApi.RESULT);
    if ("VOIDED".equals(resultCode)) {
        result.put("releaseResult", Boolean.TRUE);
    } else {
        result.put("releaseResult", Boolean.FALSE);
    }
    result.put("releaseAmount", context.get("releaseAmount"));
    result.put("releaseRefNum", out.get(PcChargeApi.TROUTD) != null ? out.get(PcChargeApi.TROUTD) : "");
    result.put("releaseCode", out.get(PcChargeApi.AUTH_CODE));
    result.put("releaseFlag", out.get(PcChargeApi.REFERENCE));
    result.put("releaseMessage", out.get(PcChargeApi.RESULT));
    return result;
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) GeneralException(org.apache.ofbiz.base.util.GeneralException) Delegator(org.apache.ofbiz.entity.Delegator) IOException(java.io.IOException) Properties(java.util.Properties) UtilProperties(org.apache.ofbiz.base.util.UtilProperties) EntityUtilProperties(org.apache.ofbiz.entity.util.EntityUtilProperties)

Example 47 with GeneralException

use of org.apache.ofbiz.base.util.GeneralException in project ofbiz-framework by apache.

the class PcChargeServices method ccAuth.

public static Map<String, Object> ccAuth(DispatchContext dctx, Map<String, ? extends Object> context) {
    Locale locale = (Locale) context.get("locale");
    Delegator delegator = dctx.getDelegator();
    // setup the PCCharge Interface
    Properties props = buildPccProperties(context, delegator);
    PcChargeApi api = getApi(props);
    if (api == null) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingPcChargeErrorGettingPaymentGatewayConfig", locale));
    }
    try {
        PcChargeServices.setCreditCardInfo(api, context);
    } catch (GeneralException e) {
        return ServiceUtil.returnError(e.getMessage());
    }
    // basic tx info
    api.set(PcChargeApi.TRANS_AMOUNT, getAmountString(context, "processAmount"));
    api.set(PcChargeApi.TICKET_NUM, context.get("orderId"));
    api.set(PcChargeApi.MANUAL_FLAG, "0");
    api.set(PcChargeApi.PRESENT_FLAG, "1");
    // command setting
    if ("1".equals(props.getProperty("autoBill"))) {
        // sale
        api.set(PcChargeApi.COMMAND, "1");
    } else {
        // pre-auth
        api.set(PcChargeApi.COMMAND, "4");
    }
    // send the transaction
    PcChargeApi out = null;
    try {
        out = api.send();
    } catch (IOException | GeneralException e) {
        Debug.logError(e, module);
        return ServiceUtil.returnError(e.getMessage());
    }
    Map<String, Object> result = ServiceUtil.returnSuccess();
    String resultCode = out.get(PcChargeApi.RESULT);
    boolean passed = false;
    if ("CAPTURED".equals(resultCode)) {
        result.put("authResult", Boolean.TRUE);
        result.put("captureResult", Boolean.TRUE);
        passed = true;
    } else if ("APPROVED".equals(resultCode)) {
        result.put("authCode", out.get(PcChargeApi.AUTH_CODE));
        result.put("authResult", Boolean.TRUE);
        passed = true;
    } else if ("PROCESSED".equals(resultCode)) {
        result.put("authResult", Boolean.TRUE);
    } else {
        result.put("authResult", Boolean.FALSE);
    }
    result.put("authRefNum", out.get(PcChargeApi.TROUTD) != null ? out.get(PcChargeApi.TROUTD) : "");
    result.put("processAmount", context.get("processAmount"));
    result.put("authCode", out.get(PcChargeApi.AUTH_CODE));
    result.put("authFlag", out.get(PcChargeApi.REFERENCE));
    result.put("authMessage", out.get(PcChargeApi.RESULT));
    result.put("cvCode", out.get(PcChargeApi.CVV2_CODE));
    result.put("avsCode", out.get(PcChargeApi.AVS_CODE));
    if (!passed) {
        String respMsg = out.get(PcChargeApi.RESULT) + " / " + out.get(PcChargeApi.AUTH_CODE);
        String refNum = out.get(PcChargeApi.TROUTD);
        result.put("customerRespMsgs", UtilMisc.toList(respMsg, refNum));
    }
    if (result.get("captureResult") != null) {
        result.put("captureCode", out.get(PcChargeApi.AUTH_CODE));
        result.put("captureFlag", out.get(PcChargeApi.REFERENCE));
        result.put("captureRefNum", out.get(PcChargeApi.TROUTD));
        result.put("captureMessage", out.get(PcChargeApi.RESULT));
    }
    return result;
}
Also used : Locale(java.util.Locale) GeneralException(org.apache.ofbiz.base.util.GeneralException) Delegator(org.apache.ofbiz.entity.Delegator) IOException(java.io.IOException) Properties(java.util.Properties) UtilProperties(org.apache.ofbiz.base.util.UtilProperties) EntityUtilProperties(org.apache.ofbiz.entity.util.EntityUtilProperties)

Example 48 with GeneralException

use of org.apache.ofbiz.base.util.GeneralException in project ofbiz-framework by apache.

the class PcChargeServices method ccRefund.

public static Map<String, Object> ccRefund(DispatchContext dctx, Map<String, ? extends Object> context) {
    GenericValue orderPaymentPreference = (GenericValue) context.get("orderPaymentPreference");
    Delegator delegator = dctx.getDelegator();
    // lets see if there is a auth transaction already in context
    GenericValue authTransaction = (GenericValue) context.get("authTrans");
    Locale locale = (Locale) context.get("locale");
    if (authTransaction == null) {
        authTransaction = PaymentGatewayServices.getAuthTransaction(orderPaymentPreference);
    }
    if (authTransaction == null) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingPaymentTransactionAuthorizationNotFoundCannotRefund", locale));
    }
    // setup the PCCharge Interface
    Properties props = buildPccProperties(context, delegator);
    PcChargeApi api = getApi(props);
    if (api == null) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingPcChargeErrorGettingPaymentGatewayConfig", locale));
    }
    api.set(PcChargeApi.TROUTD, authTransaction.getString("referenceNum"));
    api.set(PcChargeApi.COMMAND, "2");
    // send the transaction
    PcChargeApi out = null;
    try {
        out = api.send();
    } catch (IOException | GeneralException e) {
        Debug.logError(e, module);
        return ServiceUtil.returnError(e.getMessage());
    }
    Map<String, Object> result = ServiceUtil.returnSuccess();
    String resultCode = out.get(PcChargeApi.RESULT);
    if ("CAPTURED".equals(resultCode)) {
        result.put("refundResult", Boolean.TRUE);
    } else {
        result.put("refundResult", Boolean.FALSE);
    }
    result.put("refundAmount", context.get("releaseAmount"));
    result.put("refundRefNum", out.get(PcChargeApi.TROUTD) != null ? out.get(PcChargeApi.TROUTD) : "");
    result.put("refundCode", out.get(PcChargeApi.AUTH_CODE));
    result.put("refundFlag", out.get(PcChargeApi.REFERENCE));
    result.put("refundMessage", out.get(PcChargeApi.RESULT));
    return result;
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) GeneralException(org.apache.ofbiz.base.util.GeneralException) Delegator(org.apache.ofbiz.entity.Delegator) IOException(java.io.IOException) Properties(java.util.Properties) UtilProperties(org.apache.ofbiz.base.util.UtilProperties) EntityUtilProperties(org.apache.ofbiz.entity.util.EntityUtilProperties)

Example 49 with GeneralException

use of org.apache.ofbiz.base.util.GeneralException in project ofbiz-framework by apache.

the class RitaServices method ccVoid.

private static Map<String, Object> ccVoid(DispatchContext dctx, Map<String, ? extends Object> context, boolean isRefund) {
    GenericValue orderPaymentPreference = (GenericValue) context.get("orderPaymentPreference");
    Locale locale = (Locale) context.get("locale");
    Delegator delegator = dctx.getDelegator();
    // lets see if there is a auth transaction already in context
    GenericValue authTransaction = (GenericValue) context.get("authTrans");
    if (authTransaction == null) {
        authTransaction = PaymentGatewayServices.getAuthTransaction(orderPaymentPreference);
    }
    if (authTransaction == null) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingPaymentTransactionAuthorizationNotFoundCannotRelease", locale));
    }
    // setup the RiTA Interface
    Properties props = buildPccProperties(context, delegator);
    RitaApi api = getApi(props, "CREDIT");
    if (api == null) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingRitaErrorGettingPaymentGatewayConfig", locale));
    }
    api.set(RitaApi.TRANS_AMOUNT, getAmountString(context, isRefund ? "refundAmount" : "releaseAmount"));
    api.set(RitaApi.ORIG_SEQ_NUM, authTransaction.getString("referenceNum"));
    api.set(RitaApi.COMMAND, "VOID");
    // check to make sure we are configured for SALE mode
    if (!"1".equals(props.getProperty("autoBill"))) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingRitaCannotSupportReleasingPreAuth", locale));
    }
    // send the transaction
    RitaApi out = null;
    try {
        out = api.send();
    } catch (GeneralException | IOException e) {
        Debug.logError(e, module);
        return ServiceUtil.returnError(e.getMessage());
    }
    Map<String, Object> result = ServiceUtil.returnSuccess();
    String resultCode = out.get(RitaApi.RESULT);
    if ("VOIDED".equals(resultCode)) {
        result.put(isRefund ? "refundResult" : "releaseResult", Boolean.TRUE);
    } else {
        result.put(isRefund ? "refundResult" : "releaseResult", Boolean.FALSE);
    }
    result.put(isRefund ? "refundAmount" : "releaseAmount", context.get(isRefund ? "refundAmount" : "releaseAmount"));
    result.put(isRefund ? "refundRefNum" : "releaseRefNum", out.get(RitaApi.INTRN_SEQ_NUM) != null ? out.get(RitaApi.INTRN_SEQ_NUM) : "");
    result.put(isRefund ? "refundCode" : "releaseCode", out.get(RitaApi.AUTH_CODE));
    result.put(isRefund ? "refundFlag" : "releaseFlag", out.get(RitaApi.REFERENCE));
    result.put(isRefund ? "refundMessage" : "releaseMessage", out.get(RitaApi.RESULT));
    return result;
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) GeneralException(org.apache.ofbiz.base.util.GeneralException) Delegator(org.apache.ofbiz.entity.Delegator) IOException(java.io.IOException) UtilProperties(org.apache.ofbiz.base.util.UtilProperties) EntityUtilProperties(org.apache.ofbiz.entity.util.EntityUtilProperties) Properties(java.util.Properties)

Example 50 with GeneralException

use of org.apache.ofbiz.base.util.GeneralException in project ofbiz-framework by apache.

the class RitaServices method ccCreditRefund.

public static Map<String, Object> ccCreditRefund(DispatchContext dctx, Map<String, ? extends Object> context) {
    GenericValue orderPaymentPreference = (GenericValue) context.get("orderPaymentPreference");
    Locale locale = (Locale) context.get("locale");
    Delegator delegator = dctx.getDelegator();
    // lets see if there is a auth transaction already in context
    GenericValue authTransaction = (GenericValue) context.get("authTrans");
    if (authTransaction == null) {
        authTransaction = PaymentGatewayServices.getAuthTransaction(orderPaymentPreference);
    }
    if (authTransaction == null) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingPaymentTransactionAuthorizationNotFoundCannotRefund", locale));
    }
    // setup the RiTA Interface
    Properties props = buildPccProperties(context, delegator);
    RitaApi api = getApi(props, "CREDIT");
    if (api == null) {
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingRitaErrorGettingPaymentGatewayConfig", locale));
    }
    // set the required cc info
    try {
        RitaServices.setCreditCardInfo(api, dctx.getDelegator(), context);
    } catch (GeneralException e) {
        return ServiceUtil.returnError(e.getMessage());
    }
    api.set(RitaApi.TRANS_AMOUNT, getAmountString(context, "refundAmount"));
    api.set(RitaApi.ORIG_SEQ_NUM, authTransaction.getString("referenceNum"));
    api.set(RitaApi.COMMAND, "CREDIT");
    // send the transaction
    RitaApi out = null;
    try {
        out = api.send();
    } catch (GeneralException | IOException e) {
        Debug.logError(e, module);
        return ServiceUtil.returnError(e.getMessage());
    }
    Map<String, Object> result = ServiceUtil.returnSuccess();
    String resultCode = out.get(RitaApi.RESULT);
    if ("CAPTURED".equals(resultCode)) {
        result.put("refundResult", Boolean.TRUE);
    } else {
        result.put("refundResult", Boolean.FALSE);
    }
    result.put("refundAmount", context.get("refundAmount"));
    result.put("refundRefNum", out.get(RitaApi.INTRN_SEQ_NUM) != null ? out.get(RitaApi.INTRN_SEQ_NUM) : "");
    result.put("refundCode", out.get(RitaApi.AUTH_CODE));
    result.put("refundFlag", out.get(RitaApi.REFERENCE));
    result.put("refundMessage", out.get(RitaApi.RESULT));
    return result;
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) GeneralException(org.apache.ofbiz.base.util.GeneralException) Delegator(org.apache.ofbiz.entity.Delegator) IOException(java.io.IOException) UtilProperties(org.apache.ofbiz.base.util.UtilProperties) EntityUtilProperties(org.apache.ofbiz.entity.util.EntityUtilProperties) Properties(java.util.Properties)

Aggregations

GeneralException (org.apache.ofbiz.base.util.GeneralException)216 GenericValue (org.apache.ofbiz.entity.GenericValue)133 Delegator (org.apache.ofbiz.entity.Delegator)101 Locale (java.util.Locale)81 HashMap (java.util.HashMap)71 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)68 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)68 IOException (java.io.IOException)65 BigDecimal (java.math.BigDecimal)55 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)54 Writer (java.io.Writer)29 LinkedList (java.util.LinkedList)29 Map (java.util.Map)29 Timestamp (java.sql.Timestamp)26 StringWriter (java.io.StringWriter)19 Environment (freemarker.core.Environment)15 HttpServletRequest (javax.servlet.http.HttpServletRequest)14 ShoppingCart (org.apache.ofbiz.order.shoppingcart.ShoppingCart)14 HttpSession (javax.servlet.http.HttpSession)13 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)13