Search in sources :

Example 1 with IdealConnector

use of com.ing.ideal.connector.IdealConnector in project ofbiz-framework by apache.

the class IdealPaymentServiceTest method testOrderExpired.

public void testOrderExpired() throws Exception {
    try {
        IdealConnector connector = new IdealConnector(configFile);
        int amount = 3;
        int amountFormat = amount * 100;
        Transaction transaction = new Transaction();
        transaction.setIssuerID(issuerId);
        transaction.setAmount(Integer.toString(amountFormat));
        transaction.setPurchaseID(orderId);
        transaction.setDescription(orderDiscription);
        Random random = new Random();
        String EntranceCode = Long.toString(Math.abs(random.nextLong()), 36);
        transaction.setEntranceCode(EntranceCode);
        transaction.setMerchantReturnURL(merchantReturnURL);
        Transaction trx = connector.requestTransaction(transaction);
        String transactionId = trx.getTransactionID();
        Transaction transactionCustomer = connector.requestTransactionStatus(transactionId);
        transactionCustomer.isExpired();
        Debug.logInfo("[testOrderExpired] IssuerID Messages from iDEAL: " + transactionCustomer.getIssuerID(), module);
        Debug.logInfo("[testOrderExpired] Status Messages from iDEAL: " + transactionCustomer.getStatus(), module);
    } catch (IdealException ex) {
        TestCase.fail(ex.getMessage());
    }
}
Also used : IdealException(com.ing.ideal.connector.IdealException) Transaction(com.ing.ideal.connector.Transaction) Random(java.util.Random) IdealConnector(com.ing.ideal.connector.IdealConnector)

Example 2 with IdealConnector

use of com.ing.ideal.connector.IdealConnector in project ofbiz-framework by apache.

the class IdealPaymentServiceTest method testOrderOpen.

public void testOrderOpen() throws Exception {
    try {
        IdealConnector connector = new IdealConnector(configFile);
        int amount = 4;
        int amountFormat = amount * 100;
        Transaction transaction = new Transaction();
        transaction.setIssuerID(issuerId);
        transaction.setAmount(Integer.toString(amountFormat));
        transaction.setPurchaseID(orderId);
        transaction.setDescription(orderDiscription);
        Random random = new Random();
        String EntranceCode = Long.toString(Math.abs(random.nextLong()), 36);
        transaction.setEntranceCode(EntranceCode);
        transaction.setMerchantReturnURL(merchantReturnURL);
        Transaction trx = connector.requestTransaction(transaction);
        String transactionId = trx.getTransactionID();
        Transaction transactionCustomer = connector.requestTransactionStatus(transactionId);
        transactionCustomer.isOpen();
        Debug.logInfo("[testOrderOpen] IssuerID Messages from iDEAL: " + transactionCustomer.getIssuerID(), module);
        Debug.logInfo("[testOrderOpen] Status Messages from iDEAL: " + transactionCustomer.getStatus(), module);
    } catch (IdealException ex) {
        TestCase.fail(ex.getMessage());
    }
}
Also used : IdealException(com.ing.ideal.connector.IdealException) Transaction(com.ing.ideal.connector.Transaction) Random(java.util.Random) IdealConnector(com.ing.ideal.connector.IdealConnector)

Example 3 with IdealConnector

use of com.ing.ideal.connector.IdealConnector in project ofbiz-framework by apache.

the class IdealPaymentServiceTest method testDirectoryRequest.

public void testDirectoryRequest() throws Exception {
    try {
        IdealConnector connector = new IdealConnector(configFile);
        connector.getIssuerList();
    } catch (IdealException ex) {
        TestCase.fail(ex.getMessage());
    }
}
Also used : IdealException(com.ing.ideal.connector.IdealException) IdealConnector(com.ing.ideal.connector.IdealConnector)

Example 4 with IdealConnector

use of com.ing.ideal.connector.IdealConnector 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 5 with IdealConnector

use of com.ing.ideal.connector.IdealConnector in project ofbiz-framework by apache.

the class IdealPaymentServiceTest method testOrderSuccuess.

public void testOrderSuccuess() throws Exception {
    try {
        IdealConnector connector = new IdealConnector(configFile);
        int amount = 1;
        int amountFormat = amount * 100;
        Transaction transaction = new Transaction();
        transaction.setIssuerID(issuerId);
        transaction.setAmount(Integer.toString(amountFormat));
        transaction.setPurchaseID(orderId);
        transaction.setDescription(orderDiscription);
        Random random = new Random();
        String EntranceCode = Long.toString(Math.abs(random.nextLong()), 36);
        transaction.setEntranceCode(EntranceCode);
        transaction.setMerchantReturnURL(merchantReturnURL);
        Transaction trx = connector.requestTransaction(transaction);
        String transactionId = trx.getTransactionID();
        Transaction transactionCustomer = connector.requestTransactionStatus(transactionId);
        transactionCustomer.isSuccess();
        Debug.logInfo("[testOrderSuccuess] IssuerID Messages from iDEAL: " + transactionCustomer.getIssuerID(), module);
        Debug.logInfo("[testOrderSuccuess] Status Messages from iDEAL: " + transactionCustomer.getStatus(), module);
    } catch (IdealException ex) {
        TestCase.fail(ex.getMessage());
    }
}
Also used : IdealException(com.ing.ideal.connector.IdealException) Transaction(com.ing.ideal.connector.Transaction) Random(java.util.Random) IdealConnector(com.ing.ideal.connector.IdealConnector)

Aggregations

IdealConnector (com.ing.ideal.connector.IdealConnector)10 IdealException (com.ing.ideal.connector.IdealException)10 Transaction (com.ing.ideal.connector.Transaction)8 Random (java.util.Random)7 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 Locale (java.util.Locale)2 Delegator (org.apache.ofbiz.entity.Delegator)2 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)2 GenericValue (org.apache.ofbiz.entity.GenericValue)2 Issuer (com.ing.ideal.connector.Issuer)1 Issuers (com.ing.ideal.connector.Issuers)1 BigDecimal (java.math.BigDecimal)1 GenericTransactionException (org.apache.ofbiz.entity.transaction.GenericTransactionException)1 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)1 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)1