Search in sources :

Example 81 with LocalDispatcher

use of org.apache.ofbiz.service.LocalDispatcher in project ofbiz-framework by apache.

the class SagePayPaymentServices method processCardReleasePayment.

private static Map<String, Object> processCardReleasePayment(DispatchContext ctx, Map<String, Object> context) {
    Map<String, Object> result = ServiceUtil.returnSuccess();
    Locale locale = (Locale) context.get("locale");
    LocalDispatcher dispatcher = ctx.getDispatcher();
    String paymentGatewayConfigId = (String) context.get("paymentGatewayConfigId");
    BigDecimal amount = (BigDecimal) context.get("releaseAmount");
    GenericValue authTransaction = (GenericValue) context.get("authTransaction");
    String orderId = (String) authTransaction.get("altReference");
    String refNum = (String) authTransaction.get("referenceNum");
    try {
        Map<String, Object> paymentResult = dispatcher.runSync("SagePayPaymentRelease", UtilMisc.toMap("paymentGatewayConfigId", paymentGatewayConfigId, "vendorTxCode", orderId, "releaseAmount", amount.toString(), "vpsTxId", refNum, "securityKey", authTransaction.get("gatewayFlag"), "txAuthNo", authTransaction.get("gatewayCode")));
        Debug.logInfo("SagePay - SagePayPaymentRelease result : " + paymentResult, module);
        String status = (String) paymentResult.get("status");
        String statusDetail = (String) paymentResult.get("statusDetail");
        if (status != null && "OK".equals(status)) {
            Debug.logInfo("SagePay Payment Released for Order : " + orderId, module);
            result = SagePayUtil.buildCardReleasePaymentResponse(Boolean.TRUE, null, amount, refNum, orderId, statusDetail);
        } else {
            Debug.logInfo("SagePay - Invalid status " + status + " received for order : " + orderId, module);
            result = SagePayUtil.buildCardReleasePaymentResponse(Boolean.FALSE, null, amount, refNum, orderId, statusDetail);
        }
    } catch (GenericServiceException e) {
        Debug.logError(e, "Error in calling SagePayPaymentRelease", module);
        result = ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingSagePayPaymentReleaseException", UtilMisc.toMap("errorString", e.getMessage()), locale));
    }
    return result;
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) BigDecimal(java.math.BigDecimal)

Example 82 with LocalDispatcher

use of org.apache.ofbiz.service.LocalDispatcher in project ofbiz-framework by apache.

the class SagePayPaymentServices method processCardAuthorisationPayment.

private static Map<String, Object> processCardAuthorisationPayment(DispatchContext ctx, Map<String, Object> context) {
    Map<String, Object> result = ServiceUtil.returnSuccess();
    LocalDispatcher dispatcher = ctx.getDispatcher();
    Locale locale = (Locale) context.get("locale");
    Map<String, String> billingInfo = buildCustomerBillingInfo(context);
    String paymentGatewayConfigId = (String) context.get("paymentGatewayConfigId");
    try {
        Map<String, Object> paymentResult = dispatcher.runSync("SagePayPaymentAuthentication", UtilMisc.toMap("paymentGatewayConfigId", paymentGatewayConfigId, "vendorTxCode", billingInfo.get("orderId"), "cardHolder", billingInfo.get("cardHolder"), "cardNumber", billingInfo.get("cardNumber"), "expiryDate", billingInfo.get("expiryDate"), "cardType", billingInfo.get("cardType"), "cv2", billingInfo.get("cv2"), "description", billingInfo.get("description"), "amount", billingInfo.get("amount"), "currency", billingInfo.get("currency"), "billingAddress", billingInfo.get("billingAddress"), "billingPostCode", billingInfo.get("billingPostCode")));
        Debug.logInfo("SagePay - SagePayPaymentAuthentication result : " + paymentResult, module);
        String transactionType = (String) paymentResult.get("transactionType");
        String status = (String) paymentResult.get("status");
        String statusDetail = (String) paymentResult.get("statusDetail");
        String vpsTxId = (String) paymentResult.get("vpsTxId");
        String securityKey = (String) paymentResult.get("securityKey");
        String txAuthNo = (String) paymentResult.get("txAuthNo");
        String vendorTxCode = (String) paymentResult.get("vendorTxCode");
        String amount = (String) paymentResult.get("amount");
        if (status != null && "OK".equals(status)) {
            Debug.logInfo("SagePay - Payment authorized for order : " + vendorTxCode, module);
            result = SagePayUtil.buildCardAuthorisationPaymentResponse(Boolean.TRUE, txAuthNo, securityKey, new BigDecimal(amount), vpsTxId, vendorTxCode, statusDetail);
            if ("PAYMENT".equals(transactionType)) {
                Map<String, Object> captureResult = SagePayUtil.buildCardCapturePaymentResponse(Boolean.TRUE, txAuthNo, securityKey, new BigDecimal(amount), vpsTxId, vendorTxCode, statusDetail);
                result.putAll(captureResult);
            }
        } else if (status != null && "INVALID".equals(status)) {
            Debug.logInfo("SagePay - Invalid authorisation request for order : " + vendorTxCode, module);
            result = SagePayUtil.buildCardAuthorisationPaymentResponse(Boolean.FALSE, null, null, BigDecimal.ZERO, "INVALID", vendorTxCode, statusDetail);
        } else if (status != null && "MALFORMED".equals(status)) {
            Debug.logInfo("SagePay - Malformed authorisation request for order : " + vendorTxCode, module);
            result = SagePayUtil.buildCardAuthorisationPaymentResponse(Boolean.FALSE, null, null, BigDecimal.ZERO, "MALFORMED", vendorTxCode, statusDetail);
        } else if (status != null && "NOTAUTHED".equals(status)) {
            Debug.logInfo("SagePay - NotAuthed authorisation request for order : " + vendorTxCode, module);
            result = SagePayUtil.buildCardAuthorisationPaymentResponse(Boolean.FALSE, null, securityKey, BigDecimal.ZERO, vpsTxId, vendorTxCode, statusDetail);
        } else if (status != null && "REJECTED".equals(status)) {
            Debug.logInfo("SagePay - Rejected authorisation request for order : " + vendorTxCode, module);
            result = SagePayUtil.buildCardAuthorisationPaymentResponse(Boolean.FALSE, null, securityKey, new BigDecimal(amount), vpsTxId, vendorTxCode, statusDetail);
        } else {
            Debug.logInfo("SagePay - Invalid status " + status + " received for order : " + vendorTxCode, module);
            result = SagePayUtil.buildCardAuthorisationPaymentResponse(Boolean.FALSE, null, null, BigDecimal.ZERO, "ERROR", vendorTxCode, statusDetail);
        }
    } catch (GenericServiceException e) {
        Debug.logError(e, "Error in calling SagePayPaymentAuthentication", module);
        result = ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingSagePayPaymentAuthorisationException", UtilMisc.toMap("errorString", e.getMessage()), locale));
    }
    return result;
}
Also used : Locale(java.util.Locale) LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) BigDecimal(java.math.BigDecimal)

Example 83 with LocalDispatcher

use of org.apache.ofbiz.service.LocalDispatcher in project ofbiz-framework by apache.

the class SagePayPaymentServices method processCardCapturePayment.

private static Map<String, Object> processCardCapturePayment(DispatchContext ctx, Map<String, Object> context) {
    Map<String, Object> result = ServiceUtil.returnSuccess();
    LocalDispatcher dispatcher = ctx.getDispatcher();
    Locale locale = (Locale) context.get("locale");
    String paymentGatewayConfigId = (String) context.get("paymentGatewayConfigId");
    GenericValue authTransaction = (GenericValue) context.get("authTransaction");
    BigDecimal amount = (BigDecimal) context.get("captureAmount");
    String vendorTxCode = (String) authTransaction.get("altReference");
    String vpsTxId = (String) authTransaction.get("referenceNum");
    String securityKey = (String) authTransaction.get("gatewayFlag");
    String txAuthCode = (String) authTransaction.get("gatewayCode");
    try {
        Map<String, Object> paymentResult = dispatcher.runSync("SagePayPaymentAuthorisation", UtilMisc.toMap("paymentGatewayConfigId", paymentGatewayConfigId, "vendorTxCode", vendorTxCode, "vpsTxId", vpsTxId, "securityKey", securityKey, "txAuthNo", txAuthCode, "amount", amount.toString()));
        Debug.logInfo("SagePay - SagePayPaymentAuthorisation result : " + paymentResult, module);
        String status = (String) paymentResult.get("status");
        String statusDetail = (String) paymentResult.get("statusDetail");
        if (status != null && "OK".equals(status)) {
            Debug.logInfo("SagePay Payment Released for Order : " + vendorTxCode, module);
            result = SagePayUtil.buildCardCapturePaymentResponse(Boolean.TRUE, txAuthCode, securityKey, amount, vpsTxId, vendorTxCode, statusDetail);
        } else {
            Debug.logInfo("SagePay - Invalid status " + status + " received for order : " + vendorTxCode, module);
            result = SagePayUtil.buildCardCapturePaymentResponse(Boolean.FALSE, txAuthCode, securityKey, amount, vpsTxId, vendorTxCode, statusDetail);
        }
    } catch (GenericServiceException e) {
        Debug.logError(e, "Error in calling SagePayPaymentAuthorisation", module);
        result = ServiceUtil.returnError(UtilProperties.getMessage(resource, "AccountingSagePayPaymentAuthorisationException", UtilMisc.toMap("errorString", e.getMessage()), locale));
    }
    return result;
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) BigDecimal(java.math.BigDecimal)

Example 84 with LocalDispatcher

use of org.apache.ofbiz.service.LocalDispatcher in project ofbiz-framework by apache.

the class IdealEvents method idealNotify.

/**
 * iDEAL notification
 */
public static String idealNotify(HttpServletRequest request, HttpServletResponse response) {
    Locale locale = UtilHttp.getLocale(request);
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
    GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
    Map<String, Object> parametersMap = UtilHttp.getParameterMap(request);
    String transactionId = request.getParameter("trxid");
    for (String name : parametersMap.keySet()) {
        String value = request.getParameter(name);
        Debug.logError("### Param: " + name + " => " + value, module);
    }
    String orderId = null;
    String paymentStatus = null;
    try {
        IdealConnector connector = new IdealConnector("payment");
        Transaction transaction = connector.requestTransactionStatus(transactionId);
        orderId = transaction.getPurchaseID();
        if (orderId == null) {
            orderId = (String) request.getSession().getAttribute("purchaseID");
        }
        String payAmount = transaction.getAmount();
        if (payAmount == null) {
            payAmount = (String) request.getSession().getAttribute("payAmount");
        }
        paymentStatus = transaction.getStatus();
        request.setAttribute("transactionId", transactionId);
        request.setAttribute("paymentStatus", paymentStatus);
        request.setAttribute("paymentAmount", payAmount);
    } catch (IdealException ex) {
        Debug.logError(ex.getMessage(), module);
        request.setAttribute("_ERROR_MESSAGE_", ex.getConsumerMessage());
        return "error";
    }
    // get the user
    if (userLogin == null) {
        String userLoginId = "system";
        try {
            userLogin = EntityQuery.use(delegator).from("UserLogin").where("userLoginId", userLoginId).queryOne();
        } catch (GenericEntityException e) {
            Debug.logError(e, "Cannot get UserLogin for: " + userLoginId + "; cannot continue", module);
            request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resourceErr, "idealEvents.problemsGettingAuthenticationUser", locale));
            return "error";
        }
    }
    // get the order header
    GenericValue orderHeader = null;
    if (UtilValidate.isNotEmpty(orderId)) {
        try {
            orderHeader = EntityQuery.use(delegator).from("OrderHeader").where("orderId", orderId).queryOne();
        } catch (GenericEntityException e) {
            Debug.logError(e, "Cannot get the order header for order: " + orderId, module);
            request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resourceErr, "idealEvents.problemsGettingOrderHeader", locale));
            return "error";
        }
    } else {
        Debug.logError("iDEAL did not callback with a valid orderId!", module);
        request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resourceErr, "idealEvents.noValidOrderIdReturned", locale));
        return "error";
    }
    if (orderHeader == null) {
        Debug.logError("Cannot get the order header for order: " + orderId, module);
        request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resourceErr, "idealEvents.problemsGettingOrderHeader", locale));
        return "error";
    }
    // attempt to start a transaction
    boolean okay = true;
    boolean beganTransaction = false;
    try {
        beganTransaction = TransactionUtil.begin();
        // authorized
        if ("Success".equals(paymentStatus)) {
            okay = OrderChangeHelper.approveOrder(dispatcher, userLogin, orderId);
        // cancelled
        } else if ("Cancelled".equals(paymentStatus)) {
            okay = OrderChangeHelper.cancelOrder(dispatcher, userLogin, orderId);
        }
        if (okay) {
            // set the payment preference
            okay = setPaymentPreferences(delegator, dispatcher, userLogin, orderId, request);
        }
    } catch (Exception e) {
        String errMsg = "Error handling iDEAL notification";
        Debug.logError(e, errMsg, module);
        try {
            TransactionUtil.rollback(beganTransaction, errMsg, e);
        } catch (GenericTransactionException gte2) {
            Debug.logError(gte2, "Unable to rollback transaction", module);
        }
    } finally {
        if (!okay) {
            try {
                TransactionUtil.rollback(beganTransaction, "Failure in processing iDEAL callback", null);
            } catch (GenericTransactionException gte) {
                Debug.logError(gte, "Unable to rollback transaction", module);
            }
        } else {
            try {
                TransactionUtil.commit(beganTransaction);
            } catch (GenericTransactionException gte) {
                Debug.logError(gte, "Unable to commit transaction", module);
            }
        }
    }
    if (okay) {
        request.setAttribute("_EVENT_MESSAGE_", UtilProperties.getMessage(resource, "IdealSuccessful", locale));
        // call the email confirm service
        Map<String, String> emailContext = UtilMisc.toMap("orderId", orderId, "userLogin", userLogin);
        try {
            dispatcher.runSync("sendOrderConfirmation", emailContext);
        } catch (GenericServiceException e) {
            Debug.logError(e, "Problems sending email confirmation", module);
        }
    }
    return "success";
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) IdealConnector(com.ing.ideal.connector.IdealConnector) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) IdealException(com.ing.ideal.connector.IdealException) IOException(java.io.IOException) GenericTransactionException(org.apache.ofbiz.entity.transaction.GenericTransactionException) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) IdealException(com.ing.ideal.connector.IdealException) Delegator(org.apache.ofbiz.entity.Delegator) Transaction(com.ing.ideal.connector.Transaction) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) GenericTransactionException(org.apache.ofbiz.entity.transaction.GenericTransactionException) GenericServiceException(org.apache.ofbiz.service.GenericServiceException)

Example 85 with LocalDispatcher

use of org.apache.ofbiz.service.LocalDispatcher in project ofbiz-framework by apache.

the class GlEvents method createReconcileAccount.

public static String createReconcileAccount(HttpServletRequest request, HttpServletResponse response) {
    LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
    final Delegator delegator = (Delegator) request.getAttribute("delegator");
    GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
    Map<String, Object> ctx = UtilHttp.getParameterMap(request);
    String acctgTransId;
    String acctgTransEntrySeqId;
    String glAccountId = null;
    String organizationPartyId = null;
    BigDecimal reconciledBalance = BigDecimal.ZERO;
    boolean isSelected;
    String debitCreditFlag;
    // The number of multi form rows is retrieved
    int rowCount = UtilHttp.getMultiFormRowCount(ctx);
    for (int i = 0; i < rowCount; i++) {
        // for calculating amount per glAccountId
        String suffix = UtilHttp.getMultiRowDelimiter() + i;
        isSelected = (ctx.containsKey("_rowSubmit" + suffix) && "Y".equalsIgnoreCase((String) ctx.get("_rowSubmit" + suffix)));
        if (!isSelected) {
            continue;
        }
        acctgTransId = (String) ctx.get("acctgTransId" + suffix);
        acctgTransEntrySeqId = (String) ctx.get("acctgTransEntrySeqId" + suffix);
        organizationPartyId = (String) ctx.get("organizationPartyId" + suffix);
        glAccountId = (String) ctx.get("glAccountId" + suffix);
        try {
            GenericValue acctgTransEntry = EntityQuery.use(delegator).from("AcctgTransEntry").where("acctgTransId", acctgTransId, "acctgTransEntrySeqId", acctgTransEntrySeqId).queryOne();
            if (acctgTransEntry != null) {
                // calculate amount for each AcctgTransEntry according to glAccountId based on debit and credit
                debitCreditFlag = acctgTransEntry.getString("debitCreditFlag");
                if ("D".equalsIgnoreCase(debitCreditFlag)) {
                    // total balance per glAccountId
                    reconciledBalance = reconciledBalance.add(acctgTransEntry.getBigDecimal("amount"));
                } else {
                    // total balance per glAccountId
                    reconciledBalance = reconciledBalance.subtract(acctgTransEntry.getBigDecimal("amount"));
                }
            }
        } catch (GenericEntityException e) {
            Debug.logError(e, module);
            return "error";
        }
    }
    Map<String, Object> fieldMap = UtilMisc.toMap("glReconciliationName", "Reconciliation at date " + UtilDateTime.nowTimestamp(), "glAccountId", glAccountId, "organizationPartyId", organizationPartyId, "reconciledDate", UtilDateTime.nowTimestamp(), "reconciledBalance", reconciledBalance, "userLogin", userLogin);
    Map<String, Object> glReconResult = null;
    try {
        // create GlReconciliation for the glAccountId
        glReconResult = dispatcher.runSync("createGlReconciliation", fieldMap);
        if (ServiceUtil.isError(glReconResult)) {
            return "error";
        }
    } catch (GenericServiceException e) {
        Debug.logError(e, module);
        return "error";
    }
    String glReconciliationId = (String) glReconResult.get("glReconciliationId");
    String reconciledAmount;
    for (int i = 0; i < rowCount; i++) {
        String suffix = UtilHttp.getMultiRowDelimiter() + i;
        isSelected = (ctx.containsKey("_rowSubmit" + suffix) && "Y".equalsIgnoreCase((String) ctx.get("_rowSubmit" + suffix)));
        if (!isSelected) {
            continue;
        }
        acctgTransId = (String) ctx.get("acctgTransId" + suffix);
        acctgTransEntrySeqId = (String) ctx.get("acctgTransEntrySeqId" + suffix);
        try {
            GenericValue acctgTransEntry = EntityQuery.use(delegator).from("AcctgTransEntry").where("acctgTransId", acctgTransId, "acctgTransEntrySeqId", acctgTransEntrySeqId).queryOne();
            if (acctgTransEntry != null) {
                reconciledAmount = acctgTransEntry.getString("amount");
                acctgTransId = acctgTransEntry.getString("acctgTransId");
                acctgTransEntrySeqId = acctgTransEntry.getString("acctgTransEntrySeqId");
                Map<String, Object> glReconEntryMap = UtilMisc.toMap("glReconciliationId", glReconciliationId, "acctgTransId", acctgTransId, "acctgTransEntrySeqId", acctgTransEntrySeqId, "reconciledAmount", reconciledAmount, "userLogin", userLogin);
                Map<String, Object> glReconEntryResult = null;
                try {
                    glReconEntryResult = dispatcher.runSync("createGlReconciliationEntry", glReconEntryMap);
                    if (ServiceUtil.isError(glReconEntryResult)) {
                        return "error";
                    }
                } catch (GenericServiceException e) {
                    Debug.logError(e, module);
                    return "error";
                }
            }
        } catch (GenericEntityException e) {
            Debug.logError(e, module);
            return "error";
        }
    }
    ctx.put("glReconciliationId", glReconciliationId);
    request.setAttribute("glReconciliationId", glReconciliationId);
    return "success";
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) LocalDispatcher(org.apache.ofbiz.service.LocalDispatcher) Delegator(org.apache.ofbiz.entity.Delegator) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) BigDecimal(java.math.BigDecimal)

Aggregations

LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)427 GenericValue (org.apache.ofbiz.entity.GenericValue)356 Delegator (org.apache.ofbiz.entity.Delegator)324 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)321 Locale (java.util.Locale)296 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)270 HashMap (java.util.HashMap)214 BigDecimal (java.math.BigDecimal)135 GeneralException (org.apache.ofbiz.base.util.GeneralException)87 Timestamp (java.sql.Timestamp)81 LinkedList (java.util.LinkedList)79 IOException (java.io.IOException)59 Map (java.util.Map)51 HttpSession (javax.servlet.http.HttpSession)49 OrderReadHelper (org.apache.ofbiz.order.order.OrderReadHelper)28 ModelService (org.apache.ofbiz.service.ModelService)28 EntityCondition (org.apache.ofbiz.entity.condition.EntityCondition)24 ShoppingCart (org.apache.ofbiz.order.shoppingcart.ShoppingCart)23 Security (org.apache.ofbiz.security.Security)20 ByteBuffer (java.nio.ByteBuffer)19