Search in sources :

Example 6 with Transaction

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

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

use of com.ing.ideal.connector.Transaction 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)

Aggregations

IdealConnector (com.ing.ideal.connector.IdealConnector)8 IdealException (com.ing.ideal.connector.IdealException)8 Transaction (com.ing.ideal.connector.Transaction)8 Random (java.util.Random)7 IOException (java.io.IOException)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 BigDecimal (java.math.BigDecimal)1 LinkedList (java.util.LinkedList)1 GenericTransactionException (org.apache.ofbiz.entity.transaction.GenericTransactionException)1 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)1 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)1