use of com.ing.ideal.connector.Transaction 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());
}
}
use of com.ing.ideal.connector.Transaction 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());
}
}
use of com.ing.ideal.connector.Transaction 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";
}
use of com.ing.ideal.connector.Transaction 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());
}
}
use of com.ing.ideal.connector.Transaction 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());
}
}
Aggregations