Search in sources :

Example 6 with IdealConnector

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

the class IdealPaymentServiceTest method testOrderCancelled.

public void testOrderCancelled() throws Exception {
    try {
        IdealConnector connector = new IdealConnector(configFile);
        int amount = 2;
        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.isCancelled();
        Debug.logInfo("[testOrderCancelled] IssuerID Messages from iDEAL: " + transactionCustomer.getIssuerID(), module);
        Debug.logInfo("[testOrderCancelled] 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 7 with IdealConnector

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

the class IdealPaymentServiceTest method testOrderError.

public void testOrderError() throws Exception {
    try {
        IdealConnector connector = new IdealConnector(configFile);
        int amount = 7;
        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);
        IdealException ex = new IdealException("");
        ex.setErrorCode("SO1000");
        Transaction transactionCustomer = connector.requestTransaction(transaction);
        Debug.logInfo("[testOrderError] IssuerID Messages from iDEAL: " + transactionCustomer.getIssuerID(), module);
        Debug.logInfo("[testOrderError] 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 8 with IdealConnector

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

the class IdealPaymentServiceTest method testOrderFailure.

public void testOrderFailure() throws Exception {
    try {
        IdealConnector connector = new IdealConnector(configFile);
        int amount = 5;
        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.isFailure();
        Debug.logInfo("[testOrderFailure] IssuerID Messages from iDEAL: " + transactionCustomer.getIssuerID(), module);
        Debug.logInfo("[testOrderFailure] 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 9 with IdealConnector

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

the class IdealEvents method callIdeal.

/**
 * Initiate iDEAL Request
 */
public static String callIdeal(HttpServletRequest request, HttpServletResponse response) {
    Locale locale = UtilHttp.getLocale(request);
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    // get the orderId
    String orderId = (String) request.getAttribute("orderId");
    String issuerId = (String) request.getAttribute("issuerId");
    // get the order header
    GenericValue orderHeader = null;
    List<GenericValue> orderItemList = null;
    try {
        orderHeader = EntityQuery.use(delegator).from("OrderHeader").where("orderId", orderId).queryOne();
        orderItemList = EntityQuery.use(delegator).from("OrderItem").where("orderId", orderId).queryList();
    } 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";
    }
    // get the order total
    BigDecimal orderTotal = orderHeader.getBigDecimal("grandTotal");
    // get the product store
    GenericValue productStore = ProductStoreWorker.getProductStore(request);
    if (productStore == null) {
        Debug.logError("ProductStore is null", module);
        request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resourceErr, "idealEvents.problemsGettingMerchantConfiguration", locale));
        return "error";
    }
    // get the payment properties file
    GenericValue paymentConfig = ProductStoreWorker.getProductStorePaymentSetting(delegator, productStore.getString("productStoreId"), "EXT_IDEAL", null, true);
    String configString = null;
    String paymentGatewayConfigId = null;
    if (paymentConfig != null) {
        paymentGatewayConfigId = paymentConfig.getString("paymentGatewayConfigId");
        configString = paymentConfig.getString("paymentPropertiesPath");
    }
    if (configString == null) {
        configString = "payment.properties";
    }
    String merchantId = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "merchantId", configString, "merchantId");
    String merchantSubId = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "merchantSubId", configString, "merchantSubId");
    String merchantReturnURL = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "merchantReturnURL", configString, "merchantReturnURL");
    String acquirerURL = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "acquirerURL", configString, "acquirerURL");
    String acquirerTimeout = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "acquirerTimeout", configString, "acquirerTimeout");
    String privateCert = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "privateCert", configString, "privateCert");
    String acquirerKeyStoreFilename = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "acquirerKeyStoreFilename", configString, "acquirerKeyStoreFilename");
    String acquirerKeyStorePassword = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "acquirerKeyStorePassword", configString, "acquirerKeyStorePassword");
    String merchantKeyStoreFilename = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "merchantKeyStoreFilename", configString, "merchantKeyStoreFilename");
    String merchantKeyStorePassword = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "merchantKeyStorePassword", configString, "merchantKeyStorePassword");
    String expirationPeriod = getPaymentGatewayConfigValue(delegator, paymentGatewayConfigId, "expirationPeriod", configString, "expirationPeriod");
    if (UtilValidate.isEmpty(merchantId) || UtilValidate.isEmpty(merchantReturnURL) || UtilValidate.isEmpty(privateCert) || UtilValidate.isEmpty(merchantKeyStoreFilename) || UtilValidate.isEmpty(merchantKeyStoreFilename)) {
        Debug.logError("Payment properties is not configured properly, some notify URL from iDEAL is not correctly defined!", module);
        request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resourceErr, "idealEvents.problemsGettingMerchantConfiguration", locale));
        return "error";
    }
    List<String> descriptionList = new LinkedList<String>();
    for (GenericValue orderItem : orderItemList) {
        if (UtilValidate.isNotEmpty(orderItem.get("itemDescription"))) {
            descriptionList.add((String) orderItem.get("itemDescription"));
        }
    }
    String orderDescription = StringUtil.join(descriptionList, ",");
    String amount = orderTotal.setScale(decimals, rounding).movePointRight(2).toPlainString();
    String redirectString = null;
    try {
        IdealConnector connector = new IdealConnector("payment");
        Transaction transaction = new Transaction();
        transaction.setIssuerID(issuerId);
        transaction.setAmount(amount);
        transaction.setPurchaseID(orderId);
        transaction.setDescription(orderDescription);
        String returnURL = merchantReturnURL + "?orderId=" + orderId;
        Random random = new SecureRandom();
        String EntranceCode = Long.toString(Math.abs(random.nextLong()), 36);
        transaction.setEntranceCode(EntranceCode);
        transaction.setMerchantReturnURL(returnURL);
        Transaction trx = connector.requestTransaction(transaction);
        redirectString = trx.getIssuerAuthenticationURL();
        request.getSession().setAttribute("purchaseID", orderId);
        request.getSession().setAttribute("payAmount", orderTotal.toPlainString());
    } catch (IdealException ex) {
        Debug.logError(ex.getMessage(), module);
        request.setAttribute("_ERROR_MESSAGE_", ex.getConsumerMessage());
        return "error";
    }
    // redirect to iDEAL
    try {
        response.sendRedirect(redirectString);
    } catch (IOException e) {
        Debug.logError(e, "Problems redirecting to iDEAL", module);
        request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resourceErr, "idealEvents.problemsConnectingWithIdeal", locale));
        return "error";
    }
    return "success";
}
Also used : Locale(java.util.Locale) GenericValue(org.apache.ofbiz.entity.GenericValue) IdealConnector(com.ing.ideal.connector.IdealConnector) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) LinkedList(java.util.LinkedList) IdealException(com.ing.ideal.connector.IdealException) Delegator(org.apache.ofbiz.entity.Delegator) Transaction(com.ing.ideal.connector.Transaction) Random(java.util.Random) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException)

Example 10 with IdealConnector

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

the class IdealEvents method getIssuerList.

public static List<Issuer> getIssuerList() {
    List<Issuer> issuerList = new LinkedList<Issuer>();
    try {
        IdealConnector connector = new IdealConnector("payment");
        Issuers issuers = connector.getIssuerList();
        List<Issuer> shortList = issuers.getShortList();
        List<Issuer> longList = issuers.getLongList();
        for (Iterator<Issuer> iter = shortList.iterator(); iter.hasNext(); ) {
            Issuer issuer = (Issuer) iter.next();
            issuerList.add(issuer);
        }
        for (Iterator<Issuer> iter = longList.iterator(); iter.hasNext(); ) {
            Issuer issuer = (Issuer) iter.next();
            issuerList.add(issuer);
        }
    } catch (IdealException ex) {
        Debug.logError(ex.getMessage(), module);
    }
    return issuerList;
}
Also used : IdealException(com.ing.ideal.connector.IdealException) Issuer(com.ing.ideal.connector.Issuer) Issuers(com.ing.ideal.connector.Issuers) IdealConnector(com.ing.ideal.connector.IdealConnector) LinkedList(java.util.LinkedList)

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